From 940e84ee68c1cf4f576ce5c9504b10a0e19ed4cb Mon Sep 17 00:00:00 2001 From: Alejandro Date: Sun, 11 Aug 2024 00:17:42 -0700 Subject: [PATCH] Merged PR 314: v1.32.1 - Fix an issue where protests in tossup-only packets would crash MODAQ (#305) - Fix an issue where protests in tossup-only packets would crash MODAQ - Bump version to 1.32.1 --- package.json | 2 +- src/state/GameState.ts | 9 +++---- tests/ProtestsMatterTests.ts | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1ccb53d..3e8b9f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "modaq", - "version": "1.32.0", + "version": "1.32.1", "description": "Quiz Bowl Reader using TypeScript, React, and MobX", "repository": { "type": "git", diff --git a/src/state/GameState.ts b/src/state/GameState.ts index cbfb5fe..3b04af6 100644 --- a/src/state/GameState.ts +++ b/src/state/GameState.ts @@ -238,10 +238,11 @@ export class GameState { } const bonusIndex: number = this.getBonusIndex(i); - const potentialBonusPoints = this.packet.bonuses[bonusIndex].parts.reduce( - (previous, current) => current.value + previous, - 0 - ); + const potentialBonusPoints = + this.packet.bonuses[bonusIndex]?.parts.reduce( + (previous, current) => current.value + previous, + 0 + ) ?? 0; // Need to remove the neg (subtract) and add what the correct value would be swings[tossupTeamIndex].for += diff --git a/tests/ProtestsMatterTests.ts b/tests/ProtestsMatterTests.ts index 546dd1e..d0f90c2 100644 --- a/tests/ProtestsMatterTests.ts +++ b/tests/ProtestsMatterTests.ts @@ -301,6 +301,52 @@ describe("GameStateTests", () => { ); expect(game.protestsMatter).to.be.true; }); + it("Tossup-only game, protest matters", () => { + const game: GameState = new GameState(); + game.addNewPlayers(players); + const packet: PacketState = new PacketState(); + packet.setTossups(defaultPacket.tossups); + game.loadPacket(packet); + + game.setGameFormat({ ...game.gameFormat, negValue: -5 }); + game.cycles[0].addWrongBuzz( + { player: firstTeamPlayer, points: 0, position: 2, isLastWord: false }, + 0, + game.gameFormat + ); + game.cycles[0].addTossupProtest(firstTeamPlayer.teamName, 0, 2, "My answer", "My reason"); + expect(game.protestsMatter).to.be.true; + }); + it("Tossup-only game, protest doesn't matter", () => { + const game: GameState = new GameState(); + game.addNewPlayers(players); + const packet: PacketState = new PacketState(); + packet.setTossups(defaultPacket.tossups); + game.loadPacket(packet); + + game.setGameFormat({ ...game.gameFormat, negValue: -5 }); + game.cycles[0].addWrongBuzz( + { player: firstTeamPlayer, points: 0, position: 2, isLastWord: false }, + 0, + game.gameFormat + ); + game.cycles[0].addTossupProtest(firstTeamPlayer.teamName, 0, 2, "My answer", "My reason"); + + game.cycles[1].addCorrectBuzz( + { + player: firstTeamPlayer, + points: 10, + position: 1, + isLastWord: false, + }, + 1, + game.gameFormat, + 0, + 0 + ); + + expect(game.protestsMatter).to.be.false; + }); }); });