60 lines
3.4 KiB
TypeScript
60 lines
3.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {applyAction, viewGame, type Game} from '../game/engine';
|
|
import {createRicheseBetrayalFixture} from './fixture-richese-betrayal';
|
|
|
|
const player=(game:Game,id:string)=>{const p=game.players.find(row=>row.id===id);assert.ok(p);return p;};
|
|
function allow(game:Game) {
|
|
for(let n=0;game.response&&n<20;n++) {
|
|
const actor=game.players.find(p=>!game.response!.passed.includes(p.id));assert.ok(actor);
|
|
game=applyAction(game,actor.id,{type:'passResponse'});
|
|
}
|
|
return game;
|
|
}
|
|
for(const diverted of [false,true]) void test(`Basic Emperor gift resumes a ${diverted?'diverted':'ordinary'} Nexus cache sale`,()=>{
|
|
const f=createRicheseBetrayalFixture('sale',{source:'cache',advanced:false,allyPayment:2,emperorAlly:true});
|
|
const before=structuredClone(f.game),emperor=f.ally!;
|
|
assert.equal(player(before,emperor).faction,'emperor');
|
|
let game=before;
|
|
if(diverted)game=applyAction(game,f.holder,{type:'richeseBetrayalUse',event:f.event});
|
|
else for(const id of before.pendingRicheseBetrayal!.receipt.required)
|
|
game=applyAction(game,id,{type:'richeseBetrayalPass',event:f.event});
|
|
const gift=viewGame(game,emperor).emperorAuctionGift;assert.ok(gift);
|
|
assert.equal(gift.recipient,f.buyer);
|
|
assert.equal(game.pendingEmperorAuctionGift!.bank===true,diverted);
|
|
const wallet=player(game,emperor).spice,buyer=player(game,f.buyer).spice,seller=player(game,f.target).spice;
|
|
game=applyAction(game,emperor,{type:'emperorGift',amount:1});game=allow(game);
|
|
game=applyAction(game,emperor,{type:'emperorAuctionGiftContinue',event:gift.event});
|
|
game=allow(game);
|
|
assert.equal(player(game,emperor).spice,wallet-1);
|
|
assert.equal(player(game,f.buyer).spice,buyer+1-4);
|
|
assert.equal(player(game,f.target).spice,seller+(diverted?0:6));
|
|
assert.equal(player(game,f.buyer).hand.filter(card=>card.id===f.card).length,1);
|
|
assert.equal(game.richeseBetrayal!.completed[0].stage,diverted?'used':'passed');
|
|
});
|
|
|
|
void test('Basic Emperor gift follows a passed Nexus veto for an allied Richese self-purchase',()=>{
|
|
const f=createRicheseBetrayalFixture('purchase',{source:'cache',advanced:false,emperorAlly:true});
|
|
let game=f.game;
|
|
for(const id of f.game.pendingRicheseBetrayal!.receipt.required)
|
|
game=applyAction(game,id,{type:'richeseBetrayalPass',event:f.event});
|
|
const gift=viewGame(game,f.ally!).emperorAuctionGift;assert.ok(gift);
|
|
assert.equal(gift.recipient,f.target);
|
|
const buyer=player(game,f.target).spice;
|
|
game=applyAction(game,f.ally!,{type:'emperorGift',amount:1});game=allow(game);
|
|
game=applyAction(game,f.ally!,{type:'emperorAuctionGiftContinue',event:gift.event});game=allow(game);
|
|
assert.equal(player(game,f.target).spice,buyer+1-6);
|
|
assert.equal(player(game,f.target).hand.filter(card=>card.id===f.card).length,1);
|
|
assert.equal(game.richeseBetrayal!.completed[0].stage,'passed');
|
|
});
|
|
|
|
void test('A Nexus veto of an allied Richese self-purchase does not open a payment gift',()=>{
|
|
const f=createRicheseBetrayalFixture('purchase',{source:'cache',advanced:false,emperorAlly:true});
|
|
const before=player(f.game,f.ally!).spice;
|
|
const game=applyAction(f.game,f.holder,{type:'richeseBetrayalUse',event:f.event});
|
|
assert.equal(game.pendingEmperorAuctionGift??null,null);
|
|
assert.equal(player(game,f.ally!).spice,before);
|
|
assert.equal(game.discard.filter(card=>card.id===f.card).length,1);
|
|
assert.equal(player(game,f.target).hand.some(card=>card.id===f.card),false);
|
|
});
|