import assert from 'node:assert/strict'; import test from 'node:test'; import { applyAction, viewGame, type Action } from '../game/engine'; import { createTruthTurnPowerFixture, truthTurnPowerInventory, truthTurnPowerPlayer, } from './fixture-truth-turn-power'; /** Public Basic setup and a paid shipment produce the native Arrakeen battle; * Emperor buys its original Karama in an ordinary auction. The source fixture * selects unopened draw order but does not assign a battle, hand or purse. */ void test('a Basic combatant may bribe while Voice awaits its native Karama response', () => { const f = createTruthTurnPowerFixture({power: 'voice', remote: false}); let game = applyAction(f.game, f.bg, {type: 'voice', kind: 'shield', must: false}); assert.equal(game.response?.kind, 'voice'); assert.ok(game.battle && [game.battle.attacker, game.battle.defender].includes(f.atreides)); assert.ok(truthTurnPowerPlayer(game, f.emperor).hand.some(card => card.id === f.karama)); const payer = truthTurnPowerPlayer(game, f.atreides); const recipient = truthTurnPowerPlayer(game, f.emperor); assert.ok(payer.spice > 0); assert.notEqual(payer.ally, recipient.id); const options = viewGame(game, payer.id).bribeOptions; assert.equal(options.blocked, null); const limit = options.targets.find(target => target.id === recipient.id)?.maximum; assert.ok(limit && limit >= 1); const illegal: Action = {type: 'bribe', target: recipient.id, amount: limit + 1}; const unchanged = structuredClone(game); assert.throws(() => applyAction(game, payer.id, illegal)); assert.deepEqual(game, unchanged, 'An over-limit payment cannot alter the declared Voice or response'); const originalBattle = structuredClone(game.battle), originalResponse = structuredClone(game.response); const originalCards = truthTurnPowerInventory(game); const amount = 1, balance = payer.spice, income = recipient.bribes; const paid = applyAction(game, payer.id, {type: 'bribe', target: recipient.id, amount}); assert.deepEqual(paid.response, originalResponse); assert.deepEqual(paid.battle, originalBattle); assert.equal(truthTurnPowerPlayer(paid, payer.id).spice, balance - amount); assert.equal(truthTurnPowerPlayer(paid, recipient.id).spice, recipient.spice); assert.equal(truthTurnPowerPlayer(paid, recipient.id).bribes, income + amount); assert.deepEqual(truthTurnPowerInventory(paid), originalCards); // The same physical Karama must cancel the original declared Voice once; // the payment neither spends that card nor grants the recipient its escrow. const cancel: Action = {type: 'card', card: f.karama, mode: 'cancel'}; const expected = applyAction(game, f.emperor, cancel); game = applyAction(paid, f.emperor, cancel); assert.equal(game.battle?.voice, undefined); assert.deepEqual(game.battle, expected.battle); assert.deepEqual(game.response, expected.response); assert.equal(game.discard.filter(card => card.id === f.karama).length, 1); assert.equal(truthTurnPowerPlayer(game, recipient.id).bribes, income + amount); assert.deepEqual(truthTurnPowerInventory(game), originalCards); });