#!/usr/bin/env node /** * CLI Test Runner for Content Generation * Usage: node scripts/test-campaign.js */ import { pool } from '../src/lib/db.js'; import { batchQueue } from '../src/lib/queue/config.js'; const testBlueprint = { "asset_name": "{{CITY}} Test Campaign", "deployment_target": "Test Funnel", "variables": { "STATE": "California", "CITY": "San Diego|Irvine", "AVATAR_A": "Solar CEO" }, "content": { "url_path": "{{CITY}}.test.com", "meta_description": "Test campaign for {{CITY}}", "body": [ { "block_type": "Hero", "content": "
This is a {test|demo} for {{AVATAR_A}}s.
" } ] } }; async function runTest() { console.log('๐งช Content Generation Test\n'); try { // 1. Get site ID const siteResult = await pool.query( `SELECT id FROM sites WHERE domain = 'spark.jumpstartscaling.com' LIMIT 1` ); if (siteResult.rows.length === 0) { throw new Error('Admin site not found'); } const siteId = siteResult.rows[0].id; console.log(`โ Site ID: ${siteId}`); // 2. Create campaign const campaignResult = await pool.query( `INSERT INTO campaign_masters (site_id, name, blueprint_json, status) VALUES ($1, $2, $3, 'pending') RETURNING id`, [siteId, 'Test Campaign', JSON.stringify(testBlueprint)] ); const campaignId = campaignResult.rows[0].id; console.log(`โ Campaign created: ${campaignId}`); // 3. Queue job await batchQueue.add('generate_campaign_content', { campaignId, campaignName: 'Test Campaign' }); console.log(`โ Job queued for campaign ${campaignId}`); console.log('\n๐ Expected output: 2 posts (San Diego, Irvine)'); console.log('๐ Check generation_jobs table for status'); } catch (error) { console.error('โ Test failed:', error.message); process.exit(1); } finally { await pool.end(); process.exit(0); } } runTest();