diff --git a/app/javascript/Domain/ImperialGameCoordinator.js b/app/javascript/Domain/ImperialGameCoordinator.js index 1baee4d0..7217775e 100644 --- a/app/javascript/Domain/ImperialGameCoordinator.js +++ b/app/javascript/Domain/ImperialGameCoordinator.js @@ -719,9 +719,7 @@ export default class ImperialGameCoordinator { this.endOfInvestorTurn(player); } - // If there is one available action, it is the skip action and doesn't - // count as a real action. - if (this.availableActions.size <= 1) { + if ([...this.availableActions].every((action) => action.type !== 'bondPurchase')) { this.annotatedLog.push( Action.playerAutoSkipsBondPurchase({ player: this.currentPlayerName, @@ -1983,6 +1981,30 @@ export default class ImperialGameCoordinator { for (const bondPurchase of this.bondPurchasesFromAllNations()) { this.availableActions.add(bondPurchase); } + + if ([...this.availableActions].every((action) => action.type !== 'bondPurchase')) { + this.annotatedLog.push( + Action.playerAutoSkipsBondPurchase({ + player: this.currentPlayerName, + bondNation: this.currentNation, + }), + ); + this.currentNation = this.nextNation(this.currentNation); + this.currentPlayerName = this.nations.get( + this.currentNation, + ).controller; + this.advanceInvestorCard(); + + for (const availableAction of this.availableActions) { + if (availableAction.type === 'skipBondPurchase') { + this.log.push(availableAction); + this.availableActions.delete(availableAction); + } + } + for (const rondelAction of this.availableRondelActions(this.currentNation)) { + this.availableActions.add(rondelAction); + } + } } } diff --git a/app/javascript/Domain/Tests/ImperialGameCoordinator.test.js b/app/javascript/Domain/Tests/ImperialGameCoordinator.test.js index 303cd596..0862e2de 100644 --- a/app/javascript/Domain/Tests/ImperialGameCoordinator.test.js +++ b/app/javascript/Domain/Tests/ImperialGameCoordinator.test.js @@ -4625,6 +4625,18 @@ describe('imperial', () => { expect(game.currentNation).toEqual(Nation.FR); expect(game.currentPlayerName).toEqual('player1'); }); + + test('when a player does not have enough money to buy a bond, skip their invest turn', () => { + const game = newGame(); + game.players.player2.cash = 0; + game.players.player2.bonds.clear(); + + game.tick(Action.rondel({ nation: Nation.AH, cost: 0, slot: 'investor' })); + + // This is an awkward way to assert that we're not in a bond purchase round + expect([...game.availableActions].every((action) => action.type !== 'skipBondPurchase')).toEqual(true); + expect(game.currentPlayerName).toEqual('player2'); + }); }); describe('undo', () => {