cleanup and unit tests (#4434)

* put socket.updateHistory behind SessionCommand

* rename /websocket files from .tsx to .ts

* add unit tests to websocket commands

* complete unit tests for webClient commands

* secure wss

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto 2021-10-17 15:15:09 -05:00 committed by GitHub
parent e9ba195d7d
commit f75ff2a7c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 611 additions and 48 deletions

View file

@ -0,0 +1,51 @@
import { store, RoomsDispatch, RoomsSelectors } from "store";
import { Game, Message, Room, User } from 'types';
import NormalizeService from "../utils/NormalizeService";
export class RoomPersistence {
static clearStore() {
RoomsDispatch.clearStore();
}
static joinRoom(roomInfo: Room) {
NormalizeService.normalizeRoomInfo(roomInfo);
RoomsDispatch.joinRoom(roomInfo);
}
static leaveRoom(roomId: number) {
RoomsDispatch.leaveRoom(roomId);
}
static updateRooms(rooms: Room[]) {
RoomsDispatch.updateRooms(rooms);
}
static updateGames(roomId: number, gameList: Game[]) {
const game = gameList[0];
if (!game.gameType) {
const room = RoomsSelectors.getRoom(store.getState(), roomId);
if (room) {
const { gametypeMap } = room;
NormalizeService.normalizeGameObject(game, gametypeMap);
}
}
RoomsDispatch.updateGames(roomId, gameList);
}
static addMessage(roomId: number, message: Message) {
NormalizeService.normalizeUserMessage(message);
RoomsDispatch.addMessage(roomId, message);
}
static userJoined(roomId: number, user: User) {
RoomsDispatch.userJoined(roomId, user);
}
static userLeft(roomId: number, name: string) {
RoomsDispatch.userLeft(roomId, name);
}
}