Files
wownerogue/test/directEntryCredit_ultra.test.js
T
jwinterm 42ed51af69 feat(monetization): lock the cosmetic ladder (loyalty model) + free Original pack
Nails down the premium unlock system per the design pass:
- FREE `original` topdown pack (NEW): the game's bare tiles — floor/wall/door/
  torch/features only, no furniture, so the free tavern reads plain (the intended
  "reason to unlock"). Registered in assetPacks (RK.THEMES.original) as the free
  default topdown pack; plain ASCII stays free (accessibility).
- Loyalty ladder (lifetime credits PURCHASED, cumulative, NOT deducted → buying to
  play also unlocks cosmetics): Interior 1, skins 5, iso 10, +tilepack 20, +iso 40,
  3D 50. Each row is data (tilepack OR skin) → operator appends more at any rung.
  DEFAULT_CATALOG (entitlements.js) + migration 028 + MONETIZATION.md ladder table.
- Tests updated to the new thresholds (catalogEntitlements_ultra, directEntryCredit_ultra).

Note: this reprices roguelike-interior from free → 1cr, so once deployed the free
tavern becomes bare (by design). Deploy is bundled with the single-player render-kit
migration so the free-tier change lands with its payoff. Suite 61/432 green.
2026-07-12 09:52:13 -04:00

66 lines
3.0 KiB
JavaScript

/**
* Credits unification, step ②: a direct/single_game entry is recorded as "buy 1 credit and
* spend it" — the balance nets to zero but total_credits_purchased advances, so direct play
* unlocks the same tier/threshold cosmetics as buying credits.
*/
const GameModeManager = require('../src/game/gameModeManager');
const mockPaymentConfig = () => ({
getConfig: () => ({
paymentsEnabled: true,
currency: { symbol: 'WOW', decimals: 11 },
modes: {
direct: { enabled: true, price: 100000000000n },
credits: { enabled: false, creditsPerGame: 1, packages: [] }
},
payouts: { rules: { direct: { enabled: false, multipliers: { escape: 2, escapeWithTreasure: 3 }, minPayout: 0n, maxPayout: 0n } } },
preferences: { preferCreditsFirst: true },
earlyEntry: { enabled: false }
}),
getLegacyGameMode: () => 'PAID_SINGLE',
eventBus: { on: () => {} }
});
function makeGmm(userRow) {
const client = { query: jest.fn().mockResolvedValue({ rows: [userRow] }) };
const db = {
query: jest.fn().mockResolvedValue({ rows: [] }), // user_pack_entitlements lookup
withTransaction: jest.fn().mockImplementation(async (cb) => cb(client)),
_client: client
};
const gmm = new GameModeManager(db, { processPayout: jest.fn() }, { CONSOLE_LOGGING: false, getCurrentBlockHeight: () => 1 }, mockPaymentConfig());
gmm.getOrCreateUser = jest.fn().mockResolvedValue({ id: 7 });
return { gmm, db, client };
}
describe('recordDirectEntryPurchase', () => {
test('advances total_credits_purchased and unlocks threshold-1 packs', async () => {
const { gmm, client } = makeGmm({ total_credits_purchased: 1, credits: 0, premium_level: null });
const rec = await gmm.recordDirectEntryPurchase('sock');
expect(rec).toBeTruthy();
expect(rec.totalCreditsPurchased).toBe(1);
expect(rec.balance).toBe(0); // net zero — bought and spent
const insert = client.query.mock.calls.find(c => /INSERT INTO credit_transactions/i.test(c[0]));
expect(insert).toBeTruthy();
expect(insert[0]).toMatch(/'direct_entry'/); // audits the purchase leg
expect(insert[0]).toMatch(/'game_entry'/); // audits the spend leg
// A direct entry = 1 credit, which unlocks the first tilepack (roguelike-interior, threshold
// 1) but not skins (5) / Iso (10) / 3D (50).
expect(rec.entitlements.packs['roguelike-interior']).toBe(true);
expect(rec.entitlements.packs['generated-skins']).toBe(false);
expect(rec.entitlements.packs['iso-dungeon']).toBe(false);
expect(rec.entitlements.premium).toBe(true);
// ...but a direct buyer is still NOT a premium tier.
expect(rec.entitlements.level).toBe('free');
});
test('returns null when the session has no user', async () => {
const { gmm } = makeGmm({});
gmm.getOrCreateUser = jest.fn().mockResolvedValue(null);
expect(await gmm.recordDirectEntryPurchase('sock')).toBe(null);
});
});