Game Pass package rail, part two: Admin > Game Pass gets a Pass sales table (every sale labelled package / credit-paid (old rule) / package (old rule), pass value, package value, package tx link) and stats passes.pay + sales; the chatbot canned answer, tier fact and system prompt say every pass is paid by a new package bought after tapping Get (sponsor and team paid, credits kept for ads, held credits never buy a pass); docs/GAME-PASS.md "Payment: the package rail" section; release-note update draft (not sent); admin.js tag bumped. Fulfilment stamps the pass at the event time again (as before). Tests: sov-passes store + local rebuilt on order + fresh package (seeded credits never spent), gamepass ALL PASS, member walk 0 bugs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+71
-59
@@ -1,6 +1,6 @@
|
||||
// Pass tiers (2026-10-18, ultima-rpg docs/IAP-PASSES-SPEC.md section 8): unit checks of the gamepass.js store, no server.
|
||||
// node qa/sov-passes-store.cjs
|
||||
// Loads gamepass.js with in-memory maps and a fake site config. Covers: lazy migration of a weekly-only record, buy per tier,
|
||||
// Loads gamepass.js with in-memory maps and a fake site config. Since 2026-10-22 every "buy" is an order + a fresh package (buyX). Covers: lazy migration of a weekly-only record, buy per tier,
|
||||
// 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.
|
||||
@@ -18,8 +18,20 @@ gp.init({ dataDir, siteConfig: () => Object.assign({}, SC), persistedMap: k => (
|
||||
accounts: { byMemberId: async () => null, byEmail: async () => null }, marks: { claim: async () => true }, polUsd: async () => 0.1, telegram: async () => {}, notify: async () => {} });
|
||||
const passes = maps.gamepass, orders = maps.gporders;
|
||||
const T0 = Date.parse('2026-10-20T17:00:00Z'); // Tue Oct 20, noon Central
|
||||
const paid = async () => ({ ok: true, campaignId: 1 });
|
||||
const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
// 2026-10-22: no pass is bought with credits any more. buy() only opens a waiting order; a fresh package Purchase fulfils it.
|
||||
// buyX keeps the old test shape: `short` = the member opens the order and pays nothing yet; any other payer (paid / a spy) = the member
|
||||
// opens the order and then buys a package of exactly the pass price, mined at `now` (the spy sees the price and the pass label).
|
||||
const paid = async () => ({ ok: true });
|
||||
const short = async () => ({ error: 'short' });
|
||||
let txN = 0;
|
||||
async function buyX(email, payer, now, tier, opts) {
|
||||
const r = gp.buy(email, now, tier, opts); if (r.error || payer === short) return r;
|
||||
const t = r.tier; const days = gp.cfg().tiers[t].days;
|
||||
await payer(r.price, (t === 'weekly' ? 'Game Pass' : gp.TIER_NAMES[t] + ' pass') + ' (' + days + ' days)');
|
||||
const ev = await gp.onEvent({ type: 'Purchase', priceCents: r.price, tx: '0xpkg' + (++txN), ts: now, devEmail: email, devMinedAt: now, devNow: now });
|
||||
if (!ev) return { error: 'package did not fulfil the order', r };
|
||||
return { ok: true, tier: ev.tier, until: ev.until, days, paid: 'package' };
|
||||
}
|
||||
|
||||
(async () => {
|
||||
// 1. migration: a record from before tiers (until only) reads as the weekly tier; flag answers as before plus tier
|
||||
@@ -29,47 +41,47 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
f = gp.flag('old@x.com', T0 + 5 * DAY);
|
||||
ok(f.active === false && f.tier === null && f.until === T0 + 3 * DAY, 'expired weekly-only record: inactive, until kept as before tiers, tier null', JSON.stringify(f));
|
||||
f = gp.flag('never@x.com', T0); ok(f.active === false && f.until === null && f.tier === null, 'never bought: { active false, until null, tier null }', JSON.stringify(f));
|
||||
await gp.buy('old@x.com', paid, T0, 'weekly');
|
||||
await buyX('old@x.com', paid, T0, 'weekly');
|
||||
const oldRec = passes.get('old@x.com');
|
||||
ok(oldRec.tiers && oldRec.tiers.weekly.until === T0 + 10 * DAY && oldRec.until === T0 + 10 * DAY, 'buying weekly on a migrated record extends from its until and writes tiers + legacy until', JSON.stringify({ until: oldRec.until, tiers: oldRec.tiers }));
|
||||
|
||||
// 2. the switch: off refuses Explorer/Champion for members, the weekly pass is unchanged; the admin may buy
|
||||
let r = await gp.buy('a@x.com', paid, T0, 'explorer');
|
||||
let r = await buyX('a@x.com', paid, T0, 'explorer');
|
||||
ok(r.error === 'The Explorer pass is not open yet.', 'sovTiers off: Explorer refused', JSON.stringify(r));
|
||||
r = await gp.buy('a@x.com', paid, T0, 'champion');
|
||||
r = await buyX('a@x.com', paid, T0, 'champion');
|
||||
ok(r.error === 'The Champion pass is not open yet.', 'sovTiers off: Champion refused', JSON.stringify(r));
|
||||
ok(!passes.get('a@x.com'), 'a refused buy writes nothing', '');
|
||||
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,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 });
|
||||
r = await buyX('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
|
||||
r = await buyX('a@x.com', paid, T0); // tier missing = weekly
|
||||
ok(r.ok && r.tier === 'weekly' && r.until === T0 + 7 * DAY && r.days === 7, 'tier missing = weekly: 500 credits, 7 days, as before', JSON.stringify(r));
|
||||
let charged = null; await gp.buy('z@x.com', async (price, label) => { charged = { price, label }; return { ok: true }; }, T0);
|
||||
let charged = null; await buyX('z@x.com', async (price, label) => { charged = { price, label }; return { ok: true }; }, T0);
|
||||
ok(charged && charged.price === 500 && charged.label === 'Game Pass (7 days)', 'weekly charge unchanged: 500 credits, label "Game Pass (7 days)"', JSON.stringify(charged));
|
||||
r = await gp.buy('a@x.com', paid, T0, 'platinum'); ok(r.error === 'There is no such pass.', 'unknown tier refused', JSON.stringify(r));
|
||||
r = await buyX('a@x.com', paid, T0, 'platinum'); ok(r.error === 'There is no such pass.', 'unknown tier refused', JSON.stringify(r));
|
||||
SC.gamePassEnabled = '0'; SC.sovTiers = '1';
|
||||
r = await gp.buy('a@x.com', paid, T0, 'explorer'); ok(!!r.error, 'sovTiers on but the weekly Game Pass off: Explorer refused for members', JSON.stringify(r));
|
||||
r = await buyX('a@x.com', paid, T0, 'explorer'); ok(!!r.error, 'sovTiers on but the weekly Game Pass off: Explorer refused for members', JSON.stringify(r));
|
||||
SC.gamePassEnabled = '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');
|
||||
charged = null; r = await buyX('b@x.com', async (price, label) => { charged = { price, label }; return { ok: true }; }, T0, 'explorer');
|
||||
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 === 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');
|
||||
r = await buyX('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');
|
||||
r = await buyX('c@x.com', paid, T0, 'champion'); ok(r.ok && r.until === T0 + 30 * DAY, 'Champion: 30 days', '');
|
||||
r = await buyX('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 === 3999, 'Champion charges 3999 credits', String(charged));
|
||||
charged = null; await buyX('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
|
||||
await gp.buy('d@x.com', paid, T0, 'explorer'); // explorer to T0+30
|
||||
await gp.buy('d@x.com', paid, T0 - 20 * DAY, 'champion'); // champion bought earlier, to T0+10
|
||||
await buyX('d@x.com', paid, T0, 'weekly'); // weekly to T0+7
|
||||
await buyX('d@x.com', paid, T0, 'explorer'); // explorer to T0+30
|
||||
await buyX('d@x.com', paid, T0 - 20 * DAY, 'champion'); // champion bought earlier, to T0+10
|
||||
f = gp.flag('d@x.com', T0 + DAY);
|
||||
ok(f.tier === 'champion' && f.until === T0 + 10 * DAY && f.active && f.tiers.weekly === T0 + 7 * DAY && f.tiers.explorer === T0 + 30 * DAY && f.tiers.champion === T0 + 10 * DAY, 'all three on: tier champion, until = Champion end, tiers side by side', JSON.stringify(f));
|
||||
f = gp.flag('d@x.com', T0 + 12 * DAY);
|
||||
@@ -78,7 +90,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
|
||||
// 5. no extra POL: the caps are identical for weekly, explorer and champion holders (and higher than free)
|
||||
const day = '2026-10-21'; const at = Date.parse(day + 'T17:00:00Z');
|
||||
await gp.buy('w@x.com', paid, at, 'weekly'); await gp.buy('e@x.com', paid, at, 'explorer'); await gp.buy('ch@x.com', paid, at, 'champion');
|
||||
await buyX('w@x.com', paid, at, 'weekly'); await buyX('e@x.com', paid, at, 'explorer'); await buyX('ch@x.com', paid, at, 'champion');
|
||||
const capsOf = e => { const c = gp.capsFor(e, at); return [c.pass, c.daily, c.total].join('/'); };
|
||||
ok(capsOf('w@x.com') === capsOf('e@x.com') && capsOf('e@x.com') === capsOf('ch@x.com') && capsOf('w@x.com') === 'true/1.5/5' && capsOf('free@x.com') === 'false/0.3/2', 'capsFor: weekly = explorer = champion = pass caps 1.50 / 5', [capsOf('w@x.com'), capsOf('e@x.com'), capsOf('ch@x.com'), capsOf('free@x.com')].join(' '));
|
||||
const g = e => gp.grant({ email: e, game: 'polhunter', kind: 'daily', pol: 3, ref: 'cap:' + e, now: at });
|
||||
@@ -86,14 +98,14 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
ok(gw.allowed === 1.5 && ge.allowed === 1.5 && gc.allowed === 1.5 && gw.pass && ge.pass && gc.pass, 'polgrant: a 3 POL daily grant allows 1.50 for every tier, pass: true (a boolean)', [gw.allowed, ge.allowed, gc.allowed, typeof gc.pass].join(' '));
|
||||
|
||||
// 6. waiting orders per tier; a package of at least the tier price fulfils it; each tx once; highest-priced first
|
||||
r = await gp.buy('p@x.com', short, T0, 'explorer');
|
||||
ok(r.needPay && r.tier === 'explorer' && r.payUrl === '/my?from=gamepass&tier=explorer#buy' && r.package === 20 && /\$20 package/.test(r.message), 'Explorer short: waiting order, payUrl with tier, "$20 package"', JSON.stringify({ payUrl: r.payUrl, msg: r.message }));
|
||||
r = await buyX('p@x.com', short, T0, 'explorer');
|
||||
ok(r.needPay && r.tier === 'explorer' && r.payUrl === '/my?from=gamepass&tier=explorer#buy' && r.package === 20 && /package of \$20 or more/.test(r.message), 'Explorer short: waiting order, payUrl with tier, "$20 package"', JSON.stringify({ payUrl: r.payUrl, msg: r.message }));
|
||||
const ordE = r.order;
|
||||
r = await gp.buy('p@x.com', short, T0, 'explorer'); ok(r.order === ordE, 'same tier again reuses its waiting order', '');
|
||||
r = await gp.buy('p@x.com', short, T0, 'champion'); const ordC = r.order;
|
||||
ok(r.needPay && r.order !== ordE && r.package === 50 && /\$50 package/.test(r.message), 'Champion short: its own waiting order; copy names the $50 package (there is no $40 one)', r.message);
|
||||
r = await gp.buy('p@x.com', short, T0, 'weekly');
|
||||
ok(r.payUrl === '/my?from=gamepass#buy' && /Buy a \$5 package/.test(r.message), 'weekly short: payUrl and copy exactly as before', r.payUrl);
|
||||
r = await buyX('p@x.com', short, T0, 'explorer'); ok(r.order === ordE, 'same tier again reuses its waiting order', '');
|
||||
r = await buyX('p@x.com', short, T0, 'champion'); const ordC = r.order;
|
||||
ok(r.needPay && r.order !== ordE && r.package === 50 && /package of \$50 or more/.test(r.message), 'Champion short: its own waiting order; copy names the $50 package (there is no $40 one)', r.message);
|
||||
r = await buyX('p@x.com', short, T0, 'weekly');
|
||||
ok(r.payUrl === '/my?from=gamepass#buy' && /package of \$5 or more/.test(r.message), 'weekly short: payUrl and copy exactly as before', r.payUrl);
|
||||
let ev = await gp.onEvent({ type: 'Purchase', priceCents: 500, tx: '0xa1', ts: T0 + 60000, devEmail: 'p@x.com' });
|
||||
ok(ev && ev.tier === 'weekly', 'a $5 package fulfils the weekly order, not Explorer or Champion', JSON.stringify(ev));
|
||||
ev = await gp.onEvent({ type: 'Purchase', priceCents: 1000, tx: '0xa2', ts: T0 + 60000, devEmail: 'p@x.com' });
|
||||
@@ -104,7 +116,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
ok(ev === null, 'the same tx again counts once', JSON.stringify(ev));
|
||||
ev = await gp.onEvent({ type: 'Purchase', priceCents: 5000, tx: '0xa4', ts: T0 + 60000, devEmail: 'p@x.com' });
|
||||
ok(ev && ev.tier === 'champion' && ev.order === ordC, 'a $50 package fulfils the Champion order', JSON.stringify(ev));
|
||||
await gp.buy('q@x.com', short, T0, 'weekly'); await gp.buy('q@x.com', short, T0, 'explorer'); await gp.buy('q@x.com', short, T0, 'champion');
|
||||
await buyX('q@x.com', short, T0, 'weekly'); await buyX('q@x.com', short, T0, 'explorer'); await buyX('q@x.com', short, T0, 'champion');
|
||||
ev = await gp.onEvent({ type: 'Purchase', priceCents: 2000, tx: '0xb1', ts: T0, devEmail: 'q@x.com' });
|
||||
ok(ev && ev.tier === 'explorer', 'three orders waiting, a $20 package: the highest-priced one it covers (Explorer) is fulfilled first', JSON.stringify(ev));
|
||||
ev = await gp.onEvent({ type: 'Purchase', priceCents: 50000, tx: '0xb2', ts: T0, devEmail: 'q@x.com' });
|
||||
@@ -126,13 +138,13 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
// 8. admin stats: each account once at its top tier, Central week and month
|
||||
for (const k of [...passes.keys()]) passes.delete(k); for (const k of [...orders.keys()]) orders.delete(k);
|
||||
const NOW = Date.parse('2026-11-04T18:00:00Z'); // Wed Nov 4, noon Central (CST); week from Mon Nov 2, month from Nov 1
|
||||
await gp.buy('s1@x.com', paid, Date.parse('2026-11-02T06:30:00Z'), 'weekly'); // Mon Nov 2 00:30 Central: this week
|
||||
await gp.buy('s1@x.com', paid, Date.parse('2026-11-02T05:30:00Z'), 'explorer'); // Sun Nov 1 23:30 Central: last week, this month
|
||||
await gp.buy('s2@x.com', paid, Date.parse('2026-11-01T04:30:00Z'), 'champion'); // Oct 31 23:30 Central: last month
|
||||
await gp.buy('s2@x.com', paid, Date.parse('2026-11-03T18:00:00Z'), 'champion'); // a renewal this week
|
||||
await gp.buy('s3@x.com', paid, NOW - 2 * DAY, 'weekly'); // ends within 7 Central days
|
||||
await buyX('s1@x.com', paid, Date.parse('2026-11-02T06:30:00Z'), 'weekly'); // Mon Nov 2 00:30 Central: this week
|
||||
await buyX('s1@x.com', paid, Date.parse('2026-11-02T05:30:00Z'), 'explorer'); // Sun Nov 1 23:30 Central: last week, this month
|
||||
await buyX('s2@x.com', paid, Date.parse('2026-11-01T04:30:00Z'), 'champion'); // Oct 31 23:30 Central: last month
|
||||
await buyX('s2@x.com', paid, Date.parse('2026-11-03T18:00:00Z'), 'champion'); // a renewal this week
|
||||
await buyX('s3@x.com', paid, NOW - 2 * DAY, 'weekly'); // ends within 7 Central days
|
||||
gp.comp('s4@x.com', 'qa', 'explorer', NOW - DAY);
|
||||
await gp.buy('s5@x.com', short, NOW, 'champion');
|
||||
await buyX('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 === 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] }));
|
||||
@@ -154,34 +166,34 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
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));
|
||||
r = await buyX('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 buyX('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 buyX('m@x.com', short, T0, 'legend'); ok(r.error && ![...orders.values()].some(o => o.email === 'm@x.com' && o.status === 'waiting'), '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 });
|
||||
charged = null; r = await buyX('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 buyX('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');
|
||||
charged = null; r = await buyX('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(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].cents === 9999 && rec.bought[0].via === 'package', 'only the Sovereign tier moved; bought row has tier, $99.99, a 9999-cent package', JSON.stringify(rec));
|
||||
charged = null; r = await buyX('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());
|
||||
r = await buyX('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 buyX('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 buyX('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 buyX('lg2@x.com', paid, T0, 'legend'); r = await buyX('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
|
||||
await buyX('all@x.com', paid, T0, 'weekly'); await buyX('all@x.com', paid, T0, 'explorer'); await buyX('all@x.com', paid, T0, 'champion');
|
||||
await buyX('all@x.com', paid, T0, 'sovereign'); await buyX('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');
|
||||
await buyX('ce@x.com', paid, T0, 'champion'); await buyX('ce@x.com', paid, T0, 'sovereign'); await buyX('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');
|
||||
@@ -189,33 +201,33 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
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);
|
||||
r = await buyX('wo@x.com', short, T0, 'sovereign');
|
||||
ok(r.needPay && r.tier === 'sovereign' && r.payUrl === '/my?from=gamepass&tier=sovereign#buy' && r.package === 100 && /package of \$100 or more/.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', '');
|
||||
r = await buyX('wo@x.com', short, T0, 'legend'); const ordL = r.order;
|
||||
ok(r.needPay && r.order !== ordS && r.package === 250 && /package of \$250 or more/.test(r.message) && r.payUrl === '/my?from=gamepass&tier=legend#buy', 'Legend short: its own waiting order, "$250 package"', r.message);
|
||||
r = await buyX('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');
|
||||
await buyX('wo2@x.com', short, T0, 'champion'); await buyX('wo2@x.com', short, T0, 'sovereign'); await buyX('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');
|
||||
r = await buyX('ks@x.com', paid, T0, 'legend'); const r2 = await buyX('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));
|
||||
r = await buyX('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));
|
||||
charged = null; r = await buyX('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);
|
||||
@@ -233,7 +245,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
|
||||
// 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');
|
||||
await buyX('t1@x.com', paid, wkT, 'weekly'); await buyX('t2@x.com', paid, wkT, 'legend'); await buyX('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 }));
|
||||
|
||||
Reference in New Issue
Block a user