Network Weekend 2026, built dormant (Marty 2026-11-17): Black Friday to Cyber Monday, midnight to midnight Central

- promodays.js: reusable date-to-percent bonus map (setting promoDays, kill switch promoDaysOn), once per tx via marks (MySQL):
  Fri 11-27 +40% $5+, Sat/Sun +20% $5+, Mon 11-30 +30% $20+. A mapped Friday is paid by friday.js at max(fridayBonusPct, day pct),
  one bonus per tx, Game Pass Friday perk intact; Five Dollar Friday +20% resumes 12-04 with no hand edits.
- friday.js: Thanksgiving Thursday 18:00 CT notice + email carry the Black Friday copy (one message); Black Friday kickoff and
  wrap-up copy; /api/friday reports the day's real pct and name; IAP_TEST_NOW test clock (ignored in production).
- Weekend Starter Bundle ($20+ in the window: LinkSpin code WEEKEND500 on a purchase notice) and Builder Bundle ($100+: notice +
  GET /api/network/weekend-builders for DownlineHydra, X-Weekend-Key = env WEEKEND_BUNDLE_KEY, constant-time compare).
- promos.js: promo_codes.starts (dormant-until gate) for code NETWORKWEEKEND.
- gamepass.js: tier passes paid by a package Fri 11-27 00:00 CT to Fri 12-04 00:00 CT get Explorer/Champion +15 days, Legend +60.
- /weekend deals page (assets/weekend.js), Home strip + Overview card (assets/weekend-card.js), network ribbon (netdeals.js +
  assets/netweekend.js via common.js and netline.js), chatbot fact + answer date-gated.
- Share hosts: /weekend, /friday and other page names are pages, not usernames (email links use instantadpay.link: instantadpay.com
  is still on the Spamhaus DBL, checked 11-17).
