Spooky Doors launch pack (IAP side): door packs + Golden Doors, Promo tools card, season from Oct 4

- Visit packs get a placement: 'all' (as before), 'doors' (Behind Spooky Doors, doorPackCost 4/door) or
  'golden' (Golden Spooky Door, goldenDoorCost 6/door). campaigns.placement column (alterSafe) + JSON store.
- Doors serve golden packs first, then door packs, then the existing chain; each pack at most once per
  player per Central day. Door-only packs never reach the Earn tab, refuels or the PassiveDrip listing
  until rates.sdSeasonEnd ('2026-11-01'); from then on they behave as 'all'.
- Door payloads: credits = per-door price actually charged (3/4/6); Golden Doors add golden: true and
  bonus: goldenBonusCandy (2) to /api/door/open, done, callback and receipt. Gold variant of /door.
- Campaign list: Spooky Doors / Golden Door chip, doors opened + unique players, Buy more doors at the
  door price. Composer: placement choice with live cost. Admin rates labels + house pack placement.
- Promo tools: Spooky Doors card (spookydoors.com/r/<username>, copy, share image, two posts) on the same
  season window as the Games card (seasonState helper).
- Season start moved up to 2026-10-04 (Games card + promo card + chatbot).
- qa/door.mjs covers all of the above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-02 15:55:19 -05:00
parent 9809953ae0
commit a5a991d024
13 changed files with 228 additions and 41 deletions
+91 -5
View File
@@ -5,7 +5,9 @@
// Covers: open -> challenge (wrong pick, then right) -> done -> callback signature + receipt, re-open after done,
// house ads when the street is empty (RM Circle first, then the next program with the player's ref; credits 0, counted),
// "nobody's home" only with doorHouseAds = [] (none=1, door not counted), cap (cap=1), the door/refuel/earn caps staying separate, bad tokens,
// and the Games card season window. Exit code 1 on any failure.
// the Games card + Promo tools card season window, and door packs + Golden Doors (placement 'doors'/'golden': prices, golden first,
// door pack second, once per player per Central day, credits/golden/bonus in open + callback + receipt, never on Earn or refuels in
// season, ordinary visits from sdSeasonEnd, advertiser door stats). Exit code 1 on any failure.
import http from 'node:http';
import crypto from 'node:crypto';
import fs from 'node:fs';
@@ -182,9 +184,12 @@ try {
const today = new Date().toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
const gA = (await api('/api/my/games', null, { Cookie: adminCookie })).j; const sdA = gA && (gA.games || []).find(g => g.slug === 'spookydoors');
const gM = (await api('/api/my/games', null, { Cookie: playerCookie })).j; const sdM = gM && (gM.games || []).find(g => g.slug === 'spookydoors');
if (today < '2026-10-17') { ok(sdA && sdA.preview && sdA.season && sdA.season.ends === 'Oct 31' && /opens Oct 17/.test(sdA.previewNote || ''), 'before the season: admin sees a preview card ending Oct 31', JSON.stringify(sdA ? { preview: sdA.preview, season: sdA.season, note: sdA.previewNote } : gA)); ok(!sdM, 'before the season: members do not see the card'); }
else if (today < '2026-11-01') { ok(sdA && sdA.season && sdA.season.ends === 'Oct 31', 'in season: admin sees the card with the ribbon date'); ok(!sdM, 'in season but not in gamesLive: members do not see it'); }
else { ok(!sdA && !sdM, 'after the season: nobody sees the card'); }
const pA = (await api('/api/my/spookydoors/promo', null, { Cookie: adminCookie })).j, pM = (await api('/api/my/spookydoors/promo', null, { Cookie: playerCookie })).j;
if (today < '2026-10-04') { ok(sdA && sdA.preview && sdA.season && sdA.season.start === '2026-10-04' && sdA.season.ends === 'Oct 31' && /opens Oct 4/.test(sdA.previewNote || ''), 'before the season (starts Oct 4): admin sees a preview card ending Oct 31', JSON.stringify(sdA ? { preview: sdA.preview, season: sdA.season, note: sdA.previewNote } : gA)); ok(!sdM, 'before the season: members do not see the card');
ok(pA && pA.show && pA.preview && pA.base === SD && pA.image === SD + '/og-spookydoors.jpg' && pM && pM.show === false, 'Promo tools card: admin preview before the season, hidden for members', JSON.stringify({ pA, pM })); }
else if (today < '2026-11-01') { ok(sdA && sdA.season && sdA.season.ends === 'Oct 31', 'in season: admin sees the card with the ribbon date'); ok(!sdM, 'in season but not in gamesLive: members do not see it');
ok(pA && pA.show && !pA.preview && pM && pM.show && !pM.preview && pM.image === SD + '/og-spookydoors.jpg', 'Promo tools card: shown to members in season', JSON.stringify({ pA, pM })); }
else { ok(!sdA && !sdM, 'after the season: nobody sees the card'); ok(pA && pA.show === false && pM && pM.show === false, 'Promo tools card: hidden after the season'); }
// 7. costume shop: signed-out detour, confirm with CSRF, receipt + server callback, idempotent re-open, short of credits
const order = 'qa-' + crypto.randomBytes(6).toString('hex');
@@ -212,7 +217,88 @@ try {
const big = mint({ kind: 'sd-buy', order: order + 'x', email: player, memberId: 77, item: 'apple', label: 'Lucky caramel apple', credits: 999999, ret: SD + '/api/iap/receipt', cb: SD + '/api/iap/credit' }, null, 7200000);
const bh = await (await fetch(B + '/sd/shop?t=' + encodeURIComponent(big), { headers: { Cookie: playerCookie } })).text();
ok(/more credits/.test(bh) && /\/sd\/shop\/topup\?t=/.test(bh), 'short of credits -> top-up offer');
} catch (e) { fails++; console.log('FAIL exception: ' + e.message); }
// 8. door packs + Golden Doors (launch pack A, 2026-10-02)
const rt0 = (await api('/api/admin/rates', null, adminH)).j.rates;
ok(rt0.visitCostPerVisit === 3 && rt0.doorPackCost === 4 && rt0.goldenDoorCost === 6 && rt0.goldenBonusCandy === 2 && rt0.sdSeasonEnd === '2026-11-01', 'rates: visit 3, door pack 4, Golden Door 6, golden bonus 2, season end 2026-11-01', JSON.stringify({ v: rt0.visitCostPerVisit, d: rt0.doorPackCost, g: rt0.goldenDoorCost, b: rt0.goldenBonusCandy, e: rt0.sdSeasonEnd }));
await api('/api/admin/rates', { method: 'PATCH', data: { sdSeasonEnd: '2099-01-01', doorCapPerDay: 15, doorRepeatDays: 7 } }, adminH); // in season whatever today is
const mkPack = async (title, placement) => { let x = await api('/api/admin/campaigns', { type: 'visits', name: title, targetUrl: SD + '/' + placement, title, count: 20, placement }, adminH);
if (!(x.j && x.j.ok)) x = await api('/api/admin/campaigns', { type: 'visits', name: title, targetUrl: 'https://rmcircle.team/contract', title, count: 20, placement }, adminH); return x.j; };
const gp = await mkPack('QA golden door', 'golden'), dp = await mkPack('QA door pack', 'doors');
ok(gp && gp.ok && gp.campaign.placement === 'golden' && gp.campaign.budget === 120 && gp.campaign.doorOnly === true, 'Golden Door pack: 20 doors = 120 credits, placement golden', JSON.stringify(gp && gp.campaign && { pl: gp.campaign.placement, budget: gp.campaign.budget, doorOnly: gp.campaign.doorOnly }));
ok(dp && dp.ok && dp.campaign.placement === 'doors' && dp.campaign.budget === 80, 'door pack: 20 doors = 80 credits, placement doors', JSON.stringify(dp && dp.campaign && { pl: dp.campaign.placement, budget: dp.campaign.budget }));
const badPl = await api('/api/admin/campaigns', { type: 'visits', name: 'x', targetUrl: 'https://rmcircle.team/contract', title: 'x', count: 20, placement: 'roof' }, adminH);
ok(badPl.status === 400 && /Pick where/.test(badPl.j && badPl.j.error || ''), 'unknown placement refused');
// a member buys a door pack with their own credits (charged up front, 4 a door) and tops it up at the door price
const before = (await api('/api/my/campaigns', null, { Cookie: playerCookie })).j;
let mp = await api('/api/my/campaigns', { type: 'visits', name: 'QA member doors', targetUrl: SD + '/member-doors', title: 'QA member doors', count: 20, placement: 'doors', budget: 80 }, { Cookie: playerCookie });
if (!(mp.j && mp.j.ok)) mp = await api('/api/my/campaigns', { type: 'visits', name: 'QA member doors', targetUrl: 'https://rmcircle.team/contract', title: 'QA member doors', count: 20, placement: 'doors', budget: 80 }, { Cookie: playerCookie });
const mpc = mp.j && mp.j.campaign;
const after = (await api('/api/my/campaigns', null, { Cookie: playerCookie })).j;
ok(mpc && mpc.placement === 'doors' && mpc.budget === 80 && before.availableCredits - after.availableCredits === 80, 'member door pack charged 80 up front', JSON.stringify({ c: mpc && { pl: mpc.placement, budget: mpc.budget }, err: mp.j && mp.j.error, avail: [before.availableCredits, after.availableCredits] }));
const tu = (await api('/api/my/campaigns/' + (mpc && mpc.id) + '/topup', { credits: 12 }, { Cookie: playerCookie })).j;
ok(tu && tu.ok && tu.visits === 3 && tu.added === 12 && tu.total === 23, 'door pack top-up buys doors at 4 credits', JSON.stringify(tu));
const T_GOLD = gp.campaign.id, T_DOORS = [dp.campaign.id, mpc && mpc.id];
// a fresh player knocks: golden first, then door packs, then the existing chain; each pack once per Central day
const knocker = 'qa-knock@example.com'; const knockCookie = await signIn(knocker, 'qaknock');
const cbStart = callbacks.length;
async function knock(email) {
const n = crypto.randomBytes(12).toString('hex');
const o = (await api('/api/door/open?t=' + encodeURIComponent(mint({ kind: 'door', memberId: 88, email, nonce: n, ret: SD + '/play?door=' + n })))).j;
if (!o || o.mode !== 'visit') return { o };
await sleep(2200);
const c2 = (await api('/api/door/challenge?n=' + n)).j;
const d = (await api('/api/door/done', { n, answer: c2.options.indexOf(CAP[c2.prompt]) })).j;
const rc2 = d && d.ret ? verify(new URL(d.ret).searchParams.get('r')) : null;
const cbx = callbacks.map(x => JSON.parse(x.raw)).find(x => x.nonce === n) || null;
return { o, d, rc: rc2, cb: cbx };
}
const k1 = await knock(knocker);
ok(k1.o.golden === true && k1.o.bonus === 2 && k1.o.credits === 6 && k1.o.title === 'QA golden door', 'door 1: the Golden Door first (open: golden, bonus 2, credits 6)', JSON.stringify(k1.o && { title: k1.o.title, golden: k1.o.golden, bonus: k1.o.bonus, credits: k1.o.credits }));
ok(k1.cb && k1.cb.golden === true && k1.cb.bonus === 2 && k1.cb.credits === 6 && k1.cb.campaignId === T_GOLD && Object.keys(k1.cb).sort().join() === 'bonus,campaignId,credits,golden,host,memberId,nonce', 'Golden Door callback {.., credits: 6, golden: true, bonus: 2}', k1.cb && JSON.stringify(k1.cb));
ok(k1.rc && k1.rc.kind === 'door-receipt' && k1.rc.golden === true && k1.rc.bonus === 2 && k1.rc.credits === 6 && k1.rc.campaignId === T_GOLD, 'Golden Door receipt carries golden, bonus, credits 6', JSON.stringify(k1.rc && { golden: k1.rc.golden, bonus: k1.rc.bonus, credits: k1.rc.credits }));
ok(k1.d && k1.d.golden === true && k1.d.bonus === 2 && k1.d.credits === 6, 'done response says golden too');
const k2 = await knock(knocker), k3 = await knock(knocker);
ok(k2.cb && T_DOORS.includes(k2.cb.campaignId) && k2.cb.credits === 4 && !('golden' in k2.cb) && Object.keys(k2.cb).sort().join() === 'campaignId,credits,host,memberId,nonce' && k2.o.credits === 4 && !k2.o.golden, 'door 2: a door pack (credits 4, no golden fields)', JSON.stringify(k2.cb));
ok(k2.rc && k2.rc.credits === 4 && !('golden' in k2.rc), 'door pack receipt credits 4');
ok(k3.cb && T_DOORS.includes(k3.cb.campaignId) && k3.cb.campaignId !== k2.cb.campaignId && k3.cb.credits === 4, 'door 3: the other door pack, not the same one twice in a day', JSON.stringify(k3.cb));
const k4 = await knock(knocker);
ok(k4.cb && ![T_GOLD].concat(T_DOORS).includes(k4.cb.campaignId) && k4.cb.credits === 3 && !k4.o.golden, 'door 4: packs used today, so the existing chain (a visit pack, credits 3)', JSON.stringify(k4.cb));
await api('/api/admin/rates', { method: 'PATCH', data: { doorRepeatDays: 0 } }, adminH); // ordinary packs may repeat at once; door packs still wait for tomorrow
const k5 = await knock(knocker);
ok(!k5.cb || ![T_GOLD].concat(T_DOORS).includes(k5.cb.campaignId), 'with no repeat cooldown, golden and door packs still once per Central day', JSON.stringify(k5.cb || k5.o));
await api('/api/admin/rates', { method: 'PATCH', data: { doorRepeatDays: 7 } }, adminH);
// advertiser stats on the member's pack
const mine = (await api('/api/my/campaigns', null, { Cookie: playerCookie })).j;
const myPack = mine && mine.campaigns.find(c => c.id === (mpc && mpc.id)); const ds = mine && mine.doorStats && mine.doorStats[mpc && mpc.id];
ok(myPack && myPack.placement === 'doors' && myPack.doorOnly && ds && ds.doors === 1 && ds.players === 1 && myPack.imps === 1, 'campaign stats: doors opened 1, unique players 1', JSON.stringify({ ds, imps: myPack && myPack.imps }));
// in season door packs never reach the Earn tab or refuels: pause every ordinary pack, then a fresh member finds nothing there
const allCamps = (await api('/api/admin/campaigns', null, adminH)).j.campaigns.filter(c => c.type === 'visits' && c.status === 'active' && c.placement === 'all');
for (const c of allCamps) await api('/api/admin/campaigns/' + c.id + '/pause', {}, adminH);
const earner = 'qa-earner@example.com'; const earnCookie = await signIn(earner, 'qaearner');
const ev = (await api('/api/my/visits', null, { Cookie: earnCookie })).j;
ok(ev && ev.ad === null, 'in season: the Earn tab never serves a door pack or Golden Door', JSON.stringify(ev && ev.ad));
await api('/api/admin/rates', { method: 'PATCH', data: { refuelCapPerDay: 20 } }, adminH);
const nrf = crypto.randomBytes(12).toString('hex');
const rfx = (await api('/api/refuel/open?t=' + encodeURIComponent(mint({ kind: 'refuel', memberId: 89, email: earner, nonce: nrf, ret: SD + '/play?refuel=' + nrf }, DRSECRET)))).j;
ok(rfx && rfx.none && rfx.why === 'empty', 'in season: refuels never serve a door pack or Golden Door', JSON.stringify(rfx));
const pdl = (await api('/api/admin/campaigns', null, adminH)).j.campaigns.filter(c => c.doorOnly);
ok(pdl.length >= 3, 'door-only packs are flagged doorOnly (kept off the PassiveDrip listing)', String(pdl.length));
// from sdSeasonEnd they are ordinary visits: Earn and refuels serve them, doors no longer favour them, no golden fields
await api('/api/admin/rates', { method: 'PATCH', data: { sdSeasonEnd: today } }, adminH);
const ev2 = (await api('/api/my/visits', null, { Cookie: earnCookie })).j;
ok(ev2 && ev2.ad && ['QA golden door', 'QA door pack', 'QA member doors'].includes(ev2.ad.title), 'after sdSeasonEnd: the Earn tab serves door packs as normal visits', JSON.stringify(ev2 && ev2.ad && ev2.ad.title));
const nrf2 = crypto.randomBytes(12).toString('hex');
const rfy = (await api('/api/refuel/open?t=' + encodeURIComponent(mint({ kind: 'refuel', memberId: 89, email: earner, nonce: nrf2, ret: SD + '/play?refuel=' + nrf2 }, DRSECRET)))).j;
ok(rfy && rfy.mode === 'visit' && ['QA golden door', 'QA door pack', 'QA member doors'].includes(rfy.title), 'after sdSeasonEnd: refuels serve them too', JSON.stringify(rfy && { mode: rfy.mode, title: rfy.title, why: rfy.why }));
const k6 = await knock('qa-late@example.com');
ok(k6.o && k6.o.mode === 'visit' && !k6.o.golden && k6.cb && !('golden' in k6.cb) && [6, 4].includes(k6.cb.credits), 'after sdSeasonEnd: a door gets an ordinary door (no golden), credits still what the pack paid', JSON.stringify(k6.cb || k6.o));
const late = await api('/api/admin/campaigns', { type: 'visits', name: 'late', targetUrl: 'https://rmcircle.team/contract', title: 'late', count: 20, placement: 'golden' }, adminH);
ok(late.status === 400 && /season is over/.test(late.j && late.j.error || ''), 'after sdSeasonEnd: new door packs refused');
const gpNow = (await api('/api/admin/campaigns', null, adminH)).j.campaigns.find(c => c.id === T_GOLD);
ok(gpNow && gpNow.placement === 'golden' && gpNow.doorOnly === false, 'after sdSeasonEnd: placement kept, doorOnly false');
await api('/api/admin/rates', { method: 'PATCH', data: { sdSeasonEnd: '2026-11-01' } }, adminH);
} catch (e) { fails++; console.log('FAIL exception: ' + e.message + '\n' + (e.stack || '').split('\n').slice(1, 3).join('\n')); }
finally { cleanup(); }
console.log(fails ? '\n' + fails + ' failure(s)' : '\nall door checks passed');
process.exit(fails ? 1 : 0);