import assert from 'node:assert/strict'; import test from 'node:test'; import { parseKaramaAtreidesSpecialSource as parse, windowCardNativeEffect, windowCardOpportunity, type WindowCardGame } from '../game/window-card-play'; const source = (): WindowCardGame => ({ status: 'playing', advanced: true, phase: 6, turn: 2, shieldWallDestroyed: false, players: [{ id: 'a', faction: 'atreides', specialKaramaUsed: false }, { id: 'h', faction: 'harkonnen' }], battle: { event: 'battle:1', territory: 'carthag', revealed: false } }); const event = JSON.stringify(['karamaAtreidesSpecial', 2, 'a', 'battle:1', 'carthag']); void test('Atreides special source is public and bound to the original unrevealed battle', () => { const game = source(), before = structuredClone(game); assert.deepEqual(windowCardOpportunity(game, 'karamaAtreidesSpecial'), { effect: 'karamaAtreidesSpecial', source: event, turn: 2 }); assert.deepEqual(parse(event), { turn: 2, owner: 'a', battle: 'battle:1', territory: 'carthag' }); assert.equal(windowCardNativeEffect('karamaAtreidesSpecial'), 'karama'); assert.equal(windowCardOpportunity({ ...game, response: { kind: 'voice' }, decision: { kind: 'other' } }, 'karamaAtreidesSpecial')?.source, event); assert.deepEqual(game, before); }); void test('Atreides special source rejects changed battle, use, timing and malformed tuples', () => { const game = source(); for (const changes of [{ status: 'lobby' }, { advanced: false }, { phase: 3 }, { turn: 0 }, { battle: null }, { battle: { event: 'battle:1', territory: 'carthag', revealed: true } }, { battle: { event: '', territory: 'carthag', revealed: false } }, { players: [{ id: 'a', faction: 'atreides', specialKaramaUsed: true }] }, { players: [{ id: 'a', faction: 'atreides' }, { id: 'b', faction: 'atreides' }] }]) assert.equal(windowCardOpportunity({ ...game, ...changes } as WindowCardGame, 'karamaAtreidesSpecial'), null); for (const value of ['', '[]', '["karamaAtreidesSpecial", 2,"a","battle:1","carthag"]', JSON.stringify(['karamaAtreidesSpecial', 0, 'a', 'battle:1', 'carthag']), JSON.stringify(['karamaAtreidesSpecial', 2, 'a', '', 'carthag'])]) assert.equal(parse(value), null); assert.equal(windowCardOpportunity({ ...game, battle: { event: 'battle:2', territory: 'carthag', revealed: false } }, 'karamaAtreidesSpecial', event), null); });