- welcome.js says the day's real pct; common.js/netline.js/welcome.js ?v=20261117nw.
- Tests: qa/promodays.test.cjs (12) + qa/weekend.e2e.mjs (18) at test clocks; bash qa/run.sh weekend; member walk clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 07:59:55 -06:00
parent 72160c6a10
commit 218bb10145
46 changed files with 905 additions and 64 deletions
+195
View File
@@ -0,0 +1,195 @@
// Network Weekend 2026 (promodays.js + its friday.js, promos.js, gamepass.js and chatbot hooks). Every date gate is driven by the
// event time or the IAP_TEST_NOW test clock, never the machine clock. Fakes only: no chain, no DB, no mail, no network.
// node --test qa/promodays.test.cjs
'use strict';
const test = require('node:test');
const assert = require('node:assert');
const fs = require('fs'); const os = require('os'); const path = require('path');
process.env.NODE_ENV = 'test';
const DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-'));
const ROOT = path.join(__dirname, '..');
const T = s => Date.parse(s);
function fresh(mod) { delete require.cache[require.resolve(path.join(ROOT, mod))]; return require(path.join(ROOT, mod)); }
function rig(events, site) {
const granted = [], notices = [], mails = [], posts = [], claimed = new Set();
const deps = {
dataDir: fs.mkdtempSync(path.join(DIR, 'd-')), siteConfig: () => Object.assign({}, site || {}),
chain: { recentEvents: () => events.slice(), member: async id => ({ account: '0x' + String(id).padStart(40, 'a') }) },
ads: { addEarned: async (email, n, o) => granted.push({ email, n, note: o.log.note, purchased: o.purchased }) },
accounts: { byMemberId: async id => ({ email: 'm' + id + '@x.test', memberId: id }), listAll: async () => [{ email: 'a@x.test', memberId: 7, lastSeen: T('2026-11-20T00:00:00Z') }] },
marks: { claim: async k => { if (claimed.has(k)) return false; claimed.add(k); return true; } },
notify: async (id, subject, text) => notices.push({ id, subject, text }),
telegram: async t => { posts.push(t); return true; },
mailer: { hasKey: () => true, send: async (to, subject, text) => mails.push({ to, subject, text }) }, drip: { isUnsubscribed: async () => false }
};
const pd = fresh('promodays.js'); pd.init(deps);
const fr = fresh('friday.js'); fr.init(Object.assign({}, deps, { promodays: pd }));
return { pd, fr, granted, notices, mails, posts, deps };
}
let n = 0;
const buy = (iso, cents, credits, id) => ({ type: 'Purchase', tx: '0xtx' + (++n), li: 0, ts: T(iso), buyerId: id || 11, priceCents: cents, creditAmount: credits });
test('the map: each day is midnight to midnight Central (CST, UTC-6)', () => {
const { pd } = rig([]);
assert.strictEqual(pd.dayAt(T('2026-11-27T05:59:59Z')), null); // Thu 23:59:59 CT
assert.strictEqual(pd.dayAt(T('2026-11-27T06:00:00Z')).pct, 40); // Fri 00:00 CT
assert.strictEqual(pd.dayAt(T('2026-11-28T05:59:59Z')).name, 'Black Friday');
assert.strictEqual(pd.dayAt(T('2026-11-28T06:00:00Z')).pct, 20);
assert.strictEqual(pd.dayAt(T('2026-11-29T12:00:00Z')).pct, 20);
const m = pd.dayAt(T('2026-11-30T06:00:00Z')); assert.strictEqual(m.pct, 30); assert.strictEqual(m.minCents, 2000);
assert.strictEqual(pd.dayAt(T('2026-12-01T05:59:59Z')).name, 'Cyber Monday');
assert.strictEqual(pd.dayAt(T('2026-12-01T06:00:00Z')), null); // Tue 00:00 CT: off
assert.strictEqual(pd.inWeekend(T('2026-11-27T06:00:00Z')), true);
assert.strictEqual(pd.inWeekend(T('2026-12-01T06:00:00Z')), false);
});
test('Black Friday: ONE bonus per tx at 40% through friday.js, not 20 + 40, and nobody flips fridayBonusPct', async () => {
const ev = buy('2026-11-27T15:00:00Z', 500, 500);
const r = rig([ev], { fridayBonusPct: '20' });
assert.strictEqual(await r.fr.onEvent(ev), 200); // 40% of 500
assert.strictEqual(await r.fr.onEvent(ev), null); // same tx again: nothing
const p = await r.pd.onEvent(ev); assert.strictEqual(p.bonus, 0); // promodays never pays a Friday
assert.deepStrictEqual(r.granted.map(g => g.n), [200]);
assert.match(r.granted[0].note, /^Black Friday: \+40% on your \$5 package/);
assert.ok(r.notices.some(x => /^Black Friday: \+200 bonus credits/.test(x.subject) && /Ad credits buy advertising, not income\./.test(x.text)));
});
test('a normal Friday after the weekend is Five Dollar Friday +20% again (12-04)', async () => {
const ev = buy('2026-12-04T15:00:00Z', 500, 500);
const r = rig([ev], { fridayBonusPct: '20' });
assert.strictEqual(await r.fr.onEvent(ev), 100);
assert.match(r.granted[0].note, /^Five Dollar Friday: \+20%/);
assert.strictEqual((await r.pd.onEvent(ev)).bonus, 0);
});
test('Saturday and Sunday +20% on $5+, Cyber Monday +30% on $20+ only, Tuesday nothing; once per tx', async () => {
const sat = buy('2026-11-28T06:00:00Z', 500, 500), sun = buy('2026-11-30T05:59:00Z', 1000, 1000);
const mon10 = buy('2026-11-30T18:00:00Z', 1000, 1000), mon20 = buy('2026-11-30T18:00:00Z', 2000, 2000), tue = buy('2026-12-01T06:00:00Z', 2000, 2000);
const r = rig([sat, sun, mon10, mon20, tue]);
assert.strictEqual((await r.pd.onEvent(sat)).bonus, 100);
assert.strictEqual((await r.pd.onEvent(sat)).bonus, 0);
assert.strictEqual((await r.pd.onEvent(sun)).bonus, 200);
assert.strictEqual((await r.pd.onEvent(mon10)).bonus, 0);
assert.strictEqual((await r.pd.onEvent(mon20)).bonus, 600);
assert.strictEqual((await r.pd.onEvent(tue)).bonus, 0);
assert.deepStrictEqual(r.granted.map(g => g.note.split(':')[0]), ['Network Weekend Saturday', 'Network Weekend Sunday', 'Cyber Monday']);
assert.ok(r.granted.every(g => g.purchased));
assert.strictEqual(await r.fr.onEvent(sat), null); // friday.js never pays a Saturday
});
test('bundles: $20+ in the window shows the LinkSpin code; $100+ also says DownlineHydra Pro; outside the window nothing', async () => {
const s20 = buy('2026-11-29T15:00:00Z', 2000, 2000), b100 = buy('2026-11-27T06:00:01Z', 10000, 12000, 21), b5 = buy('2026-11-28T15:00:00Z', 500, 500);
const late = buy('2026-12-01T06:00:00Z', 10000, 12000), early = buy('2026-11-27T05:59:59Z', 10000, 12000);
const r = rig([s20, b100, b5, late, early], { weekendLinkspinCode: 'weekend500' });
const a = await r.pd.onEvent(s20); assert.ok(a.starter && !a.builder);
const b = await r.pd.onEvent(b100); assert.ok(b.starter && b.builder);
assert.ok(!(await r.pd.onEvent(b5)).starter);
assert.ok(!(await r.pd.onEvent(late)).starter && !(await r.pd.onEvent(early)).starter);
assert.ok(!(await r.pd.onEvent(s20)).starter, 'once per tx');
const bn = r.notices.filter(x => x.subject === 'Network Weekend: your bundle extras');
assert.strictEqual(bn.length, 2);
assert.ok(bn.every(x => /WEEKEND500/.test(x.text) && /linkspin\.app/.test(x.text) && /Ad credits buy advertising, not income\./.test(x.text)));
assert.ok(/DownlineHydra Pro/.test(bn[1].text) && /first 25 comps/.test(bn[1].text) && !/DownlineHydra/.test(bn[0].text));
});
test('builders list for DownlineHydra: $100+ packs from Fri 00:00 CT to Tue 00:00 CT, lowercase wallets', async () => {
const evs = [buy('2026-11-27T05:59:59Z', 10000, 12000, 1), buy('2026-11-27T06:00:00Z', 10000, 12000, 2), buy('2026-11-30T20:00:00Z', 25000, 32500, 3),
buy('2026-11-30T20:00:00Z', 5000, 5500, 4), buy('2026-12-01T06:00:00Z', 50000, 70000, 5), { type: 'MemberActivated', id: 2, account: '0xABCDEF0000000000000000000000000000000002', tx: 'x', ts: 1 }];
const r = rig(evs);
const out = await r.pd.builders();
assert.deepStrictEqual(out.builders.map(b => b.usdCents), [10000, 25000]);
assert.strictEqual(out.builders[0].wallet, '0xabcdef0000000000000000000000000000000002');
assert.match(out.builders[1].wallet, /^0x[a]+3$/);
assert.strictEqual(out.cap, 25);
});
test('Thanksgiving Thu 11-26 18:00 CT: the Friday notice and email carry the Black Friday copy, once; a normal Thursday stays normal', async () => {
try {
process.env.IAP_TEST_NOW = '2026-11-26T23:59:00Z'; // Thu 17:59 CT: not yet
let r = rig([]); await r.fr.tick(); assert.strictEqual(r.mails.length, 0);
process.env.IAP_TEST_NOW = '2026-11-27T00:05:00Z'; // Thu 18:05 CT
await r.fr.tick(); await r.fr.tick();
assert.strictEqual(r.mails.length, 1, 'one email, not two');
assert.strictEqual(r.mails[0].subject, 'Black Friday starts at midnight: Network Weekend');
assert.match(r.mails[0].text, /midnight to midnight/); assert.match(r.mails[0].text, /\+40% bonus ad credits on any \$5\+ pack/);
assert.match(r.mails[0].text, /Ad credits buy advertising, not income\./); assert.ok(!/—/.test(r.mails[0].text));
assert.strictEqual(r.notices.filter(x => /Black Friday starts/.test(x.subject)).length, 1);
process.env.IAP_TEST_NOW = '2026-12-04T00:05:00Z'; // Thu 12-03 18:05 CT: normal Five Dollar Friday copy
r = rig([]); await r.fr.tick(); assert.strictEqual(r.mails[0].subject, 'Tomorrow is Five Dollar Friday');
process.env.IAP_TEST_NOW = '2026-11-27T11:05:00Z'; // Fri 05:05 CT kickoff: Black Friday copy
r = rig([]); await r.fr.tick(); assert.ok(r.posts.length === 1 && /Black Friday\. Network Weekend is live/.test(r.posts[0]) && /\+40%/.test(r.posts[0]));
process.env.IAP_TEST_NOW = '2026-11-25T23:30:00Z'; // the Friday page/strip on Wed 11-25 already says the coming Friday is +40%
r = rig([]); const v = r.fr.view(); assert.strictEqual(v.pct, 40); assert.strictEqual(v.name, 'Black Friday');
} finally { delete process.env.IAP_TEST_NOW; }
});
test('promoDaysOn 0 switches everything off; a promoDays setting replaces the map for a future holiday', async () => {
const ev = buy('2026-11-28T15:00:00Z', 500, 500);
let r = rig([ev], { promoDaysOn: '0' }); assert.strictEqual((await r.pd.onEvent(ev)).bonus, 0); assert.strictEqual(r.pd.passBonusDays('legend', ev.ts), 0);
r = rig([], { promoDays: JSON.stringify({ '2027-07-04': { pct: 15, minCents: 500, name: 'Fourth of July' } }) });
assert.strictEqual(r.pd.dayAt(T('2027-07-04T17:00:00Z')).pct, 15); assert.strictEqual(r.pd.dayAt(T('2026-11-28T15:00:00Z')), null);
});
test('Game Pass bonus days: Explorer/Champion +15, Legend +60, packages fulfilled Fri 11-27 00:00 CT to Fri 12-04 00:00 CT', () => {
const { pd } = rig([]);
assert.strictEqual(pd.passBonusDays('explorer', T('2026-11-27T05:59:59Z')), 0);
assert.strictEqual(pd.passBonusDays('explorer', T('2026-11-27T06:00:00Z')), 15);
assert.strictEqual(pd.passBonusDays('champion', T('2026-12-04T05:59:59Z')), 15); // Thu 12-03 23:59:59 CT
assert.strictEqual(pd.passBonusDays('legend', T('2026-12-01T12:00:00Z')), 60);
assert.strictEqual(pd.passBonusDays('legend', T('2026-12-04T06:00:00Z')), 0);
assert.strictEqual(pd.passBonusDays('weekly', T('2026-11-28T12:00:00Z')), 0);
assert.strictEqual(pd.passBonusDays('sovereign', T('2026-11-28T12:00:00Z')), 0);
});
test('chatbot: fact and answer only around the window; the Friday question on Black Friday gets 40%', () => {
const { pd } = rig([]);
assert.strictEqual(pd.chatFact(T('2026-11-25T12:00:00Z')), '');
assert.match(pd.chatFact(T('2026-11-26T12:00:00Z')), /starts Fri 2026-11-27 00:00 Central/);
assert.match(pd.chatFact(T('2026-11-28T12:00:00Z')), /LIVE now/);
assert.match(pd.chatFact(T('2026-12-02T12:00:00Z')), /is over/);
assert.strictEqual(pd.chatFact(T('2026-12-04T06:00:00Z')), '');
assert.strictEqual(pd.chatAnswer('what is five dollar friday', T('2026-11-20T12:00:00Z')), null);
assert.match(pd.chatAnswer('any black friday deal?', T('2026-11-27T15:00:00Z')), /Today is Black Friday: \+40% bonus ad credits on any \$5\+ pack/);
assert.match(pd.chatAnswer('cyber monday?', T('2026-11-30T15:00:00Z')), /Today is Cyber Monday: \+30% .* \$20\+/);
assert.strictEqual(pd.chatAnswer('black friday', T('2026-12-01T06:00:00Z')), null);
for (const t of ['2026-11-26T12:00:00Z', '2026-11-28T12:00:00Z']) assert.ok(!/—|up to/i.test(pd.chatFact(T(t)) + pd.chatAnswer('network weekend', T(t))));
});
test('promo code start gate (NETWORKWEEKEND): dormant until Fri 00:00 CT, expired at Tue 00:00 CT', async () => {
process.env.DATABASE_URL = ''; delete process.env.DOCSTORE_URL;
const promos = fresh('promos.js'); promos.init({ dataDir: fs.mkdtempSync(path.join(DIR, 'p-')) });
const r = await promos.create({ code: 'NETWORKWEEKEND', credits: 300, maxUses: 300, starts: '2026-11-27T00:00:00-06:00', expires: '2026-12-01T00:00:00-06:00', note: 'Network Weekend 2026' });
assert.ok(r.ok); assert.strictEqual(r.code.starts, T('2026-11-27T06:00:00Z'));
try {
process.env.IAP_TEST_NOW = '2026-11-27T05:59:59Z'; assert.match((await promos.check('networkweekend', 'a@x.test')).error, /opens Friday, Nov 27, 12:00 AM Central/);
process.env.IAP_TEST_NOW = '2026-11-27T06:00:00Z'; assert.strictEqual(await promos.check('NETWORKWEEKEND', 'a@x.test'), null);
const g = await promos.redeem('NETWORKWEEKEND', 'a@x.test', 'dashboard'); assert.strictEqual(g.credits, 300); assert.strictEqual(g.step, 60);
assert.match((await promos.redeem('NETWORKWEEKEND', 'a@x.test', 'dashboard')).error, /already used/);
process.env.IAP_TEST_NOW = '2026-12-01T05:59:59Z'; assert.strictEqual(await promos.check('NETWORKWEEKEND', 'b@x.test'), null);
process.env.IAP_TEST_NOW = '2026-12-01T06:00:01Z'; assert.match((await promos.check('NETWORKWEEKEND', 'b@x.test')).error, /expired/);
// an update without starts keeps it (the admin form never drops the gate)
const u = await promos.create({ code: 'NETWORKWEEKEND', credits: 300, maxUses: 300, expires: '2026-12-01T00:00:00-06:00' }); assert.strictEqual(u.code.starts, T('2026-11-27T06:00:00Z'));
} finally { delete process.env.IAP_TEST_NOW; }
});
test.after(() => fs.rmSync(DIR, { recursive: true, force: true }));
test('gamepass: a tier pass paid by a package in the window gets the bonus days; the weekly pass and comps never do', async () => {
const maps = {}; const pm = k => (maps[k] = maps[k] || new Map());
const { pd } = rig([]);
const gp = fresh('gamepass.js');
gp.init({ dataDir: fs.mkdtempSync(path.join(DIR, 'g-')), siteConfig: () => ({ gamePassEnabled: '1', sovTiers: '1' }), accounts: { byMemberId: async () => ({ email: 'p@x.test' }) },
marks: { claim: async () => true }, isProd: false, persistedMap: pm, polUsd: async () => 0.2, blockTime: async () => 0, notify: async () => {}, telegram: async () => {},
bonusDays: (tier, ts) => pd.passBonusDays(tier, ts) });
const D = 86400000;
const pay = async (tier, cents, iso, tx) => {
pm('gporders').set('o-' + tx, { status: 'waiting', email: 'p@x.test', ts: T(iso) - 60000, tier });
return gp.onEvent({ type: 'Purchase', tx, ts: T(iso), buyerId: 9, priceCents: cents, devEmail: 'p@x.test', devMinedAt: T(iso) });
};
let r = await pay('explorer', 2000, '2026-11-28T12:00:00Z', '0xe1'); assert.strictEqual(Math.round((r.until - T('2026-11-28T12:00:00Z')) / D), 45);
r = await pay('legend', 25000, '2026-12-03T23:00:00Z', '0xl1'); assert.strictEqual(Math.round((r.until - T('2026-12-03T23:00:00Z')) / D), 425);
r = await pay('champion', 5000, '2026-12-04T06:00:00Z', '0xc1'); assert.strictEqual(Math.round((r.until - T('2026-12-04T06:00:00Z')) / D), 30); // Fri 12-04 00:00 CT: over
r = await pay('weekly', 500, '2026-11-28T12:00:00Z', '0xw1'); assert.strictEqual(Math.round((r.until - T('2026-11-28T12:00:00Z')) / D), 7);
const c = gp.comp('q@x.test', 'test', 'explorer', T('2026-11-28T12:00:00Z')); assert.strictEqual(c.days, 30);
});
+5
View File
@@ -24,6 +24,7 @@
# bash qa/run.sh fuel # Fuel Your Offers: refill notices, refuel streak, Refuel Kit, Engine Room (unit + two-copy tests, throwaway data)
# bash qa/run.sh policy # profile policy + link-farm scan: prohibited list, bio links, quarantine, 06:30 claim, walls of free/paying members, 404 walls (unit + local copy; also runs in member)
# bash qa/run.sh bixpay # BixPay card: partner-link validator, sponsor-follows resolver (own / level 3 / company), gate, click store (unit, no server; also runs in member)
# bash qa/run.sh weekend # Network Weekend 2026 (promodays.js): unit tests + local e2e at Black Friday / Cyber Monday / before / after test clocks
# bash qa/run.sh theme # light/dark themes: WCAG contrast of the main text/background pairs on the member area, admin and public pages, both themes (local copy)
# QA_THEME=dark bash qa/run.sh member # walk every pane in one theme; screenshots land as *-dark.png / *-light.png
# Each local run boots server.js on its own port with a throwaway data dir (JSON store, no DB, no
@@ -82,6 +83,10 @@ elif [ "$MODE" = "member" ]; then
node qa/profile-policy.test.cjs || status=1
node qa/sov-heroes-store.cjs || status=1
node qa/erase.test.cjs || status=1 # member erase (erase.js + scrub.js, 2026-11-15); qa/erase.mysql.test.cjs needs TEST_DATABASE_URL
node --test qa/promodays.test.cjs || status=1 # Network Weekend 2026: promo days, Black Friday via friday.js, bundles, code start gate, pass days (2026-11-17)
elif [ "$MODE" = "weekend" ]; then
node --test qa/promodays.test.cjs || status=1
node qa/weekend.e2e.mjs || status=1 # /weekend, Home strip, ribbon, feeds, builders key at test clocks (local copies + a fake hub)
elif [ "$MODE" = "draft" ]; then
node qa/draft-partner.test.mjs || status=1
elif [ "$MODE" = "theme" ]; then
+94
View File
@@ -0,0 +1,94 @@
// Network Weekend end to end on a local copy (throwaway data, JSON store, no DB, no mail key): the /weekend page, the Home strip,
// the ribbon, /api/promodays, /api/network-deals (from a fake hub that serves the real network-hub deal list at the test time),
// and the DownlineHydra builders feed's key check. The test clock is IAP_TEST_NOW (server) + window.__NW_NOW (pages).
// node qa/weekend.e2e.mjs (needs ../../network-hub/lib/deals.js beside this repo, playwright from qa-tester)
import http from 'node:http'; import { spawn } from 'node:child_process'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path';
import { createRequire } from 'node:module'; import assert from 'node:assert';
const require = createRequire(import.meta.url);
const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1')), '..');
const { chromium } = require(process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright');
const deals = require(path.resolve(ROOT, '../../network-hub/lib/deals.js'));
const KEY = 'k'.repeat(48);
const out = []; const ok = m => { out.push('ok ' + m); console.log('ok', m); };
async function run(nowIso, port) {
const hub = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(deals.current(Date.parse(nowIso)))); });
await new Promise(r => hub.listen(0, r));
const data = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-nw-')); fs.mkdirSync(path.join(data, 'uploads'));
const env = Object.assign({}, process.env, { PORT: String(port), DATA_DIR: data, ADMIN_PASSWORD: 'localtest', IAP_TEST_NOW: nowIso, HUB_URL: 'http://127.0.0.1:' + hub.address().port, WEEKEND_BUNDLE_KEY: KEY, NODE_ENV: 'test', DATABASE_URL: '', DOCSTORE_URL: '' });
const srv = spawn(process.execPath, ['server.js'], { cwd: ROOT, env, stdio: ['ignore', 'pipe', 'pipe'] });
let log = ''; srv.stdout.on('data', d => { log += d; }); srv.stderr.on('data', d => { log += d; });
const base = 'http://127.0.0.1:' + port;
try {
for (let i = 0; i < 40; i++) { try { if ((await fetch(base + '/api/config')).ok) break; } catch (e) {} await new Promise(r => setTimeout(r, 500)); }
return await fn(base, nowIso);
} finally { srv.kill(); hub.close(); fs.rmSync(data, { recursive: true, force: true }); if (process.env.QA_LOG) console.log(log.slice(-3000)); }
}
let fn;
(async () => {
const browser = await chromium.launch();
const page = async (base, nowIso, p) => {
const ctx = await browser.newContext(); const pg = await ctx.newPage(); const errs = [];
pg.on('pageerror', e => errs.push(e.message)); pg.on('console', m => { if (m.type() === 'error' && /Content Security Policy|Refused/.test(m.text())) errs.push(m.text()); });
await pg.addInitScript(t => { window.__NW_NOW = t; }, Date.parse(nowIso));
await pg.goto(base + p, { waitUntil: 'networkidle' }); await pg.waitForTimeout(800);
return { pg, ctx, errs };
};
// 1. Black Friday 09:00 CT
fn = async (base, nowIso) => {
const v = await (await fetch(base + '/api/promodays')).json();
assert.ok(v.live && v.today.name === 'Black Friday' && v.today.pct === 40 && v.lsCode === 'WEEKEND500'); ok('Black Friday /api/promodays live 40%');
const f = await (await fetch(base + '/api/friday')).json(); assert.ok(f.live && f.pct === 40 && f.name === 'Black Friday'); ok('/api/friday says Black Friday +40%');
const d = await (await fetch(base + '/api/network-deals')).json(); assert.strictEqual(d.self, 'iap'); assert.ok(d.events[0] && d.events[0].deals.length > 5); ok('/api/network-deals relays the hub');
assert.strictEqual((await fetch(base + '/api/network/weekend-builders')).status, 401);
assert.strictEqual((await fetch(base + '/api/network/weekend-builders', { headers: { 'X-Weekend-Key': 'x'.repeat(48) } })).status, 401);
const b = await fetch(base + '/api/network/weekend-builders', { headers: { 'X-Weekend-Key': KEY } }); assert.strictEqual(b.status, 200);
const bj = await b.json(); assert.ok(Array.isArray(bj.builders) && bj.cap === 25 && bj.start === '2026-11-27T06:00:00.000Z'); ok('builders feed: key required, shape right');
let { pg, ctx, errs } = await page(base, nowIso, '/weekend');
const state = await pg.textContent('#nwState'); assert.match(state, /It is Black Friday\. \+40% bonus ad credits on any \$5\+/); ok('/weekend live state');
assert.strictEqual(await pg.locator('.nw-day').count(), 4); assert.ok(await pg.locator('.nw-day.today').count() === 1);
assert.ok((await pg.locator('.nw-deal').count()) > 8); ok('/weekend day cards + every network deal');
assert.ok(await pg.locator('.nw-ribbon').count() === 1 && /Black Friday/.test(await pg.textContent('.nw-ribbon'))); ok('ribbon on /weekend (no self link)');
assert.strictEqual(await pg.locator('.nw-ribbon a').count(), 0);
await pg.screenshot({ path: path.join(ROOT, 'qa/out/weekend-live.png'), fullPage: true });
assert.deepStrictEqual(errs, []); await ctx.close();
({ pg, ctx, errs } = await page(base, nowIso, '/'));
assert.match(await pg.textContent('#nwStrip'), /Network Weekend: it\u2019s Black Friday\. \+40%/); ok('Home strip live');
assert.ok(/Ad credits buy advertising, not income\./.test(await pg.textContent('#nwStrip')));
assert.strictEqual(await pg.locator('.nw-ribbon').count(), 1); ok('ribbon on Home');
await pg.screenshot({ path: path.join(ROOT, 'qa/out/weekend-home.png') });
assert.deepStrictEqual(errs, []); await ctx.close();
};
await run('2026-11-27T15:00:00Z', 8811);
// 2. Wed 11-18 (today-ish): nothing shows anywhere
fn = async (base, nowIso) => {
const v = await (await fetch(base + '/api/promodays')).json(); assert.ok(!v.live && !v.published && v.days.length === 0); ok('before Thursday: /api/promodays publishes nothing');
const f = await (await fetch(base + '/api/friday')).json(); assert.strictEqual(f.pct, 20); ok('a normal week: Friday +20%');
let { pg, ctx, errs } = await page(base, nowIso, '/weekend');
assert.match(await pg.textContent('#nwState'), /Coming/); assert.strictEqual(await pg.locator('.nw-ribbon').count(), 0); assert.strictEqual(await pg.locator('.nw-deal').count(), 0); ok('/weekend dormant, no ribbon');
assert.deepStrictEqual(errs, []); await ctx.close();
({ pg, ctx, errs } = await page(base, nowIso, '/'));
assert.strictEqual(await pg.locator('#nwStrip:not([hidden])').count(), 0); assert.strictEqual(await pg.locator('.nw-ribbon').count(), 0); ok('Home: no strip, no ribbon');
assert.deepStrictEqual(errs, []); await ctx.close();
};
await run('2026-11-18T15:00:00Z', 8812);
// 3. Thanksgiving 20:00 CT: heads-up strip, no ribbon yet; Cyber Monday; Tuesday off
fn = async (base, nowIso) => {
let { pg, ctx } = await page(base, nowIso, '/');
assert.match(await pg.textContent('#nwStrip'), /starts at midnight Central/); assert.strictEqual(await pg.locator('.nw-ribbon').count(), 0); ok('Thanksgiving: heads-up strip, ribbon not yet');
await ctx.close();
};
await run('2026-11-27T02:00:00Z', 8813);
fn = async (base, nowIso) => {
const v = await (await fetch(base + '/api/promodays')).json(); assert.ok(v.live && v.today.pct === 30 && v.today.minUsd === 20); ok('Cyber Monday +30% $20+');
const { pg, ctx } = await page(base, nowIso, '/weekend'); assert.match(await pg.textContent('.nw-ribbon'), /Cyber Monday[\s\S]*\+30% bonus ad credits on any \$20\+/); ok('ribbon Cyber Monday text'); await ctx.close();
};
await run('2026-11-30T20:00:00Z', 8814);
fn = async (base, nowIso) => {
const v = await (await fetch(base + '/api/promodays')).json(); assert.ok(!v.live && v.today === null && v.passBonusLive === true); ok('Tue 12-01: weekend off, pass days still on');
const { pg, ctx } = await page(base, nowIso, '/'); assert.strictEqual(await pg.locator('.nw-ribbon').count(), 0); assert.strictEqual(await pg.locator('#nwStrip:not([hidden])').count(), 0); ok('Tue: no ribbon, no strip'); await ctx.close();
};
await run('2026-12-01T15:00:00Z', 8815);
await browser.close();
console.log('ALL OK weekend e2e (' + out.length + ' checks)');
})().catch(e => { console.error('FAIL', e.message); process.exit(1); });