← back to Watches

test-automation.sh

109 lines

#!/bin/bash

# Test all Puppeteer & Playwright automation features

echo "🧪 Testing Automation Features"
echo "=" | tr -d '\n' | while read; do printf '=%.0s' {1..70}; done
echo ""

# Test 1: Price Scraper (quick test - just one watch)
echo ""
echo "1️⃣ Testing Price Scraper (Playwright)..."
node -e "
import PriceScraper from './utils/price-scraper.js';
import fs from 'fs';

const scraper = new PriceScraper();
const watch = {
  id: 'speedmaster-moonwatch-1969',
  model: 'Speedmaster Professional Moonwatch',
  reference: 'ST 105.012',
  series: 'Speedmaster'
};

try {
  const results = await scraper.scrapeChrono24(watch.reference);
  console.log('✓ Scraper test passed: Found', results.length, 'price points');
} catch (error) {
  console.error('✗ Scraper test failed:', error.message);
} finally {
  await scraper.close();
}
" 2>&1 | head -20

# Test 2: Screenshot Capture (Puppeteer)
echo ""
echo "2️⃣ Testing Screenshot Capture (Puppeteer)..."
node -e "
import ScreenshotCapture from './utils/screenshot-capture.js';

const capture = new ScreenshotCapture();

try {
  await capture.captureFullPage('http://localhost:7600/', 'test-screenshot');
  console.log('✓ Screenshot test passed');
} catch (error) {
  console.error('✗ Screenshot test failed:', error.message);
} finally {
  await capture.close();
}
" 2>&1 | head -10

# Test 3: PDF Generator (Puppeteer)
echo ""
echo "3️⃣ Testing PDF Generator (Puppeteer)..."
node -e "
import PDFGenerator from './utils/pdf-generator.js';

const generator = new PDFGenerator();
const testHTML = '<html><body><h1>Test PDF</h1><p>This is a test document.</p></body></html>';

try {
  await generator.generateFromHTML(testHTML, 'test-pdf');
  console.log('✓ PDF generator test passed');
} catch (error) {
  console.error('✗ PDF generator test failed:', error.message);
} finally {
  await generator.close();
}
" 2>&1 | head -10

# Test 4: CSV Price Monitor
echo ""
echo "4️⃣ Testing CSV Price Monitor..."
if [ -f "/root/Projects/watches/data/price-history-csv/index.json" ]; then
  echo "✓ CSV monitor setup verified"
  echo "  Files found:"
  ls -lh /root/Projects/watches/data/price-history-csv/ | grep -E '\.(csv|json)$' | head -5
else
  echo "⚠️  No CSV data yet (run: node utils/price-monitor-simple.js)"
fi

# Test 5: Cron Job
echo ""
echo "5️⃣ Testing Cron Job Setup..."
if crontab -l | grep -q "price-monitor-simple.js"; then
  echo "✓ Cron job configured correctly"
  echo "  Schedule: $(crontab -l | grep price-monitor-simple.js | awk '{print $1, $2, $3, $4, $5}')"
  echo "  Time: 6:00 AM daily"
else
  echo "✗ Cron job not found"
fi

# Summary
echo ""
echo "=" | tr -d '\n' | while read; do printf '=%.0s' {1..70}; done
echo ""
echo "✅ Automation Test Complete"
echo ""
echo "📁 Output directories:"
echo "  - Screenshots: /root/Projects/watches/public/screenshots/"
echo "  - PDFs: /root/Projects/watches/analytics/reports/pdf/"
echo "  - CSV Data: /root/Projects/watches/data/price-history-csv/"
echo "  - Price Details: /root/Projects/watches/data/price-summaries/"
echo ""
echo "🔍 Next steps:"
echo "  1. Run full price scrape: node utils/price-monitor-simple.js"
echo "  2. Generate report PDF: node utils/pdf-generator.js --analytics daily"
echo "  3. Capture dashboard: node utils/screenshot-capture.js --dashboard"