218bb10145
- 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>
196 lines
15 KiB
JavaScript
196 lines
15 KiB
JavaScript
// 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);
|
|
});
|