abfb3e3199
Paid exactly like a pass: no credits, no POL. POST /api/my/heroes/buy opens a waiting order (kind hero); a fresh package of at least the
price from one of the member's own positions fulfils it in gamepass.onEvent (one package, one order: the highest-priced it covers, pass
or hero; each tx once). Ownership is permanent on the passes record (heroes, heroBundle), never in bought, so hero sales never feed the
Pass Tournament pool. No double charge: an owned hero is refused, a bundle is refused once any of its heroes is owned, and waiting orders
made pointless by a purchase are cancelled.
Settings (Admin > Settings): heroSales '0', heroPrice<Kestrel|Valda|Morag|Roland>Cents 2000 (0 = free for every account),
heroBundlePriceCents 5000, heroBundleHeroes 'valda,morag,roland', heroBundleCap '' (unset: the bundle is heroes only, no cap change).
Hand-off: sovMint (and GET /api/partner/player for shardsofvalor) carries heroes, heroBundle, heroSale { free, bundle, each, bundlePrice },
and heroBundleCap only when set. TIER_DEFS perks: Champion no longer lists the Druid, Sovereign no longer the Necromancer (dropped),
Legend every bonus hero while active. Member Game Pass card: a Bonus heroes block (shown while heroSales is on or to an owner);
Admin > Game Pass: hero test on the admin's own account (test buy / cancel / give / remove) and /api/admin/heroes/stats.
Chatbot: canned sov-bonus-heroes answer + heroesFact following heroSales; KNOWLEDGE_DATE 2026-11-05. my.js?v=20261105hr, admin.js?v=20261105hr.
QA: qa/sov-heroes-store.cjs (39 checks, in member and sov-passes); sov-passes-local expects the hero test panel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
213 lines
26 KiB
JavaScript
213 lines
26 KiB
JavaScript
// Explorer / Champion passes end to end on a LOCAL throwaway copy (2026-10-18, ultima-rpg docs/IAP-PASSES-SPEC.md).
|
|
// node qa/sov-passes-local.mjs screenshots -> SHOTS (default D:/tmp/sov-passes)
|
|
// Boots server.js with a throwaway DATA_DIR and throwaway SOV secret, preloading qa/sov-passes-stub.cjs, which seeds 2500
|
|
// purchased-grade credits on one fake position owned by the admin account. Nothing touches production.
|
|
// Covers: sovTiers off -> a member sees and can buy only the weekly pass; the ADMIN_EMAIL account sees the admin preview and buys
|
|
// 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 (Marty): no pass is bought with credits any more. The seeded credits must stay untouched: every tier is an order plus a
|
|
// fresh package purchase (faked locally with /api/dev/gamepass-purchase), and the card sends the member to Buy credits.
|
|
// 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.
|
|
// 2026-10-25 (Marty): no admin-only tier UI on the member card. The ADMIN_EMAIL account gets the member view on /my (weekly only,
|
|
// hidden-tier buys refused there too); every tier test runs from Admin > Game Pass > Tier test and preview (/api/admin/gamepass/preview,
|
|
// test-buy, test-cancel, test-comp), always on the admin's own account. A holder of a tier sees it on the card like any member.
|
|
import crypto from 'node:crypto';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { spawn } from 'node:child_process';
|
|
import { pathToFileURL } from 'node:url';
|
|
|
|
const SITE = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
|
|
const PW = process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright';
|
|
const { chromium } = (await import(pathToFileURL(PW + '/index.js').href)).default;
|
|
const PORT = Number(process.env.SOV_PORT || 8798);
|
|
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 = 2000 + 10000 + 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); });
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
|
|
const srv = spawn(process.execPath, ['-r', './qa/sov-passes-stub.cjs', 'server.js'], { cwd: SITE, stdio: ['ignore', 'pipe', 'pipe'],
|
|
env: Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, NODE_ENV: 'development', ADMIN_EMAIL, ADMIN_PASSWORD: ADMIN_PW, SOV_SSO_SECRET: SOV, DEV_POL_USD: '0.10',
|
|
QA_SEED_EMAIL: ADMIN_EMAIL, QA_SEED_ID: String(SEED_ID), QA_SEED_CREDITS: String(SEED_CREDITS) }) });
|
|
let srvLog = ''; srv.stdout.on('data', d => srvLog += d); srv.stderr.on('data', d => srvLog += d);
|
|
let browser = null;
|
|
const cleanup = async () => { try { if (browser) await browser.close(); } catch (e) {} try { srv.kill(); } catch (e) {} await sleep(300); try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} };
|
|
|
|
async function api(p, o, headers) {
|
|
const opts = { method: (o && o.method) || (o && 'data' in o ? 'POST' : 'GET'), headers: Object.assign({ 'Content-Type': 'application/json' }, headers || {}), redirect: 'manual' };
|
|
if (o && 'data' in o) opts.body = JSON.stringify(o.data);
|
|
const r = await fetch(B + p, opts); let j = null; try { j = await r.json(); } catch (e) {}
|
|
return { status: r.status, j, headers: r.headers };
|
|
}
|
|
const adminH = { Authorization: 'Bearer ' + ADMIN_PW };
|
|
async function signIn(email, username) {
|
|
const s = await api('/api/auth/email/start', { data: { email, fts: Date.now() - 5000 } });
|
|
const v = await fetch(B + '/api/auth/email/verify', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, code: s.j && s.j.devCode }) });
|
|
const cookies = (v.headers.getSetCookie ? v.headers.getSetCookie() : [v.headers.get('set-cookie')]).map(c => String(c).split(';')[0]);
|
|
const cookie = cookies.join('; ');
|
|
if (username) await api('/api/my/profile', { data: { username } }, { Cookie: cookie });
|
|
return { Cookie: cookie, pairs: cookies.map(c => { const i = c.indexOf('='); return { name: c.slice(0, i), value: c.slice(i + 1) }; }) };
|
|
}
|
|
const decode = tok => JSON.parse(Buffer.from(String(tok).split('.')[0].replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'));
|
|
async function playerOf(email) {
|
|
const ts = String(Date.now()); const sig = crypto.createHmac('sha256', SOV).update('player:' + email + ':' + ts).digest('hex');
|
|
const r = await fetch(B + '/api/partner/player?' + new URLSearchParams({ game: 'shardsofvalor', m: '0', e: email, ts, sig })); return { status: r.status, j: await r.json() };
|
|
}
|
|
async function grant(body) {
|
|
const raw = JSON.stringify(body); const ts = String(Date.now()); const sig = crypto.createHmac('sha256', SOV).update(ts + '\n' + raw).digest('hex');
|
|
const r = await fetch(B + '/api/partner/polgrant', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Game-Ts': ts, 'X-Game-Sig': sig }, body: raw }); return r.json();
|
|
}
|
|
async function pageFor(h) {
|
|
const ctx = await browser.newContext({ viewport: { width: 1280, height: 900 } });
|
|
await ctx.addCookies(h.pairs.map(c => ({ name: c.name, value: c.value, url: B })));
|
|
await ctx.addInitScript(() => { try { sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} }); // the session pop-up would block every click
|
|
const page = await ctx.newPage(); const errs = []; page.on('pageerror', e => errs.push(String(e))); return { page, errs, ctx };
|
|
}
|
|
|
|
try {
|
|
let up = false; for (let i = 0; i < 40; i++) { try { if ((await fetch(B + '/api/config')).ok) { up = true; break; } } catch (e) {} await sleep(500); }
|
|
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) === 5000 && Number(sc.gamePassExplorerDays) === 30 && sc.passTournamentTierSales === '0', 'defaults: sovTiers 0, Explorer 2000 / Champion 5000 cents ($20 / $50, 2026-10-25), 30 days, passTournamentTierSales 0', JSON.stringify({ sovTiers: sc.sovTiers, e: sc.gamePassExplorerPriceCredits, c: sc.gamePassChampionPriceCredits }));
|
|
ok(Number(sc.gamePassSovereignPriceCredits) === 10000 && Number(sc.gamePassSovereignDays) === 30 && sc.gamePassSovereignEnabled === '1' && Number(sc.gamePassLegendPriceCredits) === 25000 && Number(sc.gamePassLegendDays) === 365 && sc.gamePassLegendEnabled === '1' && Number(sc.gamePassPriceCredits) === 500 && Number(sc.gamePassDays) === 7, 'defaults: Sovereign 10000 / 30 days, Legend 25000 / 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
|
|
let g = (await api('/api/my/gamepass', null, hM)).j;
|
|
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|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 account on /my gets the MEMBER view (2026-10-25): weekly only, no preview note, hidden tiers refused on the member route
|
|
g = (await api('/api/my/gamepass', null, hA)).j;
|
|
ok(g.passes && g.passes.length === 1 && g.passes[0].tier === 'weekly' && !g.tierPreview, 'admin on /my, sovTiers off: the member view, weekly only, no preview', JSON.stringify((g.passes || []).map(x => x.tier)));
|
|
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
|
|
ok(r.status === 400 && r.j.error === 'The Explorer pass is not open yet.', 'admin on the member route: Explorer refused like any member (tests moved to Admin > Game Pass)', JSON.stringify(r.j));
|
|
{ const { page, errs, ctx } = await pageFor(hA); await page.goto(B + '/my#passes'); await page.waitForSelector('#gpCard:not([hidden]) #gpBuy', { timeout: 15000 }); await sleep(600); await hide(page);
|
|
const txt = await page.textContent('#gpCard');
|
|
ok(!/Explorer|Champion|Sovereign|Legend|Admin preview/.test(txt) && errs.length === 0, 'admin /my Games card: the weekly card a member sees, no tier boxes, no admin preview note', errs.join(' | '));
|
|
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '2-admin-member-card-weekly-only.png') }); await ctx.close(); }
|
|
// the admin portal preview: all five tiers with what each includes, every one open to the admin's own account
|
|
g = (await api('/api/admin/gamepass/preview', null, adminH)).j;
|
|
ok(g.test === true && g.email === ADMIN_EMAIL && g.tierPreview === true && g.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign,legend' && g.passes.map(x => x.price).join() === '500,2000,5000,10000,25000' && g.passes.map(x => x.package).join() === '5,20,50,100,250' && g.passes.every(x => x.usd === x.package) && g.passes.every(x => x.open) && g.passes.filter(x => x.tier !== 'weekly').every(x => x.sale === false), 'GET /api/admin/gamepass/preview: all five tiers (500 / 2000 / 5000 / 10000 / 25000, each price = its package), open to the admin, none on sale', JSON.stringify(g.passes.map(x => [x.tier, x.price, x.open, x.sale])));
|
|
ok((await api('/api/admin/gamepass/preview', null, hM)).status === 401 && (await api('/api/admin/gamepass/test-buy', { data: { tier: 'explorer' } }, hM)).status === 401, 'tier test endpoints refuse a member session (401)', '');
|
|
// test cancel + test comp + end, on the admin's own account
|
|
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'champion' } }, adminH);
|
|
ok(r.status === 200 && r.j.needPay && r.j.tier === 'champion' && r.j.email === ADMIN_EMAIL && r.j.package === 50, 'test-buy Champion: a waiting order for a $50 package on the admin account', JSON.stringify(r.j));
|
|
r = await api('/api/admin/gamepass/test-cancel', { data: { tier: 'champion' } }, adminH);
|
|
g = (await api('/api/admin/gamepass/preview', null, adminH)).j;
|
|
ok(r.j.ok && r.j.order && !g.passes.find(x => x.tier === 'champion').waiting, 'test-cancel drops the Champion test order', JSON.stringify(r.j));
|
|
r = await api('/api/admin/gamepass/test-comp', { data: { tier: 'champion' } }, adminH);
|
|
ok(r.j.ok && r.j.tier === 'champion' && r.j.email === ADMIN_EMAIL && r.j.until > Date.now(), 'test-comp Champion starts one period on the admin account at once', JSON.stringify(r.j));
|
|
r = await api('/api/admin/gamepass/revoke', { data: { email: ADMIN_EMAIL, tier: 'champion', why: 'admin tier test' } }, adminH);
|
|
g = (await api('/api/my/gamepass', null, hA)).j;
|
|
ok(r.j.ok && !g.active && g.passes.length === 1, 'ending the test Champion puts the admin card back to the weekly member view', JSON.stringify({ a: g.active, rows: g.passes.map(x => x.tier) }));
|
|
{ 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.waitForSelector('#gpTest [data-gpt-buy="explorer"]', { timeout: 10000 }).catch(() => {}); }
|
|
let txt = await page.textContent('#gpTest').catch(() => '');
|
|
ok(/Test \/ preview, admin only/.test(txt) && /hidden from members/.test(txt) && /Sovereign/.test(txt) && /Roland the Paladin/.test(txt) && /heroSales off/.test(txt) && /Legend/.test(txt) && /\$250 /.test(txt) && /for 1 year/.test(txt) && /Archer/.test(txt) && /Druid/.test(txt) && /level cap 30/.test(txt) && /\$20 /.test(txt) && !/\.99/.test(txt) && /Shards of Valor > Passes/.test(txt) && !/\u2014/.test(txt) && errs.length === 0, 'Admin > Game Pass > Tier test and preview: labelled test/preview, all five tiers with what each includes, no em dashes', errs.join(' | ') || (nav ? '' : 'admin nav not found'));
|
|
await page.locator('#gpTestCard').scrollIntoViewIfNeeded(); await sleep(300);
|
|
await page.locator('#gpTestCard').screenshot({ path: path.join(SHOTS, '3-admin-tier-test-panel.png') });
|
|
await page.click('#gpTest [data-gpt-buy="explorer"]'); await page.waitForSelector('#dlgOk', { timeout: 5000 });
|
|
await page.screenshot({ path: path.join(SHOTS, '3b-admin-confirm-test-explorer.png') });
|
|
await page.click('#dlgOk');
|
|
await page.waitForFunction(() => /test order waiting for a \$20 package/.test((document.getElementById('gpTest') || {}).textContent || ''), null, { timeout: 10000 }).catch(() => {});
|
|
txt = await page.textContent('#gpTest').catch(() => '');
|
|
ok(/test order waiting for a \$20 package/.test(txt) && errs.length === 0, 'Test buy Explorer from the admin panel: the card shows the waiting test order', errs.join(' | '));
|
|
await page.locator('#gpTestCard').screenshot({ path: path.join(SHOTS, '4-admin-test-order-waiting.png') }); await ctx.close(); }
|
|
let g1 = (await api('/api/admin/gamepass/preview', null, adminH)).j; const ex1 = g1.passes.find(x => x.tier === 'explorer');
|
|
ok(!g1.active && ex1 && ex1.waiting === true && !ex1.active, 'the click opened a waiting Explorer order; nothing active yet', JSON.stringify(ex1));
|
|
ok(!/gamepass bought with credits/.test(srvLog), 'no credit charge: the seeded purchased credits were not spent on the pass', '');
|
|
const dv0 = (await api('/api/dev/gamepass-purchase', { data: { cents: 2000, email: ADMIN_EMAIL } })).j;
|
|
ok(dv0 && dv0.order && dv0.order.tier === 'explorer', 'a fresh $20 package fulfils the Explorer test order', JSON.stringify(dv0));
|
|
// a HOLDER sees the tier on the member card the way any member holding it would (no preview note, nothing they cannot buy listed)
|
|
{ const { page, errs, ctx } = await pageFor(hA); await page.goto(B + '/my?from=shardsofvalor#passes');
|
|
await page.waitForFunction(() => /Explorer active/.test((document.getElementById('gpCard') || {}).textContent || ''), null, { timeout: 15000 }).catch(() => {});
|
|
await sleep(600); await hide(page);
|
|
const after = await page.textContent('#gpCard');
|
|
ok(/#games/.test(page.url()), 'the Shards of Valor link (#passes) lands on the pass card, not the Buy pane', page.url());
|
|
ok(/Explorer active/.test(after) && /never better than gear players can earn/.test(after) && /main story of Shards of Valor is free/.test(after) && !/Admin preview|Champion|Sovereign|Legend/.test(after) && !/\u2014/.test(after) && errs.length === 0, 'holder card: Explorer active, weekly + Explorer only, no admin preview, no em dashes', errs.join(' | '));
|
|
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '5-admin-explorer-active-holder-card.png') }); await ctx.close(); }
|
|
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 fulfilled by package explorer qa-admin@example.com/.test(srvLog), 'Explorer paid by the package rail, not 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);
|
|
const loc = ho.headers.get('location') || ''; const t = new URL(loc).searchParams.get('t'); const claims = t ? decode(t) : null;
|
|
ok(ho.status === 302 && claims && claims.gamePass && claims.gamePass.active === true && claims.gamePass.tier === 'explorer' && claims.gamePass.until === ex.until && !('tiers' in claims.gamePass), 'hand-off token: gamePass { active, until, tier: explorer }', JSON.stringify(claims && claims.gamePass));
|
|
const sig = t && crypto.createHmac('sha256', SOV).update(Buffer.from(t.split('.')[0].replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8')).digest('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
ok(sig && sig === t.split('.')[1], 'the token verifies with SOV_SSO_SECRET', '');
|
|
const pl = await playerOf(ADMIN_EMAIL);
|
|
ok(pl.status === 200 && pl.j.pass.active === true && pl.j.pass.tier === 'explorer' && pl.j.pass.tiers && pl.j.pass.tiers.explorer === ex.until && pl.j.pass.tiers.champion === null && pl.j.caps.daily === 1.5 && pl.j.caps.total === 5, 'GET /api/partner/player: pass { active, until, tier: explorer, tiers }, weekly pass caps 1.50 / 5', JSON.stringify(pl.j.pass) + ' ' + JSON.stringify({ d: pl.j.caps.daily, t: pl.j.caps.total }));
|
|
const plm = await playerOf(MEMBER);
|
|
ok(plm.j.pass.active === false && plm.j.pass.tier === null, 'a free member: pass { active false, tier null }', JSON.stringify(plm.j.pass));
|
|
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 (10000 cents = $100, 30 days) and the yearly Legend (25000 = $250, 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/admin/gamepass/test-buy', { data: { tier: 'sovereign' } }, adminH);
|
|
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'sovereign' && r.j.package === 100, 'admin Sovereign (sovTiers off, testing): a waiting order for a $100 package, credits untouched', JSON.stringify(r.j));
|
|
let dvS = (await api('/api/dev/gamepass-purchase', { data: { cents: 10000, email: ADMIN_EMAIL } })).j;
|
|
ok(dvS && dvS.order && dvS.order.tier === 'sovereign' && Math.abs(dvS.order.until - (Date.now() + 30 * 86400000)) < 120000, 'a fresh $100 package fulfils Sovereign: 30 days', JSON.stringify(dvS));
|
|
ok(!/gamepass bought with credits/.test(srvLog), 'still no credit charge anywhere', '');
|
|
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'explorer' } }, adminH);
|
|
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'explorer' && /package of \$20 or more/.test(r.j.message), 'a second Explorer -> waiting order, "package of $20 or more"', JSON.stringify({ needPay: r.j.needPay, payUrl: r.j.payUrl, msg: r.j.message }));
|
|
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'legend' } }, adminH);
|
|
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'legend' && r.j.price === 25000 && r.j.payUrl === '/my?from=gamepass&tier=legend#buy' && /package of \$250 or more/.test(r.j.message), 'Legend: waiting order, "package of $250 or more", 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/admin/gamepass/preview', null, adminH)).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 === 0 && st.tiers.explorer.soldTotal === 2 && st.tiers.explorer.usdTotal === 40 && st.tiers.explorer.waitingOrders === 0 && st.tierSales === false, 'admin stats: Explorer 2 sold ($40: 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 === 100 && st.tiers.legend.active === 1 && st.tiers.legend.soldTotal === 1 && st.tiers.legend.usdTotal === 250 && st.tiers.legend.waitingOrders === 0 && st.settings.tiers.legend.days === 365 && st.settings.tiers.sovereign.sale === false, 'admin stats: Sovereign 1 sold ($100), Legend 1 active + 1 sold ($250), 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) && /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++;
|
|
} finally {
|
|
await cleanup();
|
|
}
|
|
if (fails) console.log('--- server log (tail) ---\n' + srvLog.split('\n').filter(l => /gamepass|Error|error|qa stub/.test(l)).slice(-30).join('\n'));
|
|
console.log(fails ? fails + ' FAILURE(S)' : 'ALL PASS');
|
|
process.exit(fails ? 1 : 0);
|