Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhudis committed May 23, 2024
1 parent 0f8585f commit 33c9019
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions server/test/game.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { GuessResult, Progress, State } from '../src/types';
const addPlayer = jest.fn();
const getPlayer = jest.fn();
const updateRoundData = jest.fn();
const updatePlayerRound = jest.fn();
const updateCorrectGuessPoints = jest.fn();
jest.mock('../src/leaderboard', () =>
jest.fn().mockImplementation(() => ({
addPlayer,
getPlayer,
updatePlayerRound,
updateCorrectGuessPoints,
}))
);
jest.mock('../src/data', () => ({
Expand Down Expand Up @@ -70,36 +70,36 @@ describe('guess processing', () => {
getPlayer.mockImplementation(() => ({ progress: Progress.NONE }));
expect(game.processGuess('player1', 'na', 100)).toBe(GuessResult.INCORRECT);
expect(updateRoundData).not.toHaveBeenCalled();
expect(updatePlayerRound).not.toHaveBeenCalled();
expect(updateCorrectGuessPoints).not.toHaveBeenCalled();
});
test("incorrect guess with BOTH returns INCORRECT and doesn't update anything", () => {
getPlayer.mockImplementation(() => ({ progress: Progress.BOTH }));
expect(game.processGuess('player1', 'na', 100)).toBe(GuessResult.INCORRECT);
expect(updateRoundData).not.toHaveBeenCalled();
expect(updatePlayerRound).not.toHaveBeenCalled();
expect(updateCorrectGuessPoints).not.toHaveBeenCalled();
});
test('title guess with NONE returns TITLE and updates title metadata and updates leaderboard to TITLE', () => {
getPlayer.mockImplementation(() => ({ progress: Progress.NONE }));
expect(game.processGuess('player1', 'title1', 100)).toBe(GuessResult.TITLE);
expect(updateRoundData).toHaveBeenCalledWith(expect.anything(), { title: 1 });
expect(updatePlayerRound).toHaveBeenCalledWith(expect.anything(), Progress.TITLE, expect.anything());
expect(updateCorrectGuessPoints).toHaveBeenCalledWith(expect.anything(), Progress.TITLE, expect.anything());
});
test('artist guess with TITLE returns ARTIST and updates artist metadata and updates leaderboard to BOTH', () => {
getPlayer.mockImplementation(() => ({ progress: Progress.TITLE }));
expect(game.processGuess('player1', 'artist1', 100)).toBe(GuessResult.ARTIST);
expect(updateRoundData).toHaveBeenCalledWith(expect.anything(), { artist: 1 });
expect(updatePlayerRound).toHaveBeenCalledWith(expect.anything(), Progress.BOTH, expect.anything());
expect(updateCorrectGuessPoints).toHaveBeenCalledWith(expect.anything(), Progress.BOTH, expect.anything());
});
test('title guess with ARTIST returns TITLE and updates title metadata and updates leaderboard to BOTH', () => {
getPlayer.mockImplementation(() => ({ progress: Progress.ARTIST }));
expect(game.processGuess('player1', 'title1', 101)).toBe(GuessResult.TITLE);
expect(updateRoundData).toHaveBeenCalledWith(expect.anything(), { title: 1 });
expect(updatePlayerRound).toHaveBeenCalledWith(expect.anything(), Progress.BOTH, 101);
expect(updateCorrectGuessPoints).toHaveBeenCalledWith(expect.anything(), Progress.BOTH, 101);
});
test("artist guess with ARTIST returns NONE and doesn't update anything", () => {
getPlayer.mockImplementation(() => ({ progress: Progress.ARTIST }));
expect(game.processGuess('player1', 'artist1', 101)).toBe(GuessResult.INCORRECT);
expect(updateRoundData).not.toHaveBeenCalled();
expect(updatePlayerRound).not.toHaveBeenCalled();
expect(updateCorrectGuessPoints).not.toHaveBeenCalled();
});
});
20 changes: 10 additions & 10 deletions server/test/leaderboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('testing completion points system', () => {
});
});
test('getting the artist sets progress and 1 point', () => {
board.updatePlayerRound(name, Progress.ARTIST, 100);
board.updateCorrectGuessPoints(name, Progress.ARTIST, 100);
expect(board.getPlayer(name)).toEqual({
score: 0,
points_from_current_track: 1,
Expand All @@ -27,7 +27,7 @@ describe('testing completion points system', () => {
});
});
test('getting the artist after the title sets BOTH and 6 points', () => {
board.updatePlayerRound(name, Progress.BOTH, 100);
board.updateCorrectGuessPoints(name, Progress.BOTH, 100);
expect(board.getPlayer(name)).toEqual({
score: 0,
points_from_current_track: 6,
Expand All @@ -37,7 +37,7 @@ describe('testing completion points system', () => {
});
});
test('ending the round resets the status and sets score', () => {
board.endRound();
board.awardCurrentPoints();
expect(board.getPlayer(name)).toEqual({
score: 6,
points_from_current_track: 0,
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('testing completion points system', () => {
expect(board.getActive().size).toBe(2);
});
test("setting complete for one player sets it's fields and none on the other", () => {
board.updatePlayerRound(name1, Progress.BOTH, 100);
board.updateCorrectGuessPoints(name1, Progress.BOTH, 100);
expect(board.getActive().get(name1)).toEqual({
score: 0,
points_from_current_track: 6,
Expand All @@ -90,8 +90,8 @@ describe('testing completion points system', () => {
});
describe('setting complete for the second player before the first player', () => {
beforeAll(() => {
board.updatePlayerRound(name1, Progress.BOTH, 100);
board.updatePlayerRound(name2, Progress.BOTH, 90);
board.updateCorrectGuessPoints(name1, Progress.BOTH, 100);
board.updateCorrectGuessPoints(name2, Progress.BOTH, 90);
});
it("sets the 'first' player to second place and 5 pts", () => {
expect(board.getActive().get(name1)).toEqual({
Expand All @@ -115,10 +115,10 @@ describe('testing completion points system', () => {
test('setting complete for 3rd and 4th player sets place (3rd, none) and points (4, 2)', () => {
board.addPlayer(name3);
board.addPlayer(name4);
board.updatePlayerRound(name1, Progress.BOTH, 100);
board.updatePlayerRound(name2, Progress.BOTH, 100);
board.updatePlayerRound(name3, Progress.BOTH, 1000);
board.updatePlayerRound(name4, Progress.BOTH, 10000);
board.updateCorrectGuessPoints(name1, Progress.BOTH, 100);
board.updateCorrectGuessPoints(name2, Progress.BOTH, 100);
board.updateCorrectGuessPoints(name3, Progress.BOTH, 1000);
board.updateCorrectGuessPoints(name4, Progress.BOTH, 10000);
expect(board.getActive().get(name3)).toEqual({
score: 0,
points_from_current_track: 4,
Expand Down
6 changes: 3 additions & 3 deletions server/test/room.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const enterPlayer = jest.fn();
const getActiveLeaderboard = jest.fn();
const setGameConfig = jest.fn();
const processGuess = jest.fn();
const resetLeaderboard = jest.fn();
const newRound = jest.fn();
const nextTrack = jest.fn();

jest.mock('../src/game', () =>
Expand All @@ -26,7 +26,7 @@ jest.mock('../src/game', () =>
state: State.LOBBY,
setGameConfig,
processGuess,
resetLeaderboard,
newRound,
nextTrack,
endTrack: jest.fn(),
deactivatePlayer: jest.fn(),
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('lobby tests', () => {
});
test('Sets game state to between tracks and resets leaderboard', () => {
expect(room.game.state).toBe(State.BETWEEN_TRACKS);
expect(resetLeaderboard).toBeCalled();
expect(newRound).toBeCalled();
});
test('Sends leaderboard and next track to start in 1 second', () => {
expect(clientMock1.send).toHaveBeenCalledWith(expect.stringContaining('leaderboard'));
Expand Down

0 comments on commit 33c9019

Please sign in to comment.