mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 00:54:53 -07:00
Webatrice websocket refactor (#4435)
* add unit tests for websocket events * add unit tests for KeepAliveService, clean up keepAlive termination flow * put keepAlive command in protobuf service and expose thru webClient * secure wss * rename files tsx to ts * add localhost support for ws/wss connection Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
parent
f75ff2a7c8
commit
586f23cfa9
15 changed files with 568 additions and 77 deletions
64
webclient/src/websocket/events/RoomEvents.spec.ts
Normal file
64
webclient/src/websocket/events/RoomEvents.spec.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { Message } from 'types';
|
||||
|
||||
import {
|
||||
RoomEvents,
|
||||
RoomEvent,
|
||||
JoinRoomData,
|
||||
LeaveRoomData,
|
||||
ListGamesData,
|
||||
} from './RoomEvents';
|
||||
import { RoomPersistence } from '../persistence/RoomPersistence';
|
||||
|
||||
describe('RoomEvents', () => {
|
||||
it('.Event_JoinRoom.ext should call RoomPersistence.userJoined', () => {
|
||||
spyOn(RoomPersistence, 'userJoined');
|
||||
const data: JoinRoomData = { userInfo: {} as any };
|
||||
const event: RoomEvent = { roomEvent: { roomId: 1 } };
|
||||
|
||||
RoomEvents['.Event_JoinRoom.ext'](data, event);
|
||||
|
||||
expect(RoomPersistence.userJoined).toHaveBeenCalledWith(
|
||||
event.roomEvent.roomId,
|
||||
data.userInfo
|
||||
);
|
||||
});
|
||||
|
||||
it('.Event_LeaveRoom.ext should call RoomPersistence.userLeft', () => {
|
||||
spyOn(RoomPersistence, 'userLeft');
|
||||
const data: LeaveRoomData = { name: '' };
|
||||
const event: RoomEvent = { roomEvent: { roomId: 1 } };
|
||||
|
||||
RoomEvents['.Event_LeaveRoom.ext'](data, event);
|
||||
|
||||
expect(RoomPersistence.userLeft).toHaveBeenCalledWith(
|
||||
event.roomEvent.roomId,
|
||||
data.name
|
||||
);
|
||||
});
|
||||
|
||||
it('.Event_ListGames.ext should call RoomPersistence.updateGames', () => {
|
||||
spyOn(RoomPersistence, 'updateGames');
|
||||
const data: ListGamesData = { gameList: [] };
|
||||
const event: RoomEvent = { roomEvent: { roomId: 1 } };
|
||||
|
||||
RoomEvents['.Event_ListGames.ext'](data, event);
|
||||
|
||||
expect(RoomPersistence.updateGames).toHaveBeenCalledWith(
|
||||
event.roomEvent.roomId,
|
||||
data.gameList
|
||||
);
|
||||
});
|
||||
|
||||
it('.Event_RoomSay.ext should call RoomPersistence.addMessage', () => {
|
||||
spyOn(RoomPersistence, 'addMessage');
|
||||
const data: Message = {} as any;
|
||||
const event: RoomEvent = { roomEvent: { roomId: 1 } };
|
||||
|
||||
RoomEvents['.Event_RoomSay.ext'](data, event);
|
||||
|
||||
expect(RoomPersistence.addMessage).toHaveBeenCalledWith(
|
||||
event.roomEvent.roomId,
|
||||
data
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue