Pass tiers restructure (Dallas, Marty approved 2026-10-22): Explorer $19.99 (1999 credits) and Champion $39.99 (3999) for 30 days, new Sovereign $99.99 (9999, 30 days) and Legend $249.99 (24999, 365 days, the yearly pass). One table (gamepass.js TIER_DEFS: rank, names, settings stem, defaults, member-card perks); settings gamePassSovereign*/gamePassLegend* with kill switches; flag()/partner player/hand-off token carry sovereign/legend; buy, waiting orders ($100/$250 package copy), extend from max(now, until), comp/revoke, admin By pass tier table and comp options; chatbot tier fact says coming soon while sovTiers is off. All behind sovTiers (still 0): weekly Game Pass price, length and caps unchanged. Tests: sov-passes store + local extended (all pass), member QA 0 bugs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-22 10:26:58 -05:00
parent 32eefae473
commit 839c867595
11 changed files with 259 additions and 77 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
# bash qa/run.sh sponsorfollow # sponsor follow rule + network tank unit tests and the two-server e2e (local IAP + local LinkSpin, throwaway data)
# bash qa/run.sh door # Spooky Doors door + costume shop flows on their own local copy (qa/door.mjs boots it)
# bash qa/run.sh gamepass # Game Pass buy flow + account-wide POL caps (polgrant) on their own local copy (qa/gamepass.mjs boots it)
# bash qa/run.sh sov-passes # Explorer/Champion tiers: store unit checks + admin buys Explorer with seeded purchased credits on a local copy (screenshots D:/tmp/sov-passes)
# bash qa/run.sh sov-passes # pass tiers (Explorer/Champion/Sovereign/Legend): store unit checks + admin buys Explorer + Sovereign with seeded purchased credits on a local copy (screenshots D:/tmp/sov-passes)
# bash qa/run.sh gamepass-games # the REAL games' polgrant.js + PolHunter's tournament payer against a local copy (needs the sibling game repos)
# Each local run boots server.js on its own port with a throwaway data dir (JSON store, no DB, no
# mail key, devCode sign-in), so nothing touches production data. Reports land in qa/out/.
+41 -10
View File
@@ -6,6 +6,8 @@
// Explorer in the browser through the REAL ads.gamePurchase(purchasedOnly) charge; the 500 left is short for a second Explorer
// (waiting order, $20 package copy); the Shards of Valor hand-off token and GET /api/partner/player carry tier explorer;
// polgrant answers pass: true with the weekly pass caps; Admin > Game Pass shows the tier table. Exit 1 on any failure.
// 2026-10-22: + Sovereign / Legend: members refused while sovTiers is off, the admin preview lists all five, the admin buys Sovereign
// (real charge), a Legend waiting order is settled by a $250 package (a year), the token / partner player carry tier legend + tiers.
import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
@@ -21,7 +23,7 @@ const B = 'http://127.0.0.1:' + PORT;
const SHOTS = process.env.SHOTS || 'D:/tmp/sov-passes'; fs.mkdirSync(SHOTS, { recursive: true });
const SOV = crypto.randomBytes(24).toString('hex'); // throwaway, never printed
const ADMIN_PW = 'localtest', ADMIN_EMAIL = 'qa-admin@example.com', MEMBER = 'qa-sov-member@example.com';
const SEED_ID = 9001, SEED_CREDITS = 2500;
const SEED_ID = 9001, SEED_CREDITS = 1999 + 9999 + 500; // Explorer + Sovereign, then 500 left (short for a second Explorer)
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-sovpasses-')); fs.mkdirSync(path.join(DATA, 'uploads'));
let fails = 0; const ok = (c, label, extra) => { console.log((c ? 'PASS ' : 'FAIL ') + label + (extra ? ' ' + extra : '')); if (!c) fails++; };
const hide = page => page.evaluate(() => { document.querySelectorAll('.lgate,.iap-welcome,#onboardModal').forEach(m => m.hidden = true); });
@@ -70,7 +72,8 @@ try {
ok(up && /qa stub: position #9001/.test(srvLog), 'local copy up with the seeded position', '');
await api('/api/admin/site', { method: 'PATCH', data: { fraudMaxSignupsPerIpDay: 10, gamePassEnabled: '1' } }, adminH);
const site = (await api('/api/admin/site', null, adminH)).j; const sc = (site && (site.site || site)) || {};
ok(sc.sovTiers === '0' && Number(sc.gamePassExplorerPriceCredits) === 2000 && Number(sc.gamePassChampionPriceCredits) === 4000 && Number(sc.gamePassExplorerDays) === 30 && sc.passTournamentTierSales === '0', 'defaults: sovTiers 0, Explorer 2000 / Champion 4000 credits, 30 days, passTournamentTierSales 0', JSON.stringify({ sovTiers: sc.sovTiers, e: sc.gamePassExplorerPriceCredits, c: sc.gamePassChampionPriceCredits }));
ok(sc.sovTiers === '0' && Number(sc.gamePassExplorerPriceCredits) === 1999 && Number(sc.gamePassChampionPriceCredits) === 3999 && Number(sc.gamePassExplorerDays) === 30 && sc.passTournamentTierSales === '0', 'defaults: sovTiers 0, Explorer 1999 / Champion 3999 credits, 30 days, passTournamentTierSales 0', JSON.stringify({ sovTiers: sc.sovTiers, e: sc.gamePassExplorerPriceCredits, c: sc.gamePassChampionPriceCredits }));
ok(Number(sc.gamePassSovereignPriceCredits) === 9999 && Number(sc.gamePassSovereignDays) === 30 && sc.gamePassSovereignEnabled === '1' && Number(sc.gamePassLegendPriceCredits) === 24999 && Number(sc.gamePassLegendDays) === 365 && sc.gamePassLegendEnabled === '1' && Number(sc.gamePassPriceCredits) === 500 && Number(sc.gamePassDays) === 7, 'defaults: Sovereign 9999 / 30 days, Legend 24999 / 365 days (kill switches 1), weekly 500 / 7 unchanged', JSON.stringify({ s: [sc.gamePassSovereignPriceCredits, sc.gamePassSovereignDays], l: [sc.gamePassLegendPriceCredits, sc.gamePassLegendDays] }));
const hA = await signIn(ADMIN_EMAIL, 'qaadmin'), hM = await signIn(MEMBER, 'qasovm');
// 1. a member with sovTiers off: weekly only, Explorer refused
@@ -78,20 +81,24 @@ try {
ok(g.passes && g.passes.length === 1 && g.passes[0].tier === 'weekly' && !g.tierPreview, 'member, sovTiers off: only the weekly pass is offered', JSON.stringify((g.passes || []).map(x => x.tier)));
let r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hM);
ok(r.status === 400 && r.j.error === 'The Explorer pass is not open yet.', 'member, sovTiers off: Explorer buy refused', JSON.stringify(r.j));
for (const [tier, name] of [['sovereign', 'Sovereign'], ['legend', 'Legend']]) { r = await api('/api/my/gamepass/buy', { data: { tier } }, hM);
ok(r.status === 400 && r.j.error === 'The ' + name + ' pass is not open yet.', 'member, sovTiers off: ' + name + ' buy refused', JSON.stringify(r.j)); }
g = (await api('/api/my/gamepass', null, hM)).j; ok(!g.active && !g.waiting && g.passes.length === 1, 'the refused buys left the member with no pass and no waiting order', JSON.stringify({ a: g.active, w: g.waiting }));
browser = await chromium.launch();
{ const { page, errs, ctx } = await pageFor(hM); await page.goto(B + '/my#passes'); await page.waitForSelector('#gpCard:not([hidden]) #gpBuy', { timeout: 15000 });
const txt = await page.textContent('#gpCard'); ok(!/Explorer|Champion/.test(txt) && errs.length === 0, 'member page: the weekly card as before, no Explorer/Champion text, no page errors', errs.join(' | '));
const txt = await page.textContent('#gpCard'); ok(!/Explorer|Champion|Sovereign|Legend/.test(txt) && errs.length === 0, 'member page: the weekly card as before, no Explorer/Champion/Sovereign/Legend text, no page errors', errs.join(' | '));
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '1-member-weekly-only.png') }); await ctx.close(); }
// 2. the admin: preview of all three, buys Explorer in the browser with the seeded purchased credits (the real charge)
g = (await api('/api/my/gamepass', null, hA)).j;
ok(g.tierPreview === true && g.passes.map(x => x.tier).join() === 'weekly,explorer,champion', 'admin, sovTiers off: preview with all three tiers', JSON.stringify(g.passes.map(x => [x.tier, x.price, x.open])));
ok(g.tierPreview === true && g.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign,legend' && g.passes.map(x => x.price).join() === '500,1999,3999,9999,24999', 'admin, sovTiers off: preview with all five tiers, 500 / 1999 / 3999 / 9999 / 24999', JSON.stringify(g.passes.map(x => [x.tier, x.price, x.open])));
{ const { page, errs, ctx } = await pageFor(hA); await page.goto(B + '/my?from=shardsofvalor#passes');
await page.waitForSelector('#gpCard [data-gp-tier="explorer"]', { timeout: 15000 }); await sleep(600); await hide(page);
const txt = await page.textContent('#gpCard');
ok(/never make you stronger than players who earn their gear/.test(txt) && /main story of Shards of Valor is free/.test(txt) && /Admin preview/.test(txt) && !/\u2014/.test(txt), 'tier card copy: never stronger, main story free, admin preview note, no em dashes', '');
ok(/#games/.test(page.url()), 'the Shards of Valor link (#passes) lands on the pass card, not the Buy pane', page.url());
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '2-admin-preview-three-tiers.png') });
ok(/Sovereign/.test(txt) && /Necromancer/.test(txt) && /Legend/.test(txt) && /\$249\.99/.test(txt) && /for 1 year/.test(txt) && /Archer/.test(txt) && /Druid/.test(txt) && /level cap 30/.test(txt) && /\$19\.99/.test(txt), 'admin preview card lists Sovereign and Legend ($249.99 for 1 year) with what each includes', '');
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '2-admin-preview-all-tiers.png') });
await page.click('#gpCard [data-gp-tier="explorer"]'); await page.waitForSelector('#dlgOk', { timeout: 5000 });
await page.screenshot({ path: path.join(SHOTS, '3-admin-confirm-explorer.png') });
await page.click('#dlgOk');
@@ -102,9 +109,7 @@ try {
g = (await api('/api/my/gamepass', null, hA)).j;
const ex = g.passes.find(x => x.tier === 'explorer');
ok(g.active && g.tier === 'explorer' && ex.active && Math.abs(ex.until - (Date.now() + 30 * 86400000)) < 120000, 'GET /api/my/gamepass: tier explorer, 30 days', JSON.stringify({ tier: g.tier, until: ex && new Date(ex.until).toISOString() }));
ok(/gamepass bought with credits explorer qa-admin@example.com 2000/.test(srvLog), 'paid through the real ads.gamePurchase(purchasedOnly) path, 2000 credits', '');
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'explorer' && r.j.available === 500 && /\$20 package/.test(r.j.message), 'a second Explorer: only 500 purchased credits left -> waiting order, "$20 package"', JSON.stringify({ needPay: r.j.needPay, available: r.j.available, payUrl: r.j.payUrl }));
ok(/gamepass bought with credits explorer qa-admin@example.com 1999/.test(srvLog), 'paid through the real ads.gamePurchase(purchasedOnly) path, 1999 credits', '');
// 3. the Shards of Valor hand-off token and the partner player answer carry tier explorer
const ho = await api('/api/my/shardsofvalor', null, hA);
@@ -119,15 +124,41 @@ try {
const gr = await grant({ memberId: 0, email: ADMIN_EMAIL, game: 'shardsofvalor', kind: 'daily', pol: 0.2, ref: 'qa:1' });
ok(gr.pass === true && gr.allowed === 0.2, 'polgrant: pass true (a boolean) for the Explorer holder', JSON.stringify(gr));
// 3b. Sovereign (9999 credits, 30 days) and the yearly Legend (24999, 365 days), 2026-10-22: the admin buys Sovereign through the
// real charge, then is short for Legend (waiting order, $250 package) and for a second Explorer; a $250 package settles Legend.
r = await api('/api/my/gamepass/buy', { data: { tier: 'sovereign' } }, hA);
ok(r.status === 200 && r.j.ok && r.j.tier === 'sovereign' && r.j.days === 30 && Math.abs(r.j.until - (Date.now() + 30 * 86400000)) < 120000, 'admin buys Sovereign (sovTiers off, testing): 30 days', JSON.stringify(r.j));
ok(/gamepass bought with credits sovereign qa-admin@example.com 9999/.test(srvLog), 'Sovereign paid through the real ads.gamePurchase(purchasedOnly) path, 9999 credits', '');
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'explorer' && r.j.available === 500 && /\$20 package/.test(r.j.message), 'a second Explorer: only 500 purchased credits left -> waiting order, "$20 package"', JSON.stringify({ needPay: r.j.needPay, available: r.j.available, payUrl: r.j.payUrl }));
r = await api('/api/my/gamepass/buy', { data: { tier: 'legend' } }, hA);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'legend' && r.j.available === 500 && r.j.price === 24999 && r.j.payUrl === '/my?from=gamepass&tier=legend#buy' && /\$250 package/.test(r.j.message), 'Legend with 500 credits: waiting order, "$250 package", payUrl with tier', JSON.stringify({ needPay: r.j.needPay, payUrl: r.j.payUrl, msg: r.j.message }));
let dv = (await api('/api/dev/gamepass-purchase', { data: { cents: 10000, email: ADMIN_EMAIL } })).j;
ok(dv && dv.order && dv.order.tier === 'explorer' && dv.order.until === ex.until + 30 * 86400000, 'a $100 package fulfils the waiting Explorer (extends it from its end), never Legend', JSON.stringify(dv));
g = (await api('/api/my/gamepass', null, hA)).j;
ok(!g.passes.find(x => x.tier === 'legend').active && g.passes.find(x => x.tier === 'legend').waiting, 'Legend still waiting after a $100 package', JSON.stringify(g.passes.find(x => x.tier === 'legend')));
dv = (await api('/api/dev/gamepass-purchase', { data: { cents: 25000, email: ADMIN_EMAIL } })).j;
ok(dv && dv.order && dv.order.tier === 'legend' && Math.abs(dv.order.until - (Date.now() + 365 * 86400000)) < 120000, 'a $250 package fulfils the Legend order: a year', JSON.stringify(dv));
g = (await api('/api/my/gamepass', null, hA)).j;
const lg = g.passes.find(x => x.tier === 'legend'), sv = g.passes.find(x => x.tier === 'sovereign');
ok(g.active && g.tier === 'legend' && g.until === lg.until && lg.active && sv.active && lg.days === 365, 'GET /api/my/gamepass: tier legend (highest), Sovereign and Explorer still running underneath', JSON.stringify({ tier: g.tier, l: lg.until, s: sv.until }));
const ho2 = await api('/api/my/shardsofvalor', null, hA); const t2 = new URL(ho2.headers.get('location') || 'http://x/').searchParams.get('t'); const c2 = t2 ? decode(t2) : null;
ok(c2 && c2.gamePass && c2.gamePass.active === true && c2.gamePass.tier === 'legend' && c2.gamePass.until === lg.until, 'hand-off token: gamePass { active, until, tier: legend }', JSON.stringify(c2 && c2.gamePass));
const pl2 = await playerOf(ADMIN_EMAIL);
ok(pl2.status === 200 && pl2.j.pass.tier === 'legend' && pl2.j.pass.tiers.legend === lg.until && pl2.j.pass.tiers.sovereign === sv.until && pl2.j.pass.tiers.explorer === ex.until + 30 * 86400000 && pl2.j.pass.tiers.champion === null && pl2.j.caps.daily === 1.5 && pl2.j.caps.total === 5, 'GET /api/partner/player: tier legend, tiers carry sovereign + legend, weekly pass caps 1.50 / 5', JSON.stringify(pl2.j.pass));
const gr2 = await grant({ memberId: 0, email: ADMIN_EMAIL, game: 'shardsofvalor', kind: 'daily', pol: 5, ref: 'qa:2' });
ok(gr2.pass === true && gr2.enforced === false && gr2.allowed === 5, 'polgrant: pass true (a boolean) for the Legend holder (caps not enforced on this copy: no capsStartDate; the cap values are the player answer above)', JSON.stringify(gr2));
// 4. Admin > Game Pass: the tier table
const st = (await api('/api/admin/gamepass/stats', null, adminH)).j;
ok(st.tiers && st.tiers.explorer.active === 1 && st.tiers.explorer.soldTotal === 1 && st.tiers.explorer.usdTotal === 20 && st.tiers.explorer.waitingOrders === 1 && st.tierSales === false, 'admin stats: Explorer 1 active, 1 sold ($20), 1 waiting; sale switch off', JSON.stringify(st.tiers.explorer));
ok(st.tiers && st.tiers.explorer.active === 0 && st.tiers.explorer.soldTotal === 2 && st.tiers.explorer.usdTotal === 39.98 && st.tiers.explorer.waitingOrders === 0 && st.tierSales === false, 'admin stats: Explorer 2 sold ($39.98: credits + the $100 package order), not counted active (the account is at Legend); sale switch off', JSON.stringify(st.tiers.explorer));
ok(st.tiers.sovereign && st.tiers.sovereign.active === 0 && st.tiers.sovereign.soldTotal === 1 && st.tiers.sovereign.usdTotal === 99.99 && st.tiers.legend.active === 1 && st.tiers.legend.soldTotal === 1 && st.tiers.legend.usdTotal === 249.99 && st.tiers.legend.waitingOrders === 0 && st.settings.tiers.legend.days === 365 && st.settings.tiers.sovereign.sale === false, 'admin stats: Sovereign 1 sold ($99.99), Legend 1 active + 1 sold ($249.99), not on sale', JSON.stringify({ s: st.tiers.sovereign, l: st.tiers.legend }));
{ const ctx = await browser.newContext({ viewport: { width: 1280, height: 1000 } }); const page = await ctx.newPage(); const errs = []; page.on('pageerror', e => errs.push(String(e)));
await page.goto(B + '/admin', { waitUntil: 'networkidle' });
await page.fill('#adEmail', ADMIN_EMAIL); await page.click('#adSend'); await page.waitForSelector('#adVerify:not([hidden])'); await page.click('#adVerify'); await sleep(1200);
const nav = await page.$('.bo-menu [data-pane="gamepass"]'); if (nav) { await nav.click(); await page.waitForFunction(() => /Explorer/.test((document.getElementById('gpTiers') || {}).textContent || ''), null, { timeout: 10000 }).catch(() => {}); }
const txt = await page.textContent('#gpTiers').catch(() => '');
ok(/Explorer/.test(txt) && /Champion/.test(txt), 'Admin > Game Pass renders the per-tier table', errs.join(' | ') || (nav ? '' : 'admin nav not found (sign-in flow)'));
ok(/Explorer/.test(txt) && /Champion/.test(txt) && /Sovereign/.test(txt) && /Legend/.test(txt) && /365 d/.test(txt), 'Admin > Game Pass renders the per-tier table (all five, Legend 365 d)', errs.join(' | ') || (nav ? '' : 'admin nav not found (sign-in flow)'));
await sleep(800); await page.locator('#gpTiers').evaluate(e => e.closest('.card').scrollIntoView()); await sleep(400); await page.locator('#gpTiers').evaluate(e => e.closest('.card').id = 'gpTiersCard'); await page.locator('#gpTiersCard').screenshot({ path: path.join(SHOTS, '5-admin-gamepass-tiers.png') }); await ctx.close(); }
} catch (e) {
console.error('FAIL harness error', e && e.stack || e); fails++;
+101 -6
View File
@@ -4,6 +4,8 @@
// extend from max(now, until), side-by-side expiry, highest active tier wins, the sovTiers switch (off refuses, admin may buy),
// waiting orders per tier fulfilled by a big-enough package (each tx once, highest price first), the same caps for every tier
// (no extra POL), comp and revoke, admin stats per tier (each account once at its top tier, Central week/month). Exit 1 on failure.
// 2026-10-22: section 10 adds Sovereign (9999 / 30 days) and the yearly Legend (24999 / 365 days): rank, off-switch refusal,
// buy, short -> waiting order ($100 / $250 package), extend from max(now, until), kill switches, comp/revoke, flag payload, stats.
'use strict';
const fs = require('fs'); const os = require('os'); const path = require('path');
const gp = require('../gamepass');
@@ -40,7 +42,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
let v = gp.view('a@x.com', T0);
ok(v.passes.length === 1 && v.passes[0].tier === 'weekly' && v.show === true && v.tierPreview === false, 'sovTiers off: a member sees only the weekly pass', JSON.stringify(v.passes.map(x => x.tier)));
v = gp.view('admin@x.com', T0, { admin: true });
ok(v.passes.map(x => x.tier).join() === 'weekly,explorer,champion' && v.tierPreview === true && v.passes[1].open === true && v.passes[1].price === 2000 && v.passes[2].price === 4000 && v.passes[1].days === 30, 'sovTiers off: the admin sees all three (preview), prices 2000 / 4000, 30 days', JSON.stringify(v.passes));
ok(v.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign,legend' && v.tierPreview === true && v.passes.slice(1).every(x => x.open === true) && v.passes.map(x => x.price).join() === '500,1999,3999,9999,24999' && v.passes.map(x => x.days).join() === '7,30,30,30,365' && v.passes.map(x => x.package).join() === '5,20,50,100,250', 'sovTiers off: the admin sees all five (preview), prices 500 / 1999 / 3999 / 9999 / 24999, days 7 / 30 / 30 / 30 / 365, packages $5 / $20 / $50 / $100 / $250', JSON.stringify(v.passes));
r = await gp.buy('admin@x.com', paid, T0, 'explorer', { admin: true });
ok(r.ok && r.tier === 'explorer' && r.until === T0 + 30 * DAY && r.days === 30, 'sovTiers off: the admin can buy Explorer (testing)', JSON.stringify(r));
r = await gp.buy('a@x.com', paid, T0); // tier missing = weekly
@@ -54,15 +56,15 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
// 3. on: each tier extends only itself; buying again extends from max(now, until)
charged = null; r = await gp.buy('b@x.com', async (price, label) => { charged = { price, label }; return { ok: true }; }, T0, 'explorer');
ok(r.ok && r.until === T0 + 30 * DAY && charged.price === 2000 && charged.label === 'Explorer pass (30 days)', 'sovTiers on: Explorer charges 2000 credits, 30 days', JSON.stringify(charged));
ok(r.ok && r.until === T0 + 30 * DAY && charged.price === 1999 && charged.label === 'Explorer pass (30 days)', 'sovTiers on: Explorer charges 1999 credits, 30 days', JSON.stringify(charged));
let rec = passes.get('b@x.com');
ok(rec.tiers.explorer.until === T0 + 30 * DAY && !rec.tiers.weekly && !rec.tiers.champion && rec.until === 0 && rec.bought[0].tier === 'explorer' && rec.bought[0].usd === 20, 'only the Explorer tier moved; legacy until (weekly) stays 0; bought row has tier + $20', JSON.stringify(rec));
ok(rec.tiers.explorer.until === T0 + 30 * DAY && !rec.tiers.weekly && !rec.tiers.champion && rec.until === 0 && rec.bought[0].tier === 'explorer' && rec.bought[0].usd === 19.99, 'only the Explorer tier moved; legacy until (weekly) stays 0; bought row has tier + $19.99', JSON.stringify(rec));
r = await gp.buy('b@x.com', paid, T0 + 10 * DAY, 'explorer');
ok(r.until === T0 + 60 * DAY, 'Explorer again while active: extends from its until (+30 days, nothing lost)', new Date(r.until).toISOString());
r = await gp.buy('c@x.com', paid, T0, 'champion'); ok(r.ok && r.until === T0 + 30 * DAY, 'Champion: 30 days', '');
r = await gp.buy('c@x.com', paid, T0 + 45 * DAY, 'champion');
ok(r.until === T0 + 75 * DAY, 'Champion again after it ended: extends from now', new Date(r.until).toISOString());
charged = null; await gp.buy('c2@x.com', async (price) => { charged = price; return { ok: true }; }, T0, 'champion'); ok(charged === 4000, 'Champion charges 4000 credits', String(charged));
charged = null; await gp.buy('c2@x.com', async (price) => { charged = price; return { ok: true }; }, T0, 'champion'); ok(charged === 3999, 'Champion charges 3999 credits', String(charged));
// 4. side by side: Champion over Explorer, then Explorer shows through; weekly underneath
await gp.buy('d@x.com', paid, T0, 'weekly'); // weekly to T0+7
@@ -133,7 +135,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
await gp.buy('s5@x.com', short, NOW, 'champion');
const st = gp.adminStats(NOW); const S = st.tiers;
ok(S.weekly.active === 1 && S.explorer.active === 2 && S.champion.active === 1, 'active counts each account once at its top tier (s1 = explorer, not weekly)', JSON.stringify({ w: S.weekly.active, e: S.explorer.active, c: S.champion.active }));
ok(S.weekly.soldWeek === 2 && S.explorer.soldWeek === 0 && S.explorer.soldMonth === 1 && S.champion.soldWeek === 1 && S.champion.soldMonth === 1 && S.champion.soldTotal === 2 && S.champion.usdTotal === 80, 'Central week (from Mon 00:00) and month (from the 1st 00:00) boundaries', JSON.stringify({ w: [S.weekly.soldWeek, S.weekly.soldMonth], e: [S.explorer.soldWeek, S.explorer.soldMonth], c: [S.champion.soldWeek, S.champion.soldMonth, S.champion.soldTotal, S.champion.usdTotal] }));
ok(S.weekly.soldWeek === 2 && S.explorer.soldWeek === 0 && S.explorer.soldMonth === 1 && S.champion.soldWeek === 1 && S.champion.soldMonth === 1 && S.champion.soldTotal === 2 && S.champion.usdTotal === 79.98, 'Central week (from Mon 00:00) and month (from the 1st 00:00) boundaries', JSON.stringify({ w: [S.weekly.soldWeek, S.weekly.soldMonth], e: [S.explorer.soldWeek, S.explorer.soldMonth], c: [S.champion.soldWeek, S.champion.soldMonth, S.champion.soldTotal, S.champion.usdTotal] }));
ok(S.champion.renewals30d === 1 && S.weekly.renewals30d === 0, 'renewals30d: a second Champion purchase by a Champion holder', String(S.champion.renewals30d));
ok(S.weekly.expiring7d === 2 && S.explorer.comped === 1 && S.champion.waitingOrders === 1, 'expiring7d (weekly passes ending in 7 Central days), comped, waiting orders per tier', JSON.stringify({ exp: S.weekly.expiring7d, comped: S.explorer.comped, wait: S.champion.waitingOrders }));
ok(st.passes.active === 4 && st.passes.soldTotal === 5 && st.passes.comped === 1 && st.passes.waitingOrders === 1, 'the existing all-tier passes block still adds up', JSON.stringify(st.passes));
@@ -143,7 +145,100 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
ok(rows.sales === 2 && rows.salesUsd === 10, 'passTournamentTierSales off: only the 2 weekly sales ($10) feed the pool', JSON.stringify({ sales: rows.sales, usd: rows.salesUsd }));
SC.passTournamentTierSales = '1';
const rows2 = await gp.runTournament(Date.parse('2026-11-03T18:00:00Z'), { force: true });
ok(rows2.sales === 3 && rows2.salesUsd === 50, 'passTournamentTierSales on: the Champion renewal ($40) is added', JSON.stringify({ sales: rows2.sales, usd: rows2.salesUsd }));
ok(rows2.sales === 3 && rows2.salesUsd === 49.99, 'passTournamentTierSales on: the Champion renewal ($39.99) is added', JSON.stringify({ sales: rows2.sales, usd: rows2.salesUsd }));
// 10. Sovereign ($99.99 / 30 days) and Legend ($249.99 / 365 days), 2026-10-22 (Dallas's structure)
for (const k of [...passes.keys()]) passes.delete(k); for (const k of [...orders.keys()]) orders.delete(k);
delete SC.passTournamentTierSales; SC.sovTiers = '0';
ok(gp.TIERS.join() === 'weekly,explorer,champion,sovereign,legend' && gp.TIER_NAMES.sovereign === 'Sovereign' && gp.TIER_NAMES.legend === 'Legend', 'rank: weekly < explorer < champion < sovereign < legend; names from the one table', gp.TIERS.join());
const C0 = gp.cfg().tiers;
ok(C0.weekly.price === 500 && C0.weekly.days === 7 && C0.explorer.price === 1999 && C0.champion.price === 3999 && C0.sovereign.price === 9999 && C0.sovereign.days === 30 && C0.legend.price === 24999 && C0.legend.days === 365 && !C0.sovereign.sale && !C0.legend.sale && C0.weekly.sale, 'defaults: weekly 500/7 (unchanged), Sovereign 9999/30, Legend 24999/365; sovTiers off = not on sale, weekly on sale', JSON.stringify(C0));
// off switch: members refused, nothing written, nothing charged; the weekly pass still sells
charged = null; const spy = async (price, label) => { charged = { price, label }; return { ok: true }; };
r = await gp.buy('m@x.com', spy, T0, 'sovereign'); ok(r.error === 'The Sovereign pass is not open yet.' && !charged, 'sovTiers off: Sovereign refused for a member, nothing charged', JSON.stringify(r));
r = await gp.buy('m@x.com', spy, T0, 'legend'); ok(r.error === 'The Legend pass is not open yet.' && !charged, 'sovTiers off: Legend refused for a member, nothing charged', JSON.stringify(r));
r = await gp.buy('m@x.com', short, T0, 'legend'); ok(r.error && !orders.size, 'sovTiers off: a short member gets no waiting Legend order either', JSON.stringify(r));
ok(!passes.get('m@x.com'), 'refused Sovereign/Legend buys write nothing', '');
v = gp.view('m@x.com', T0); ok(v.passes.map(x => x.tier).join() === 'weekly' && !v.tierPreview, 'sovTiers off: the member still sees only the weekly pass', JSON.stringify(v.passes.map(x => x.tier)));
charged = null; r = await gp.buy('m@x.com', spy, T0); ok(r.ok && r.tier === 'weekly' && charged.price === 500 && charged.label === 'Game Pass (7 days)' && r.until === T0 + 7 * DAY, 'sovTiers off: the weekly Game Pass sells exactly as before', JSON.stringify(charged));
charged = null; r = await gp.buy('adm@x.com', spy, T0, 'legend', { admin: true });
ok(r.ok && r.tier === 'legend' && r.days === 365 && r.until === T0 + 365 * DAY && charged.price === 24999 && charged.label === 'Legend pass (365 days)', 'sovTiers off: the admin can buy Legend (testing): 24999 credits, 365 days', JSON.stringify({ r, charged }));
SC.sovTiers = '1';
// buy with enough purchased credits
charged = null; r = await gp.buy('sv@x.com', spy, T0, 'sovereign');
ok(r.ok && r.tier === 'sovereign' && r.days === 30 && r.until === T0 + 30 * DAY && charged.price === 9999 && charged.label === 'Sovereign pass (30 days)', 'sovTiers on: Sovereign charges 9999 credits, 30 days', JSON.stringify(charged));
rec = passes.get('sv@x.com');
ok(rec.tiers.sovereign.until === T0 + 30 * DAY && !rec.tiers.weekly && !rec.tiers.legend && rec.until === 0 && rec.bought[0].tier === 'sovereign' && rec.bought[0].usd === 99.99 && rec.bought[0].credits === 9999, 'only the Sovereign tier moved; bought row has tier, $99.99, 9999 credits', JSON.stringify(rec));
charged = null; r = await gp.buy('lg@x.com', spy, T0, 'legend');
ok(r.ok && r.until === T0 + 365 * DAY && charged.price === 24999 && passes.get('lg@x.com').bought[0].usd === 249.99, 'sovTiers on: Legend charges 24999 credits, a YEAR (365 days), $249.99 row', JSON.stringify(charged));
// extend: from max(now, until)
r = await gp.buy('lg@x.com', paid, T0 + 100 * DAY, 'legend'); ok(r.until === T0 + 730 * DAY, 'Legend again while active: +365 days from its end (nothing lost)', new Date(r.until).toISOString());
r = await gp.buy('sv@x.com', paid, T0 + 10 * DAY, 'sovereign'); ok(r.until === T0 + 60 * DAY, 'Sovereign again while active: +30 days from its end', new Date(r.until).toISOString());
r = await gp.buy('sv@x.com', paid, T0 + 90 * DAY, 'sovereign'); ok(r.until === T0 + 120 * DAY, 'Sovereign again after it ended: +30 days from now', new Date(r.until).toISOString());
r = await gp.buy('lg2@x.com', paid, T0, 'legend'); r = await gp.buy('lg2@x.com', paid, T0 + 400 * DAY, 'legend'); ok(r.until === T0 + 765 * DAY, 'Legend again after it ended: +365 days from now', new Date(r.until).toISOString());
// ordering: all five side by side
await gp.buy('all@x.com', paid, T0, 'weekly'); await gp.buy('all@x.com', paid, T0, 'explorer'); await gp.buy('all@x.com', paid, T0, 'champion');
await gp.buy('all@x.com', paid, T0, 'sovereign'); await gp.buy('all@x.com', paid, T0 - 360 * DAY, 'legend'); // legend to T0+5
f = gp.flag('all@x.com', T0 + DAY);
ok(f.active && f.tier === 'legend' && f.until === T0 + 5 * DAY && f.tiers.sovereign === T0 + 30 * DAY && f.tiers.legend === T0 + 5 * DAY && f.tiers.champion === T0 + 30 * DAY && f.tiers.weekly === T0 + 7 * DAY && Object.keys(f.tiers).join() === 'weekly,explorer,champion,sovereign,legend', 'all five on: tier legend, until = Legend end, every tier side by side in the payload', JSON.stringify(f));
f = gp.flag('all@x.com', T0 + 6 * DAY); ok(f.tier === 'sovereign' && f.until === T0 + 30 * DAY && f.tiers.legend === null, 'Legend ended: Sovereign shows through (above Champion and Explorer, same end)', JSON.stringify(f));
await gp.buy('ce@x.com', paid, T0, 'champion'); await gp.buy('ce@x.com', paid, T0, 'sovereign'); await gp.buy('ce@x.com', paid, T0, 'explorer');
ok(gp.flag('ce@x.com', T0 + 1).tier === 'sovereign', 'Sovereign outranks Champion and Explorer whatever the buy order', gp.flag('ce@x.com', T0 + 1).tier);
// the same caps (no extra POL) and pass: true
const at2 = Date.parse('2026-10-22T17:00:00Z');
ok([gp.capsFor('sv@x.com', at2), gp.capsFor('lg@x.com', at2)].every(c => c.pass === true && c.daily === 1.5 && c.total === 5), 'capsFor: Sovereign and Legend holders get exactly the weekly pass caps 1.50 / 5', '');
const gs = gp.grant({ email: 'lg@x.com', game: 'shardsofvalor', kind: 'daily', pol: 3, ref: 'cap:lg', now: at2 });
ok(gs.allowed === 1.5 && gs.pass === true, 'polgrant: a Legend holder is capped at 1.50 on daily play, pass: true (a boolean)', JSON.stringify(gs));
// waiting orders: a $50 package does not cover Sovereign, $100 does; $100 does not cover Legend, $250 does
r = await gp.buy('wo@x.com', short, T0, 'sovereign');
ok(r.needPay && r.tier === 'sovereign' && r.payUrl === '/my?from=gamepass&tier=sovereign#buy' && r.package === 100 && /\$100 package/.test(r.message) && r.price === 9999, 'Sovereign short: waiting order, payUrl with tier, "$100 package"', r.message);
const ordS = r.order;
r = await gp.buy('wo@x.com', short, T0, 'legend'); const ordL = r.order;
ok(r.needPay && r.order !== ordS && r.package === 250 && /\$250 package/.test(r.message) && r.payUrl === '/my?from=gamepass&tier=legend#buy', 'Legend short: its own waiting order, "$250 package"', r.message);
r = await gp.buy('wo@x.com', short, T0, 'legend'); ok(r.order === ordL, 'Legend again: reuses its waiting order', '');
ev = await gp.onEvent({ type: 'Purchase', priceCents: 5000, tx: '0xd1', ts: T0, devEmail: 'wo@x.com' }); ok(ev === null, 'a $50 package fulfils neither Sovereign nor Legend', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 10000, tx: '0xd2', ts: T0, devEmail: 'wo@x.com' });
ok(ev && ev.tier === 'sovereign' && ev.order === ordS && ev.until === T0 + 30 * DAY, 'a $100 package fulfils the Sovereign order (not Legend)', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 10000, tx: '0xd2', ts: T0, devEmail: 'wo@x.com' }); ok(ev === null, 'the same tx again counts once', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 25000, tx: '0xd3', ts: T0, devEmail: 'wo@x.com' });
ok(ev && ev.tier === 'legend' && ev.order === ordL && ev.until === T0 + 365 * DAY, 'a $250 package fulfils the Legend order: a year', JSON.stringify(ev));
await gp.buy('wo2@x.com', short, T0, 'champion'); await gp.buy('wo2@x.com', short, T0, 'sovereign'); await gp.buy('wo2@x.com', short, T0, 'legend');
ev = await gp.onEvent({ type: 'Purchase', priceCents: 50000, tx: '0xd4', ts: T0, devEmail: 'wo2@x.com' }); ok(ev && ev.tier === 'legend', 'three orders waiting, a $500 package: Legend (the highest-priced it covers) first', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 10000, tx: '0xd5', ts: T0, devEmail: 'wo2@x.com' }); ok(ev && ev.tier === 'sovereign', 'then a $100 package: Sovereign', JSON.stringify(ev));
// kill switches: one tier stops alone, the rest keep selling
SC.gamePassLegendEnabled = '0';
r = await gp.buy('ks@x.com', paid, T0, 'legend'); const r2 = await gp.buy('ks@x.com', paid, T0, 'sovereign');
ok(r.error === 'The Legend pass is not open yet.' && r2.ok, 'gamePassLegendEnabled 0: Legend refused, Sovereign still sells', JSON.stringify(r));
v = gp.view('ks2@x.com', T0); ok(v.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign', 'a stopped tier drops off the member card', v.passes.map(x => x.tier).join());
v = gp.view('lg@x.com', T0); const lrow = v.passes.find(x => x.tier === 'legend');
ok(lrow && lrow.active && !lrow.open, 'a Legend holder still sees their pass (not on sale) after the switch stops it', JSON.stringify(lrow));
delete SC.gamePassLegendEnabled; SC.gamePassSovereignEnabled = '0';
r = await gp.buy('ks@x.com', paid, T0, 'sovereign'); ok(r.error === 'The Sovereign pass is not open yet.', 'gamePassSovereignEnabled 0: Sovereign refused', JSON.stringify(r));
delete SC.gamePassSovereignEnabled;
SC.gamePassLegendPriceCredits = '20000'; SC.gamePassLegendDays = '180';
charged = null; r = await gp.buy('pr@x.com', spy, T0, 'legend'); ok(charged.price === 20000 && r.until === T0 + 180 * DAY, 'gamePassLegendPriceCredits / gamePassLegendDays settings override the defaults', JSON.stringify(charged));
delete SC.gamePassLegendPriceCredits; delete SC.gamePassLegendDays;
// comp and revoke
cp = gp.comp('cv@x.com', 'qa', 'legend', T0); f = gp.flag('cv@x.com', T0 + 1);
ok(cp.tier === 'legend' && cp.days === 365 && cp.until === T0 + 365 * DAY && f.tier === 'legend' && passes.get('cv@x.com').bought[0].via === 'admin' && passes.get('cv@x.com').bought[0].usd === 0, 'comp Legend: a year, an admin row worth $0', JSON.stringify(cp));
gp.comp('cv@x.com', 'qa', 'sovereign', T0);
rv = gp.revoke('cv@x.com', 'legend', 'refund qa', T0 + DAY); f = gp.flag('cv@x.com', T0 + DAY + 1);
ok(rv.ok && rv.tier === 'legend' && f.tier === 'sovereign' && f.tiers.legend === null, 'revoke Legend: ends now, Sovereign shows through', JSON.stringify(f));
rv = gp.revoke('cv@x.com', 'sovereign', 'refund qa', T0 + DAY); ok(rv.ok && gp.flag('cv@x.com', T0 + DAY + 1).active === false, 'revoke Sovereign: no pass left', JSON.stringify(rv));
rv = gp.revoke('cv@x.com', 'legend', 'again', T0 + 2 * DAY); ok(rv.error === 'No active Legend pass on this account.', 'revoking an inactive Legend is refused', rv.error);
// admin stats: per tier, each account once at its top tier; comps are not sales
const st2 = gp.adminStats(T0 + DAY); const S2 = st2.tiers;
ok(Object.keys(S2).join() === 'weekly,explorer,champion,sovereign,legend' && S2.sovereign.name === 'Sovereign' && S2.legend.name === 'Legend', 'admin stats carry all five tiers by name', Object.keys(S2).join());
ok(S2.legend.active >= 3 && S2.legend.comped === 1 && S2.sovereign.comped === 1 && S2.legend.soldTotal >= 4 && S2.sovereign.soldTotal >= 4, 'admin stats: Legend/Sovereign active, sold and comped counted', JSON.stringify({ l: S2.legend, s: S2.sovereign }));
ok(st2.settings.tiers.legend.days === 365 && st2.settings.tiers.sovereign.price === 9999, 'admin settings block shows Legend 365 days, Sovereign 9999', '');
// tournament: Legend/Sovereign sales stay out of the pool unless passTournamentTierSales
for (const k of [...passes.keys()]) passes.delete(k);
const wkT = Date.parse('2026-11-10T18:00:00Z');
await gp.buy('t1@x.com', paid, wkT, 'weekly'); await gp.buy('t2@x.com', paid, wkT, 'legend'); await gp.buy('t3@x.com', paid, wkT, 'sovereign');
let tr = await gp.runTournament(wkT, { force: true }); ok(tr.sales === 1 && tr.salesUsd === 5, 'passTournamentTierSales default off: Sovereign/Legend sales do not feed the pool', JSON.stringify({ s: tr.sales, u: tr.salesUsd }));
SC.passTournamentTierSales = '1';
tr = await gp.runTournament(wkT, { force: true }); ok(tr.sales === 3 && tr.salesUsd === 354.98, 'passTournamentTierSales on: Legend ($249.99) and Sovereign ($99.99) are added', JSON.stringify({ s: tr.sales, u: tr.salesUsd }));
delete SC.passTournamentTierSales;
try { fs.rmSync(dataDir, { recursive: true, force: true }); } catch (e) {}
console.log(fails ? fails + ' FAILURE(S)' : 'ALL PASS');
process.exit(fails ? 1 : 0);