more integration tests

This commit is contained in:
seavor 2026-04-16 12:40:47 -05:00
parent 4b5f66d497
commit decebc25c7
192 changed files with 3090 additions and 1657 deletions

View file

@ -14,8 +14,16 @@ vi.mock('../../WebClient', () => ({
}));
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
import { useWebClientCleanup } from '../../__mocks__/helpers';
import { WebClient } from '../../WebClient';
import { Data } from '@app/types';
import {
Command_CreateGame_ext,
Command_CreateGameSchema,
Command_JoinGame_ext,
Command_JoinGameSchema,
Command_LeaveRoom_ext,
Command_RoomSay_ext,
} from '@app/generated';
import { createGame } from './createGame';
import { joinGame } from './joinGame';
@ -24,6 +32,8 @@ import { roomSay } from './roomSay';
import { create } from '@bufbuild/protobuf';
import { Mock } from 'vitest';
useWebClientCleanup();
const { invokeOnSuccess } = makeCallbackHelpers(
WebClient.instance.protobuf.sendRoomCommand as Mock,
// sendRoomCommand(roomId, ext, value, options) — options at index 3
@ -36,14 +46,14 @@ const { invokeOnSuccess } = makeCallbackHelpers(
describe('createGame', () => {
it('calls sendRoomCommand with Command_CreateGame', () => {
createGame(5, create(Data.Command_CreateGameSchema, { maxPlayers: 4 }));
createGame(5, create(Command_CreateGameSchema, { maxPlayers: 4 }));
expect(WebClient.instance.protobuf.sendRoomCommand).toHaveBeenCalledWith(
5, Data.Command_CreateGame_ext, expect.objectContaining({ maxPlayers: 4 }), expect.any(Object)
5, Command_CreateGame_ext, expect.objectContaining({ maxPlayers: 4 }), expect.any(Object)
);
});
it('onSuccess calls response.room.gameCreated with roomId', () => {
createGame(5, create(Data.Command_CreateGameSchema, {}));
createGame(5, create(Command_CreateGameSchema, {}));
invokeOnSuccess();
expect(WebClient.instance.response.room.gameCreated).toHaveBeenCalledWith(5);
});
@ -55,14 +65,14 @@ describe('createGame', () => {
describe('joinGame', () => {
it('calls sendRoomCommand with Command_JoinGame', () => {
joinGame(7, create(Data.Command_JoinGameSchema, { gameId: 42, password: '' }));
joinGame(7, create(Command_JoinGameSchema, { gameId: 42, password: '' }));
expect(WebClient.instance.protobuf.sendRoomCommand).toHaveBeenCalledWith(
7, Data.Command_JoinGame_ext, expect.objectContaining({ gameId: 42, password: '' }), expect.any(Object)
7, Command_JoinGame_ext, expect.objectContaining({ gameId: 42, password: '' }), expect.any(Object)
);
});
it('onSuccess calls response.room.joinedGame with roomId and gameId', () => {
joinGame(7, create(Data.Command_JoinGameSchema, { gameId: 42 }));
joinGame(7, create(Command_JoinGameSchema, { gameId: 42 }));
invokeOnSuccess();
expect(WebClient.instance.response.room.joinedGame).toHaveBeenCalledWith(7, 42);
});
@ -76,7 +86,7 @@ describe('leaveRoom', () => {
it('calls sendRoomCommand with Command_LeaveRoom', () => {
leaveRoom(3);
expect(WebClient.instance.protobuf.sendRoomCommand).toHaveBeenCalledWith(
3, Data.Command_LeaveRoom_ext, expect.any(Object), expect.any(Object)
3, Command_LeaveRoom_ext, expect.any(Object), expect.any(Object)
);
});
@ -96,7 +106,7 @@ describe('roomSay', () => {
roomSay(2, ' hello ');
expect(WebClient.instance.protobuf.sendRoomCommand).toHaveBeenCalledWith(
2,
Data.Command_RoomSay_ext,
Command_RoomSay_ext,
expect.objectContaining({ message: 'hello' })
);
});