mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
parent
0994d10410
commit
c4bf9eb61c
61 changed files with 207 additions and 737 deletions
|
|
@ -1,75 +0,0 @@
|
|||
import { RoomPersistence } from '../../persistence';
|
||||
import webClient from '../../WebClient';
|
||||
|
||||
import { leaveRoom, roomSay } from './';
|
||||
|
||||
describe.skip('RoomCommands', () => {
|
||||
const roomId = 1;
|
||||
let sendRoomCommandSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
sendRoomCommandSpy = jest.spyOn(webClient.protobuf, 'sendRoomCommand').mockImplementation(() => {});
|
||||
|
||||
webClient.protobuf.controller.RoomCommand = { create: args => args };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('roomSay', () => {
|
||||
beforeEach(() => {
|
||||
webClient.protobuf.controller.Command_RoomSay = { create: args => args };
|
||||
});
|
||||
|
||||
it('should call protobuf controller methods and sendCommand', () => {
|
||||
const message = ' message ';
|
||||
|
||||
roomSay(roomId, message);
|
||||
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalled();
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(roomId, {
|
||||
'.Command_RoomSay.ext': { message: message.trim() }
|
||||
});
|
||||
});
|
||||
|
||||
it('should not call sendRoomCommand if trimmed message is empty', () => {
|
||||
const message = ' ';
|
||||
|
||||
roomSay(roomId, message);
|
||||
|
||||
expect(webClient.protobuf.sendRoomCommand).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('leaveRoom', () => {
|
||||
beforeEach(() => {
|
||||
webClient.protobuf.controller.Command_LeaveRoom = { create: () => ({}) };
|
||||
});
|
||||
|
||||
it('should call protobuf controller methods and sendCommand', () => {
|
||||
leaveRoom(roomId);
|
||||
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalled();
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(
|
||||
roomId,
|
||||
{ '.Command_LeaveRoom.ext': {} },
|
||||
expect.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it('should call RoomPersistence.leaveRoom if RespOk', () => {
|
||||
const RespOk = 'ok';
|
||||
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
|
||||
sendRoomCommandSpy.mockImplementation((_, __, callback) => {
|
||||
callback({ responseCode: RespOk })
|
||||
});
|
||||
|
||||
jest.spyOn(RoomPersistence, 'leaveRoom').mockImplementation(() => {});
|
||||
|
||||
leaveRoom(roomId);
|
||||
|
||||
expect(RoomPersistence.leaveRoom).toHaveBeenCalledWith(roomId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -2,11 +2,8 @@ import { RoomPersistence } from '../../persistence';
|
|||
import webClient from '../../WebClient';
|
||||
|
||||
export function leaveRoom(roomId: number): void {
|
||||
const CmdLeaveRoom = webClient.protobuf.controller.Command_LeaveRoom.create();
|
||||
|
||||
const rc = webClient.protobuf.controller.RoomCommand.create({
|
||||
'.Command_LeaveRoom.ext': CmdLeaveRoom
|
||||
});
|
||||
const command = webClient.protobuf.controller.Command_LeaveRoom.create();
|
||||
const rc = webClient.protobuf.controller.RoomCommand.create({ '.Command_LeaveRoom.ext': command });
|
||||
|
||||
webClient.protobuf.sendRoomCommand(roomId, rc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
|
|
|||
|
|
@ -7,13 +7,8 @@ export function roomSay(roomId: number, message: string): void {
|
|||
return;
|
||||
}
|
||||
|
||||
const CmdRoomSay = webClient.protobuf.controller.Command_RoomSay.create({
|
||||
'message': trimmed
|
||||
});
|
||||
|
||||
const rc = webClient.protobuf.controller.RoomCommand.create({
|
||||
'.Command_RoomSay.ext': CmdRoomSay
|
||||
});
|
||||
const command = webClient.protobuf.controller.Command_RoomSay.create({ 'message': trimmed });
|
||||
const rc = webClient.protobuf.controller.RoomCommand.create({ '.Command_RoomSay.ext': command });
|
||||
|
||||
webClient.protobuf.sendRoomCommand(roomId, rc);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue