diff --git a/server/test/game.test.ts b/server/test/game.test.ts index 253c0f7..d196530 100644 --- a/server/test/game.test.ts +++ b/server/test/game.test.ts @@ -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', () => ({ @@ -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(); }); }); diff --git a/server/test/leaderboard.test.ts b/server/test/leaderboard.test.ts index f6ada76..029d6a6 100644 --- a/server/test/leaderboard.test.ts +++ b/server/test/leaderboard.test.ts @@ -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, @@ -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, @@ -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, @@ -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, @@ -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({ @@ -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, diff --git a/server/test/room.test.ts b/server/test/room.test.ts index 6e9dccc..b3a9e54 100644 --- a/server/test/room.test.ts +++ b/server/test/room.test.ts @@ -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', () => @@ -26,7 +26,7 @@ jest.mock('../src/game', () => state: State.LOBBY, setGameConfig, processGuess, - resetLeaderboard, + newRound, nextTrack, endTrack: jest.fn(), deactivatePlayer: jest.fn(), @@ -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'));