Skip to content

Commit

Permalink
Merged PR 314: v1.32.1 - Fix an issue where protests in tossup-only p…
Browse files Browse the repository at this point in the history
…ackets would crash MODAQ (#305)

- Fix an issue where protests in tossup-only packets would crash MODAQ
- Bump version to 1.32.1
  • Loading branch information
alopezlago authored Aug 11, 2024
1 parent 562bfc7 commit 940e84e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/state/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 +=
Expand Down
46 changes: 46 additions & 0 deletions tests/ProtestsMatterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});

Expand Down

0 comments on commit 940e84e

Please sign in to comment.