fix tests, add golden command (#4486)

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto 2021-11-26 15:55:12 -06:00 committed by GitHub
parent 6ce346af4a
commit 6dc9f004ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 481 additions and 272 deletions

View file

@ -6,6 +6,9 @@ module.exports = {
"@typescript-eslint" "@typescript-eslint"
], ],
"ignorePatterns": ["node_modules/*", "build/*", "public/pb/*"], "ignorePatterns": ["node_modules/*", "build/*", "public/pb/*"],
"env": {
"jest": true
},
"rules": { "rules": {
"array-bracket-spacing": ["error", "never"], "array-bracket-spacing": ["error", "never"],
"arrow-spacing": ["error", {"before": true, "after": true}], "arrow-spacing": ["error", {"before": true, "after": true}],

File diff suppressed because it is too large Load diff

View file

@ -33,10 +33,12 @@
"postinstall:default": "./copy_shared_files.sh", "postinstall:default": "./copy_shared_files.sh",
"start": "cross-env ESLINT_NO_DEV_ERRORS=true react-scripts start", "start": "cross-env ESLINT_NO_DEV_ERRORS=true react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "cross-env CI=true react-scripts test",
"test:watch": "react-scripts test",
"eject": "react-scripts eject", "eject": "react-scripts eject",
"lint": "eslint \"./**/*.{ts,tsx}\"", "lint": "eslint \"./**/*.{ts,tsx}\"",
"lint:fix": "eslint \"./**/*.{ts,tsx}\" --fix" "lint:fix": "eslint \"./**/*.{ts,tsx}\" --fix",
"golden": "npm run lint && npm run test"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "react-app" "extends": "react-app"

View file

@ -8,11 +8,15 @@ describe('RoomCommands', () => {
let sendRoomCommandSpy; let sendRoomCommandSpy;
beforeEach(() => { beforeEach(() => {
sendRoomCommandSpy = spyOn(webClient.protobuf, 'sendRoomCommand'); sendRoomCommandSpy = jest.spyOn(webClient.protobuf, 'sendRoomCommand').mockImplementation(() => {});
webClient.protobuf.controller.RoomCommand = { create: args => args }; webClient.protobuf.controller.RoomCommand = { create: args => args };
}); });
afterEach(() => {
jest.restoreAllMocks();
});
describe('roomSay', () => { describe('roomSay', () => {
beforeEach(() => { beforeEach(() => {
webClient.protobuf.controller.Command_RoomSay = { create: args => args }; webClient.protobuf.controller.Command_RoomSay = { create: args => args };
@ -50,18 +54,18 @@ describe('RoomCommands', () => {
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith( expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(
roomId, roomId,
{ '.Command_LeaveRoom.ext': {} }, { '.Command_LeaveRoom.ext': {} },
jasmine.any(Function) expect.any(Function)
); );
}); });
it('should call RoomPersistence.leaveRoom if RespOk', () => { it('should call RoomPersistence.leaveRoom if RespOk', () => {
const RespOk = 'ok'; const RespOk = 'ok';
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } }; webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
sendRoomCommandSpy.and.callFake((_, __, callback) => { sendRoomCommandSpy.mockImplementation((_, __, callback) => {
callback({ responseCode: RespOk }) callback({ responseCode: RespOk })
}); });
spyOn(RoomPersistence, 'leaveRoom'); jest.spyOn(RoomPersistence, 'leaveRoom').mockImplementation(() => {});
RoomCommands.leaveRoom(roomId); RoomCommands.leaveRoom(roomId);

View file

@ -1,34 +1,37 @@
import { StatusEnum } from 'types'; import { StatusEnum, WebSocketConnectReason } from 'types';
import { SessionCommands } from './SessionCommands'; import { SessionCommands } from './SessionCommands';
import { RoomPersistence, SessionPersistence } from '../persistence'; import { RoomPersistence, SessionPersistence } from '../persistence';
import webClient from '../WebClient'; import webClient from '../WebClient';
import { WebSocketConnectReason } from '../services/WebSocketService';
import { AccountActivationParams, ServerRegisterParams } from '../../store'; import { AccountActivationParams, ServerRegisterParams } from '../../store';
describe('SessionCommands', () => { describe('SessionCommands', () => {
const roomId = 1; const roomId = 1;
let sendModeratorCommandSpy; let sendModeratorCommandSpy;
let sendSessionCommandSpy; let sendSessionCommandSpy;
let MockSessionCommands;
beforeEach(() => { beforeEach(() => {
spyOn(SessionCommands, 'updateStatus').and.callThrough(); jest.spyOn(SessionCommands, 'updateStatus');
spyOn(webClient, 'updateStatus'); jest.spyOn(webClient, 'updateStatus').mockImplementation(() => {});
spyOn(console, 'error'); jest.spyOn(console, 'error').mockImplementation(() => {});
sendModeratorCommandSpy = spyOn(webClient.protobuf, 'sendModeratorCommand'); sendModeratorCommandSpy = jest.spyOn(webClient.protobuf, 'sendModeratorCommand').mockImplementation(() => {});
sendSessionCommandSpy = spyOn(webClient.protobuf, 'sendSessionCommand'); sendSessionCommandSpy = jest.spyOn(webClient.protobuf, 'sendSessionCommand').mockImplementation(() => {});
webClient.protobuf.controller.ModeratorCommand = { create: args => args }; webClient.protobuf.controller.ModeratorCommand = { create: args => args };
webClient.protobuf.controller.SessionCommand = { create: args => args }; webClient.protobuf.controller.SessionCommand = { create: args => args };
}); });
afterEach(() => {
jest.restoreAllMocks();
});
describe('connect', () => { describe('connect', () => {
let options; let options;
beforeEach(() => { beforeEach(() => {
spyOn(webClient, 'connect'); jest.spyOn(webClient, 'connect').mockImplementation(() => {});
options = { options = {
host: 'host', host: 'host',
port: 'port', port: 'port',
@ -69,13 +72,10 @@ describe('SessionCommands', () => {
describe('disconnect', () => { describe('disconnect', () => {
it('should call SessionCommands.updateStatus and webClient.disconnect', () => { it('should call SessionCommands.updateStatus and webClient.disconnect', () => {
spyOn(webClient, 'disconnect'); jest.spyOn(webClient, 'disconnect');
SessionCommands.disconnect(); SessionCommands.disconnect();
expect(SessionCommands.updateStatus).toHaveBeenCalled();
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTING, 'Disconnecting...');
expect(webClient.disconnect).toHaveBeenCalled(); expect(webClient.disconnect).toHaveBeenCalled();
}); });
}); });
@ -83,8 +83,8 @@ describe('SessionCommands', () => {
describe('login', () => { describe('login', () => {
beforeEach(() => { beforeEach(() => {
webClient.protobuf.controller.Command_Login = { create: args => args }; webClient.protobuf.controller.Command_Login = { create: args => args };
webClient.options.user = 'user'; webClient.options.userName = 'user';
webClient.options.pass = 'pass'; webClient.options.password = 'pass';
}); });
it('should call protobuf controller methods and sendCommand', () => { it('should call protobuf controller methods and sendCommand', () => {
@ -94,11 +94,11 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_Login.ext': { '.Command_Login.ext': {
...webClient.clientConfig, ...webClient.clientConfig,
userName: webClient.options.user, userName: webClient.options.userName,
password: webClient.options.pass, password: webClient.options.password,
clientid: jasmine.any(String) clientid: expect.any(String)
} }
}, jasmine.any(Function)); }, expect.any(Function));
}); });
describe('response', () => { describe('response', () => {
@ -118,15 +118,15 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } }; webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response)); sendSessionCommandSpy.mockImplementation((_, callback) => callback(response));
}); });
it('RespOk should update user/state and list users/games', () => { it('RespOk should update user/state and list users/games', () => {
spyOn(SessionPersistence, 'updateBuddyList'); jest.spyOn(SessionPersistence, 'updateBuddyList').mockImplementation(() => {});
spyOn(SessionPersistence, 'updateIgnoreList'); jest.spyOn(SessionPersistence, 'updateIgnoreList').mockImplementation(() => {});
spyOn(SessionPersistence, 'updateUser'); jest.spyOn(SessionPersistence, 'updateUser').mockImplementation(() => {});
spyOn(SessionCommands, 'listUsers'); jest.spyOn(SessionCommands, 'listUsers').mockImplementation(() => {});
spyOn(SessionCommands, 'listRooms'); jest.spyOn(SessionCommands, 'listRooms').mockImplementation(() => {});
SessionCommands.login(); SessionCommands.login();
@ -270,14 +270,14 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_Register.ext': { '.Command_Register.ext': {
...webClient.clientConfig, ...webClient.clientConfig,
userName: options.user, userName: options.userName,
password: options.pass, password: options.password,
email: options.email, email: options.email,
country: options.country, country: options.country,
realName: options.realName, realName: options.realName,
clientid: jasmine.any(String) clientid: expect.any(String)
} }
}, jasmine.any(Function)); }, expect.any(Function));
}); });
describe('response', () => { describe('response', () => {
@ -296,12 +296,12 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response = { ResponseCode: { RespRegistrationAccepted } }; webClient.protobuf.controller.Response = { ResponseCode: { RespRegistrationAccepted } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response)); sendSessionCommandSpy.mockImplementation((_, callback) => callback(response));
}) })
it('should login user if registration accepted without email verification', () => { it('should login user if registration accepted without email verification', () => {
spyOn(SessionCommands, 'login'); jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
spyOn(SessionPersistence, 'accountAwaitingActivation'); jest.spyOn(SessionPersistence, 'accountAwaitingActivation').mockImplementation(() => {});
SessionCommands.register(); SessionCommands.register();
@ -315,8 +315,8 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation = webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation =
RespRegistrationAcceptedNeedsActivation; RespRegistrationAcceptedNeedsActivation;
spyOn(SessionCommands, 'login'); jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
spyOn(SessionPersistence, 'accountAwaitingActivation'); jest.spyOn(SessionPersistence, 'accountAwaitingActivation').mockImplementation(() => {});
SessionCommands.register(); SessionCommands.register();
@ -355,11 +355,11 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_Activate.ext': { '.Command_Activate.ext': {
...webClient.clientConfig, ...webClient.clientConfig,
userName: options.user, userName: options.userName,
token: options.activationCode, token: options.token,
clientid: jasmine.any(String) clientid: expect.any(String)
} }
}, jasmine.any(Function)); }, expect.any(Function));
}); });
describe('response', () => { describe('response', () => {
@ -377,9 +377,9 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response = { ResponseCode: { RespActivationAccepted } }; webClient.protobuf.controller.Response = { ResponseCode: { RespActivationAccepted } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response)); sendSessionCommandSpy.mockImplementation((_, callback) => callback(response));
spyOn(SessionCommands, 'login'); jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
spyOn(SessionPersistence, 'accountActivationFailed'); jest.spyOn(SessionPersistence, 'accountActivationFailed').mockImplementation(() => {});
}); });
it('should activate user and login if correct activation token used', () => { it('should activate user and login if correct activation token used', () => {
@ -413,7 +413,7 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled(); expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_ListUsers.ext': {} '.Command_ListUsers.ext': {}
}, jasmine.any(Function)); }, expect.any(Function));
}); });
it('should call SessionPersistence.updateUsers if RespOk', () => { it('should call SessionPersistence.updateUsers if RespOk', () => {
@ -425,8 +425,8 @@ describe('SessionCommands', () => {
}; };
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } }; webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response)); sendSessionCommandSpy.mockImplementation((_, callback) => callback(response));
spyOn(SessionPersistence, 'updateUsers'); jest.spyOn(SessionPersistence, 'updateUsers').mockImplementation(() => {});
SessionCommands.listUsers(); SessionCommands.listUsers();
@ -460,7 +460,7 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled(); expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_JoinRoom.ext': { roomId } '.Command_JoinRoom.ext': { roomId }
}, jasmine.any(Function)); }, expect.any(Function));
}); });
describe('response', () => { describe('response', () => {
@ -476,11 +476,11 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } }; webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
sendSessionCommandSpy.and.callFake((_, callback) => callback(response)); sendSessionCommandSpy.mockImplementation((_, callback) => callback(response));
}); });
it('RespOk should call RoomPersistence.joinRoom', () => { it('RespOk should call RoomPersistence.joinRoom', () => {
spyOn(RoomPersistence, 'joinRoom'); jest.spyOn(RoomPersistence, 'joinRoom').mockImplementation(() => {});
SessionCommands.joinRoom(roomId); SessionCommands.joinRoom(roomId);
@ -534,7 +534,7 @@ describe('SessionCommands', () => {
describe('addToBuddyList', () => { describe('addToBuddyList', () => {
it('should call SessionCommands.addToList', () => { it('should call SessionCommands.addToList', () => {
spyOn(SessionCommands, 'addToList'); jest.spyOn(SessionCommands, 'addToList').mockImplementation(() => {});
const userName = 'userName'; const userName = 'userName';
SessionCommands.addToBuddyList(userName); SessionCommands.addToBuddyList(userName);
@ -545,7 +545,7 @@ describe('SessionCommands', () => {
describe('removeFromBuddyList', () => { describe('removeFromBuddyList', () => {
it('should call SessionCommands.removeFromList', () => { it('should call SessionCommands.removeFromList', () => {
spyOn(SessionCommands, 'removeFromList'); jest.spyOn(SessionCommands, 'removeFromList').mockImplementation(() => {});
const userName = 'userName'; const userName = 'userName';
SessionCommands.removeFromBuddyList(userName); SessionCommands.removeFromBuddyList(userName);
@ -556,7 +556,7 @@ describe('SessionCommands', () => {
describe('addToIgnoreList', () => { describe('addToIgnoreList', () => {
it('should call SessionCommands.addToList', () => { it('should call SessionCommands.addToList', () => {
spyOn(SessionCommands, 'addToList'); jest.spyOn(SessionCommands, 'addToList').mockImplementation(() => {});
const userName = 'userName'; const userName = 'userName';
SessionCommands.addToIgnoreList(userName); SessionCommands.addToIgnoreList(userName);
@ -567,7 +567,7 @@ describe('SessionCommands', () => {
describe('removeFromIgnoreList', () => { describe('removeFromIgnoreList', () => {
it('should call SessionCommands.removeFromList', () => { it('should call SessionCommands.removeFromList', () => {
spyOn(SessionCommands, 'removeFromList'); jest.spyOn(SessionCommands, 'removeFromList').mockImplementation(() => {});
const userName = 'userName'; const userName = 'userName';
SessionCommands.removeFromIgnoreList(userName); SessionCommands.removeFromIgnoreList(userName);
@ -588,7 +588,7 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled(); expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_AddToList.ext': addToList '.Command_AddToList.ext': addToList
}, jasmine.any(Function)); }, expect.any(Function));
}); });
}); });
@ -604,7 +604,7 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled(); expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith({
'.Command_RemoveFromList.ext': removeFromList '.Command_RemoveFromList.ext': removeFromList
}, jasmine.any(Function)); }, expect.any(Function));
}); });
}); });
@ -621,7 +621,7 @@ describe('SessionCommands', () => {
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalled(); expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith({ expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith({
'.Command_ViewLogHistory.ext': filters '.Command_ViewLogHistory.ext': filters
}, jasmine.any(Function)); }, expect.any(Function));
}); });
describe('response', () => { describe('response', () => {
@ -637,11 +637,11 @@ describe('SessionCommands', () => {
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } }; webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
sendModeratorCommandSpy.and.callFake((_, callback) => callback(response)); sendModeratorCommandSpy.mockImplementation((_, callback) => callback(response));
}); });
it('RespOk should call SessionPersistence.viewLogs', () => { it('RespOk should call SessionPersistence.viewLogs', () => {
spyOn(SessionPersistence, 'viewLogs'); jest.spyOn(SessionPersistence, 'viewLogs').mockImplementation(() => {});
SessionCommands.viewLogHistory(filters); SessionCommands.viewLogHistory(filters);

View file

@ -11,7 +11,7 @@ import { RoomPersistence } from '../persistence/RoomPersistence';
describe('RoomEvents', () => { describe('RoomEvents', () => {
it('.Event_JoinRoom.ext should call RoomPersistence.userJoined', () => { it('.Event_JoinRoom.ext should call RoomPersistence.userJoined', () => {
spyOn(RoomPersistence, 'userJoined'); jest.spyOn(RoomPersistence, 'userJoined').mockImplementation(() => {});
const data: JoinRoomData = { userInfo: {} as any }; const data: JoinRoomData = { userInfo: {} as any };
const event: RoomEvent = { roomEvent: { roomId: 1 } }; const event: RoomEvent = { roomEvent: { roomId: 1 } };
@ -24,7 +24,7 @@ describe('RoomEvents', () => {
}); });
it('.Event_LeaveRoom.ext should call RoomPersistence.userLeft', () => { it('.Event_LeaveRoom.ext should call RoomPersistence.userLeft', () => {
spyOn(RoomPersistence, 'userLeft'); jest.spyOn(RoomPersistence, 'userLeft').mockImplementation(() => {});
const data: LeaveRoomData = { name: '' }; const data: LeaveRoomData = { name: '' };
const event: RoomEvent = { roomEvent: { roomId: 1 } }; const event: RoomEvent = { roomEvent: { roomId: 1 } };
@ -37,7 +37,7 @@ describe('RoomEvents', () => {
}); });
it('.Event_ListGames.ext should call RoomPersistence.updateGames', () => { it('.Event_ListGames.ext should call RoomPersistence.updateGames', () => {
spyOn(RoomPersistence, 'updateGames'); jest.spyOn(RoomPersistence, 'updateGames').mockImplementation(() => {});
const data: ListGamesData = { gameList: [] }; const data: ListGamesData = { gameList: [] };
const event: RoomEvent = { roomEvent: { roomId: 1 } }; const event: RoomEvent = { roomEvent: { roomId: 1 } };
@ -50,7 +50,7 @@ describe('RoomEvents', () => {
}); });
it('.Event_RoomSay.ext should call RoomPersistence.addMessage', () => { it('.Event_RoomSay.ext should call RoomPersistence.addMessage', () => {
spyOn(RoomPersistence, 'addMessage'); jest.spyOn(RoomPersistence, 'addMessage').mockImplementation(() => {});
const data: Message = {} as any; const data: Message = {} as any;
const event: RoomEvent = { roomEvent: { roomId: 1 } }; const event: RoomEvent = { roomEvent: { roomId: 1 } };

View file

@ -1,4 +1,4 @@
import { StatusEnum } from 'types'; import { StatusEnum, WebSocketConnectReason } from 'types';
import { import {
AddToListData, AddToListData,
@ -15,18 +15,17 @@ import {
import { SessionCommands } from '../commands'; import { SessionCommands } from '../commands';
import { RoomPersistence, SessionPersistence } from '../persistence'; import { RoomPersistence, SessionPersistence } from '../persistence';
import webClient from '../WebClient'; import webClient from '../WebClient';
import { WebSocketConnectReason } from '../services/WebSocketService';
describe('SessionEvents', () => { describe('SessionEvents', () => {
const roomId = 1; const roomId = 1;
beforeEach(() => { beforeEach(() => {
spyOn(SessionCommands, 'updateStatus'); jest.spyOn(SessionCommands, 'updateStatus').mockImplementation(() => {});
}); });
describe('.Event_AddToList.ext', () => { describe('.Event_AddToList.ext', () => {
it('should call SessionPersistence.addToBuddyList if buddy listName', () => { it('should call SessionPersistence.addToBuddyList if buddy listName', () => {
spyOn(SessionPersistence, 'addToBuddyList'); jest.spyOn(SessionPersistence, 'addToBuddyList').mockImplementation(() => {});
const data: AddToListData = { listName: 'buddy', userInfo: {} as any }; const data: AddToListData = { listName: 'buddy', userInfo: {} as any };
SessionEvents['.Event_AddToList.ext'](data); SessionEvents['.Event_AddToList.ext'](data);
@ -37,7 +36,7 @@ describe('SessionEvents', () => {
}); });
it('should call SessionPersistence.addToIgnoreList if ignore listName', () => { it('should call SessionPersistence.addToIgnoreList if ignore listName', () => {
spyOn(SessionPersistence, 'addToIgnoreList'); jest.spyOn(SessionPersistence, 'addToIgnoreList').mockImplementation(() => {});
const data: AddToListData = { listName: 'ignore', userInfo: {} as any }; const data: AddToListData = { listName: 'ignore', userInfo: {} as any };
SessionEvents['.Event_AddToList.ext'](data); SessionEvents['.Event_AddToList.ext'](data);
@ -48,7 +47,7 @@ describe('SessionEvents', () => {
}); });
it('should call console.log if unknown listName', () => { it('should call console.log if unknown listName', () => {
spyOn(console, 'log'); jest.spyOn(console, 'log').mockImplementation(() => {});
const data: AddToListData = { listName: 'unknown', userInfo: {} as any }; const data: AddToListData = { listName: 'unknown', userInfo: {} as any };
SessionEvents['.Event_AddToList.ext'](data); SessionEvents['.Event_AddToList.ext'](data);
@ -218,7 +217,7 @@ describe('SessionEvents', () => {
describe('.Event_ListRooms.ext', () => { describe('.Event_ListRooms.ext', () => {
beforeEach(() => { beforeEach(() => {
webClient.options.autojoinrooms = false; webClient.options.autojoinrooms = false;
spyOn(RoomPersistence, 'updateRooms'); jest.spyOn(RoomPersistence, 'updateRooms').mockImplementation(() => {});
}); });
it('should call RoomPersistence.updateRooms', () => { it('should call RoomPersistence.updateRooms', () => {
@ -231,7 +230,7 @@ describe('SessionEvents', () => {
it('should call SessionCommands.joinRoom if webClient and room is configured for autojoin', () => { it('should call SessionCommands.joinRoom if webClient and room is configured for autojoin', () => {
webClient.options.autojoinrooms = true; webClient.options.autojoinrooms = true;
spyOn(SessionCommands, 'joinRoom'); jest.spyOn(SessionCommands, 'joinRoom').mockImplementation(() => {});
const data: ListRoomsData = { roomList: [{ roomId, autoJoin: true } as any, { roomId: 2, autoJoin: false } as any] }; const data: ListRoomsData = { roomList: [{ roomId, autoJoin: true } as any, { roomId: 2, autoJoin: false } as any] };
SessionEvents['.Event_ListRooms.ext'](data); SessionEvents['.Event_ListRooms.ext'](data);
@ -243,7 +242,7 @@ describe('SessionEvents', () => {
describe('.Event_RemoveFromList.ext', () => { describe('.Event_RemoveFromList.ext', () => {
it('should call SessionPersistence.removeFromBuddyList if buddy listName', () => { it('should call SessionPersistence.removeFromBuddyList if buddy listName', () => {
spyOn(SessionPersistence, 'removeFromBuddyList'); jest.spyOn(SessionPersistence, 'removeFromBuddyList').mockImplementation(() => {});
const data: RemoveFromListData = { listName: 'buddy', userName: '' }; const data: RemoveFromListData = { listName: 'buddy', userName: '' };
SessionEvents['.Event_RemoveFromList.ext'](data); SessionEvents['.Event_RemoveFromList.ext'](data);
@ -254,7 +253,7 @@ describe('SessionEvents', () => {
}); });
it('should call SessionPersistence.removeFromIgnoreList if ignore listName', () => { it('should call SessionPersistence.removeFromIgnoreList if ignore listName', () => {
spyOn(SessionPersistence, 'removeFromIgnoreList'); jest.spyOn(SessionPersistence, 'removeFromIgnoreList').mockImplementation(() => {});
const data: RemoveFromListData = { listName: 'ignore', userName: '' }; const data: RemoveFromListData = { listName: 'ignore', userName: '' };
SessionEvents['.Event_RemoveFromList.ext'](data); SessionEvents['.Event_RemoveFromList.ext'](data);
@ -265,7 +264,7 @@ describe('SessionEvents', () => {
}); });
it('should call console.log if unknown listName', () => { it('should call console.log if unknown listName', () => {
spyOn(console, 'log'); jest.spyOn(console, 'log').mockImplementation(() => {});
const data: RemoveFromListData = { listName: 'unknown', userName: '' }; const data: RemoveFromListData = { listName: 'unknown', userName: '' };
SessionEvents['.Event_RemoveFromList.ext'](data); SessionEvents['.Event_RemoveFromList.ext'](data);
@ -287,13 +286,15 @@ describe('SessionEvents', () => {
serverName: 'serverName', serverName: 'serverName',
serverVersion: 'serverVersion', serverVersion: 'serverVersion',
protocolVersion: 0, protocolVersion: 0,
serverOptions: 0
}; };
spyOn(SessionPersistence, 'updateInfo'); jest.spyOn(SessionPersistence, 'updateInfo').mockImplementation(() => {});
webClient.protobuf.controller.Event_ServerIdentification = { ServerOptions: { SupportsPasswordHash: 1 } };
}); });
it('update status/info and login', () => { it('update status/info and login', () => {
spyOn(SessionCommands, 'login'); jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
webClient.options.reason = WebSocketConnectReason.LOGIN; webClient.options.reason = WebSocketConnectReason.LOGIN;
@ -305,7 +306,7 @@ describe('SessionEvents', () => {
}); });
it('should update stat/info and register', () => { it('should update stat/info and register', () => {
spyOn(SessionCommands, 'register'); jest.spyOn(SessionCommands, 'register').mockImplementation(() => {});
webClient.options.reason = WebSocketConnectReason.REGISTER; webClient.options.reason = WebSocketConnectReason.REGISTER;
@ -316,7 +317,7 @@ describe('SessionEvents', () => {
}); });
it('should update stat/info and activate account', () => { it('should update stat/info and activate account', () => {
spyOn(SessionCommands, 'activateAccount'); jest.spyOn(SessionCommands, 'activateAccount').mockImplementation(() => {});
webClient.options.reason = WebSocketConnectReason.ACTIVATE_ACCOUNT; webClient.options.reason = WebSocketConnectReason.ACTIVATE_ACCOUNT;
@ -327,14 +328,15 @@ describe('SessionEvents', () => {
}); });
it('should disconnect if protocolVersion mismatched', () => { it('should disconnect if protocolVersion mismatched', () => {
spyOn(SessionCommands, 'login'); jest.spyOn(SessionCommands, 'login').mockImplementation(() => {});
spyOn(SessionCommands, 'disconnect'); jest.spyOn(SessionCommands, 'disconnect').mockImplementation(() => {});
webClient.protocolVersion = 0; webClient.protocolVersion = 0;
const data: ServerIdentificationData = { const data: ServerIdentificationData = {
serverName: '', serverName: '',
serverVersion: '', serverVersion: '',
protocolVersion: 1, protocolVersion: 1,
serverOptions: 0
}; };
event(data); event(data);
@ -350,7 +352,7 @@ describe('SessionEvents', () => {
describe('.Event_ServerMessage.ext', () => { describe('.Event_ServerMessage.ext', () => {
it('should call SessionPersistence.serverMessage', () => { it('should call SessionPersistence.serverMessage', () => {
spyOn(SessionPersistence, 'serverMessage'); jest.spyOn(SessionPersistence, 'serverMessage').mockImplementation(() => {});
const data: ServerMessageData = { message: 'message' }; const data: ServerMessageData = { message: 'message' };
SessionEvents['.Event_ServerMessage.ext'](data); SessionEvents['.Event_ServerMessage.ext'](data);
@ -363,7 +365,7 @@ describe('SessionEvents', () => {
describe('.Event_UserJoined.ext', () => { describe('.Event_UserJoined.ext', () => {
it('should call SessionPersistence.userJoined', () => { it('should call SessionPersistence.userJoined', () => {
spyOn(SessionPersistence, 'userJoined'); jest.spyOn(SessionPersistence, 'userJoined').mockImplementation(() => {});
const data: UserJoinedData = { userInfo: {} as any }; const data: UserJoinedData = { userInfo: {} as any };
SessionEvents['.Event_UserJoined.ext'](data); SessionEvents['.Event_UserJoined.ext'](data);
@ -376,7 +378,7 @@ describe('SessionEvents', () => {
describe('.Event_UserLeft.ext', () => { describe('.Event_UserLeft.ext', () => {
it('should call SessionPersistence.userLeft', () => { it('should call SessionPersistence.userLeft', () => {
spyOn(SessionPersistence, 'userLeft'); jest.spyOn(SessionPersistence, 'userLeft').mockImplementation(() => {});
const data: UserLeftData = { name: '' }; const data: UserLeftData = { name: '' };
SessionEvents['.Event_UserLeft.ext'](data); SessionEvents['.Event_UserLeft.ext'](data);

View file

@ -30,8 +30,8 @@ describe('KeepAliveService', () => {
promise = new Promise(resolve => resolvePing = resolve); promise = new Promise(resolve => resolvePing = resolve);
ping = (done) => promise.then(done); ping = (done) => promise.then(done);
checkReadyStateSpy = spyOn(socket, 'checkReadyState'); checkReadyStateSpy = jest.spyOn(socket, 'checkReadyState');
checkReadyStateSpy.and.returnValue(true); checkReadyStateSpy.mockImplementation(() => true);
service.startPingLoop(interval, ping); service.startPingLoop(interval, ping);
jest.advanceTimersByTime(interval); jest.advanceTimersByTime(interval);
@ -52,15 +52,15 @@ describe('KeepAliveService', () => {
}); });
it('should fire disconnected$ if lastPingPending is still true', () => { it('should fire disconnected$ if lastPingPending is still true', () => {
spyOn(service.disconnected$, 'next'); jest.spyOn(service.disconnected$, 'next').mockImplementation(() => {});
jest.advanceTimersByTime(interval); jest.advanceTimersByTime(interval);
expect(service.disconnected$.next).toHaveBeenCalled(); expect(service.disconnected$.next).toHaveBeenCalled();
}); });
it('should endPingLoop if socket is not open', () => { it('should endPingLoop if socket is not open', () => {
spyOn(service, 'endPingLoop'); jest.spyOn(service, 'endPingLoop').mockImplementation(() => {});
checkReadyStateSpy.and.returnValue(false); checkReadyStateSpy.mockImplementation(() => false);
resolvePing(); resolvePing();
jest.advanceTimersByTime(interval); jest.advanceTimersByTime(interval);