Skip to content

Commit

Permalink
some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Teun van Dalen committed Nov 30, 2023
1 parent a47247d commit 113a0fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions server/domain/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type Vote = {
captionID: number;
}

const POINTS_PER_VOTE = 100;

export class Game {

gamePhase: Phase;
Expand All @@ -28,6 +26,7 @@ export class Game {
votes: Map<number, Vote[]>;
votingRound: number;
score: Map<string, number>;
POINTS_PER_VOTE = 100;

constructor(playerIDs: Set<string>, initialScores?: Map<string, number>) {
this.gamePhase = Phase.PHOTO_UPLOAD;
Expand Down Expand Up @@ -188,7 +187,7 @@ export class Game {
addPoint(playerID: string) {
if (this.score.has(playerID)) {
let currentValue = this.score.get(playerID)!;
this.score.set(playerID, currentValue + POINTS_PER_VOTE);
this.score.set(playerID, currentValue + this.POINTS_PER_VOTE);
}
}

Expand Down
20 changes: 10 additions & 10 deletions server/domain/tests/game.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ test('game goes to voting if every photo has a caption of all players', () => {
expect(game.getCurrentPhase()).toBe(Phase.VOTING);
})

// test('Caption has 2 votes when 2 people voted on it.', () => {
// const game = new Game(players);
test('Caption has the score of 2 votes when 2 people voted on it.', () => {
const game = new Game(players);

// setGameOnCaptionPhase(game);
// addCaptionsAndGoToVotePhase(game);
setGameOnCaptionPhase(game);
addCaptionsAndGoToVotePhase(game);

// const captionID = 10;
// game.addVote(player1, captionID);
// game.addVote(player2, captionID);
const captionID = 10; //Belongs to player 4
game.addVote(player1, captionID);
game.addVote(player2, captionID);

// const Caption10 = game.captions[captionID];
// expect(Caption10.votedBy).toStrictEqual([player1, player2]);
// })
const score_player4 = game.score.get(player4);
expect(score_player4).toBe(game.POINTS_PER_VOTE * 2);
})

test('Throw error when vote on your own caption. (Frontend should prohibit this)', () => {
const game = new Game(players);
Expand Down

0 comments on commit 113a0fc

Please sign in to comment.