// Chasing Unicorns promo page (Marty, 2026-11-12). Boots a throwaway server, opens /chasing-unicorns?ref= and checks: // the viral ?ref= sets the sponsor cookie, every red-flag button opens its card and lights the radar, the ending unlocks after 3, // the join button keeps the sponsor, no page errors, no sideways scroll on a phone. Writes the 1200x630 share image too: // public/assets/chasing-unicorns-og.png (pass --og to refresh it). node qa/chasing-unicorns.mjs [--og] import { spawn } from 'node:child_process'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; const PW = process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright/index.js'; const { chromium } = (await import('file:///' + PW.replace(/^\/+/, ''))).default; const PORT = 8796, B = 'http://127.0.0.1:' + PORT; const DATA = path.join(os.tmpdir(), 'iap-unicorns-' + Date.now()); fs.mkdirSync(DATA, { recursive: true }); const ok = [], bad = []; const t = (n, c, x) => (c ? ok : bad).push(n + (c || !x ? '' : ' -> ' + x)); const srv = spawn(process.execPath, ['server.js'], { env: { ...process.env, PORT: String(PORT), DATA_DIR: DATA, ADMIN_PASSWORD: 'localtest', NODE_ENV: 'test', DATABASE_URL: '' }, stdio: 'ignore' }); const bye = c => { try { srv.kill(); } catch (e) {} setTimeout(() => { try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} process.exit(c); }, 500); }; for (let i = 0; i < 60; i++) { try { if ((await fetch(B + '/api/stats')).ok) break; } catch (e) {} await new Promise(r => setTimeout(r, 500)); } // a real member to share the page const DEV = 'c0ffee00c0ffee00c0ffee00c0ffee00'; const jf = async (p, body, cookie) => { const r = await fetch(B + p, { method: body ? 'POST' : 'GET', redirect: 'manual', headers: { 'Content-Type': 'application/json', Cookie: cookie || '', 'X-Forwarded-For': '203.0.113.9' }, body: body ? JSON.stringify(body) : undefined }); let b = {}; try { b = await r.json(); } catch (e) {} return { r, b }; }; const st = await jf('/api/auth/email/start', { email: 'sharer@example.com', fts: Date.now() - 20000 }, 'iap.dev=' + DEV); const vf = await jf('/api/auth/email/verify', { email: 'sharer@example.com', code: st.b.devCode || st.b.code }, 'iap.dev=' + DEV); const jar = ['iap.dev=' + DEV, ...(vf.r.headers.getSetCookie ? vf.r.headers.getSetCookie() : []).map(c => String(c).split(';')[0])].join('; '); await jf('/api/my/profile', { username: 'unisharer' }, jar); const pg = await fetch(B + '/chasing-unicorns?ref=unisharer', { redirect: 'manual' }); const sc = (pg.headers.getSetCookie ? pg.headers.getSetCookie() : []).join(' | '); t('page serves 200', pg.status === 200, pg.status); t('?ref= sets the sponsor cookie', /iap\.sponsor=unisharer/.test(sc), sc.slice(0, 160)); const br = await chromium.launch(); const errs = []; const page = await br.newPage({ viewport: { width: 1280, height: 900 } }); page.on('pageerror', e => errs.push(e.message)); page.on('console', m => { if (m.type() === 'error') errs.push(m.text()); }); await page.goto(B + '/chasing-unicorns?ref=unisharer', { waitUntil: 'domcontentloaded' }); await page.waitForTimeout(1500); if (process.argv.includes('--og')) { const og = await br.newPage({ viewport: { width: 1200, height: 630 }, deviceScaleFactor: 1 }); await og.goto(B + '/chasing-unicorns', { waitUntil: 'domcontentloaded' }); await og.waitForTimeout(3500); await og.evaluate(() => { const i = document.querySelector('.intro p'); if (i) i.hidden = true; }); await og.screenshot({ path: 'public/assets/chasing-unicorns-og.png' }); await og.close(); ok.push('share image written'); } const join0 = await page.$eval('#joinBtn', a => a.getAttribute('href')); t('join button keeps the sponsor', join0 === '/join/unisharer?src=chasing-unicorns', join0); t('ending is locked at first', await page.$eval('#after', e => e.hidden)); const flags = ['daily', 'withdraw', 'vip', 'team', 'clock', 'coin', 'keys']; for (const f of flags) { await page.click('.console [data-flag="' + f + '"] >> nth=0'); await page.waitForTimeout(150); const h = await page.$eval('#cardH', e => e.textContent); const open = await page.$eval('#veil', e => !e.hidden); t('flag ' + f + ' opens its card', open && h.length > 8, h); await page.click('#cardNext'); await page.waitForTimeout(100); } t('radar counts 7', (await page.$eval('#score', e => e.textContent)) === '7 of 8'); t('ending unlocks after 3', !(await page.$eval('#after', e => e.hidden))); await page.waitForSelector('#proof.on', { timeout: 12000 }).catch(() => {}); await page.click('#proof', { timeout: 5000 }).catch(() => {}); await page.waitForTimeout(150); const last = await page.$eval('#cardH', e => e.textContent).catch(() => ''); t('the popup is the 8th flag', /Dave from Denver|withdrew/.test(last), last); await page.click('#cardNext').catch(() => {}); await page.waitForTimeout(400); t('8 of 8 result', /8 of 8/.test(await page.$eval('#endH', e => e.textContent))); await page.screenshot({ path: 'qa/out/unicorns-end.png', fullPage: true }); const ph = await br.newPage({ viewport: { width: 390, height: 844 } }); ph.on('pageerror', e => errs.push(e.message)); await ph.goto(B + '/chasing-unicorns', { waitUntil: 'domcontentloaded' }); await ph.waitForTimeout(1200); const over = await ph.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); t('phone: no sideways scroll', over <= 1, over); await ph.screenshot({ path: 'qa/out/unicorns-phone.png' }); t('no page errors', !errs.filter(e => !/favicon/.test(e)).length, errs.join(' | ').slice(0, 300)); await br.close(); console.log(ok.map(x => ' ok ' + x).join('\n')); if (bad.length) console.log(bad.map(x => ' FAIL ' + x).join('\n')); bye(bad.length ? 1 : 0);