import test from 'node:test'; import assert from 'node:assert/strict'; import { leaders } from '../game/cards'; import { BattleResolutionQuoteError, quoteBattleResolution, type BattleResolutionInput, type ResolutionCombatant, } from '../game/battle-resolution-quote'; /** Two actual leader identities and paid forces; CHOAM is a third seat. The * caller supplies the final public-reveal flag from the same battle receipt. */ function battle(): BattleResolutionInput { const side = (id: string, faction: 'harkonnen' | 'atreides'): ResolutionCombatant => { const leader = leaders(faction)[0]; return { id, faction, leader, spice: 10, hand: [], plan: { dial: 2, support: 2, leader: leader.id, weapon: null, defense: null }, forces: { normal: 5, elite: 0, eliteStrength: 2, freeSupport: false } }; }; return { advanced: true, turn: 2, territory: 'arrakeen', attacker: side('h', 'harkonnen'), defender: side('a', 'atreides'), voters: [{ id: 'h', beneficiary: 'h', called: false, traitors: [] }, { id: 'a', beneficiary: 'a', called: false, traitors: [] }], participants: [{ id: 'h', faction: 'harkonnen' }, { id: 'a', faction: 'atreides' }, { id: 'c', faction: 'choam' }], physicalCards: [], pendingAuditorPresent: false, pendingRetentionPresent: false }; } void test('a Nexus-canceled public Traitor reveal suppresses CHOAM income without changing the normal battle or payment', () => { const normal = battle(); const canceled: BattleResolutionInput = { ...structuredClone(normal), nexusCanceledTraitorRevealed: true }; const before = structuredClone(canceled); const ordinaryQuote = quoteBattleResolution(normal), canceledQuote = quoteBattleResolution(canceled); assert.equal(ordinaryQuote.result, 'normal'); assert.deepEqual(ordinaryQuote.choamIncome, { owner: 'c', amount: 2 }); assert.equal(canceledQuote.choamIncome, null); assert.deepEqual({ ...canceledQuote, choamIncome: ordinaryQuote.choamIncome }, ordinaryQuote); assert.deepEqual(canceled, before); }); void test('ordinary sole and mutual Traitor calls retain their native income and support rules', () => { for (const mutual of [false, true]) { const input = battle(); input.voters[0].called = true; input.voters[0].traitors = [input.defender.plan.leader!]; if (mutual) { input.voters[1].called = true; input.voters[1].traitors = [input.attacker.plan.leader!]; } const quote = quoteBattleResolution(input); assert.equal(quote.result, mutual ? 'mutualTraitors' : 'traitor'); assert.equal(quote.choamIncome, null); assert.equal(quote.payments.find(p => p.player === 'h')!.ownPayment, mutual ? 2 : 0); assert.equal(quote.payments.find(p => p.player === 'a')!.ownPayment, 2); } }); void test('the private source flag is true or absent and does not mutate a rejected quote', () => { for (const invalid of [false, null, 'true']) { const input = { ...battle(), nexusCanceledTraitorRevealed: invalid } as unknown as BattleResolutionInput; const before = structuredClone(input); assert.throws(() => quoteBattleResolution(input), BattleResolutionQuoteError); assert.deepEqual(input, before); } });