run-e2e-outreach-only.js
1 #!/usr/bin/env node 2 /** 3 * Run E2E Outreach Stage Only 4 * Assumes database is already populated with sites and proposals. 5 * 6 * Queries the production PostgreSQL database (read-only) to check state, 7 * then runs the outreach stage against it. 8 */ 9 10 import 'dotenv/config'; 11 import '../src/utils/load-env.js'; 12 import { getOne, getAll, closePool } from '../src/utils/db.js'; 13 14 // Import outreach stage 15 const { runOutreach } = await import('../src/stages/outreach.js'); 16 17 console.log('\n=== E2E Outreach Stage Only ===\n'); 18 console.log(`Time: ${new Date().toISOString()}\n`); 19 20 try { 21 // Check if we have data to work with 22 const siteRow = await getOne('SELECT COUNT(*) as count FROM sites'); 23 const siteCount = siteRow?.count ?? 0; 24 25 // messages table uses message_type='outreach' for what was previously 'outreaches' table 26 const outreachRow = await getOne( 27 `SELECT COUNT(*) as count FROM messages WHERE message_type = 'outreach' AND direction = 'outbound'` 28 ); 29 const outreachCount = outreachRow?.count ?? 0; 30 31 console.log(`Sites in database: ${siteCount}`); 32 console.log(`Outreach messages in database: ${outreachCount}\n`); 33 34 if (outreachCount === 0) { 35 console.error('ERROR: No outreach messages found in database. Run full E2E test first.'); 36 process.exit(1); 37 } 38 39 // Show outreach status breakdown 40 const statusBreakdown = await getAll( 41 `SELECT COALESCE(delivery_status, approval_status) as status, contact_method, COUNT(*) as count 42 FROM messages 43 WHERE message_type = 'outreach' AND direction = 'outbound' 44 GROUP BY status, contact_method 45 ORDER BY contact_method, status` 46 ); 47 48 console.log('Outreach status breakdown:'); 49 console.table(statusBreakdown); 50 console.log(''); 51 52 // Run outreach stage (limit 10 to match E2E test) 53 console.log('Running outreach stage...\n'); 54 const result = await runOutreach({ limit: 10, useBulk: false }); 55 56 console.log('\n=== Outreach Complete ===\n'); 57 console.log('Results:'); 58 console.log(JSON.stringify(result, null, 2)); 59 } catch (error) { 60 console.error('\n=== Error ===\n'); 61 console.error(error); 62 process.exit(1); 63 } finally { 64 await closePool(); 65 }