mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
Add ESLint & Run it against the system (#4470)
This commit is contained in:
parent
43eee6b32e
commit
f789e02096
106 changed files with 1235 additions and 20242 deletions
|
|
@ -68,4 +68,4 @@ describe('RoomCommands', () => {
|
|||
expect(RoomPersistence.leaveRoom).toHaveBeenCalledWith(roomId);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,28 +1,30 @@
|
|||
import { RoomPersistence } from '../persistence';
|
||||
import webClient from "../WebClient";
|
||||
import webClient from '../WebClient';
|
||||
|
||||
export class RoomCommands {
|
||||
static roomSay(roomId: number, message: string): void {
|
||||
const trimmed = message.trim();
|
||||
|
||||
if (!trimmed) return;
|
||||
|
||||
var CmdRoomSay = webClient.protobuf.controller.Command_RoomSay.create({
|
||||
"message" : trimmed
|
||||
if (!trimmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const CmdRoomSay = webClient.protobuf.controller.Command_RoomSay.create({
|
||||
'message': trimmed
|
||||
});
|
||||
|
||||
var rc = webClient.protobuf.controller.RoomCommand.create({
|
||||
".Command_RoomSay.ext" : CmdRoomSay
|
||||
const rc = webClient.protobuf.controller.RoomCommand.create({
|
||||
'.Command_RoomSay.ext': CmdRoomSay
|
||||
});
|
||||
|
||||
webClient.protobuf.sendRoomCommand(roomId, rc);
|
||||
}
|
||||
|
||||
static leaveRoom(roomId: number): void {
|
||||
var CmdLeaveRoom = webClient.protobuf.controller.Command_LeaveRoom.create();
|
||||
const CmdLeaveRoom = webClient.protobuf.controller.Command_LeaveRoom.create();
|
||||
|
||||
var rc = webClient.protobuf.controller.RoomCommand.create({
|
||||
".Command_LeaveRoom.ext" : CmdLeaveRoom
|
||||
const rc = webClient.protobuf.controller.RoomCommand.create({
|
||||
'.Command_LeaveRoom.ext': CmdLeaveRoom
|
||||
});
|
||||
|
||||
webClient.protobuf.sendRoomCommand(roomId, rc, (raw) => {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {StatusEnum} from 'types';
|
||||
import { StatusEnum } 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 {WebSocketConnectReason} from "../services/WebSocketService";
|
||||
import {AccountActivationParams, ServerRegisterParams} from "../../store";
|
||||
import { WebSocketConnectReason } from '../services/WebSocketService';
|
||||
import { AccountActivationParams, ServerRegisterParams } from '../../store';
|
||||
|
||||
describe('SessionCommands', () => {
|
||||
const roomId = 1;
|
||||
|
|
@ -42,7 +42,7 @@ describe('SessionCommands', () => {
|
|||
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalled();
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, expect.any(String));
|
||||
|
||||
|
||||
expect(webClient.connect).toHaveBeenCalled();
|
||||
expect(webClient.connect).toHaveBeenCalledWith({ ...options, reason: WebSocketConnectReason.LOGIN });
|
||||
});
|
||||
|
|
@ -75,7 +75,7 @@ describe('SessionCommands', () => {
|
|||
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalled();
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTING, 'Disconnecting...');
|
||||
|
||||
|
||||
expect(webClient.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
@ -226,7 +226,10 @@ describe('SessionCommands', () => {
|
|||
|
||||
SessionCommands.login();
|
||||
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, 'Login failed: account not activated');
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
|
||||
StatusEnum.DISCONNECTED,
|
||||
'Login failed: account not activated'
|
||||
);
|
||||
});
|
||||
|
||||
it('all other responseCodes should update status', () => {
|
||||
|
|
@ -236,7 +239,10 @@ describe('SessionCommands', () => {
|
|||
|
||||
SessionCommands.login();
|
||||
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, `Login failed: unknown error: ${response.responseCode}`);
|
||||
expect(SessionCommands.updateStatus).toHaveBeenCalledWith(
|
||||
StatusEnum.DISCONNECTED,
|
||||
`Login failed: unknown error: ${response.responseCode}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -283,17 +289,17 @@ describe('SessionCommands', () => {
|
|||
response = {
|
||||
responseCode: RespRegistrationAccepted,
|
||||
[respKey]: {
|
||||
reasonStr: "",
|
||||
reasonStr: '',
|
||||
endTime: 10000000
|
||||
}
|
||||
};
|
||||
|
||||
webClient.protobuf.controller.Response = { ResponseCode: { RespRegistrationAccepted }};
|
||||
webClient.protobuf.controller.Response = { ResponseCode: { RespRegistrationAccepted } };
|
||||
|
||||
sendSessionCommandSpy.and.callFake((_, 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');
|
||||
spyOn(SessionPersistence, 'accountAwaitingActivation');
|
||||
|
||||
|
|
@ -303,10 +309,11 @@ describe('SessionCommands', () => {
|
|||
expect(SessionPersistence.accountAwaitingActivation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should prompt user if registration accepted with email verification", () => {
|
||||
it('should prompt user if registration accepted with email verification', () => {
|
||||
const RespRegistrationAcceptedNeedsActivation = 'RespRegistrationAcceptedNeedsActivation';
|
||||
response.responseCode = RespRegistrationAcceptedNeedsActivation;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation = RespRegistrationAcceptedNeedsActivation;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAcceptedNeedsActivation =
|
||||
RespRegistrationAcceptedNeedsActivation;
|
||||
|
||||
spyOn(SessionCommands, 'login');
|
||||
spyOn(SessionPersistence, 'accountAwaitingActivation');
|
||||
|
|
@ -317,7 +324,7 @@ describe('SessionCommands', () => {
|
|||
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should disconnect user if registration fails due to registration being disabled", () => {
|
||||
it('should disconnect user if registration fails due to registration being disabled', () => {
|
||||
const RespRegistrationDisabled = 'RespRegistrationDisabled';
|
||||
response.responseCode = RespRegistrationDisabled;
|
||||
webClient.protobuf.controller.Response.ResponseCode.RespRegistrationDisabled = RespRegistrationDisabled;
|
||||
|
|
@ -368,7 +375,7 @@ describe('SessionCommands', () => {
|
|||
}
|
||||
};
|
||||
|
||||
webClient.protobuf.controller.Response = { ResponseCode: { RespActivationAccepted }};
|
||||
webClient.protobuf.controller.Response = { ResponseCode: { RespActivationAccepted } };
|
||||
|
||||
sendSessionCommandSpy.and.callFake((_, callback) => callback(response));
|
||||
spyOn(SessionCommands, 'login');
|
||||
|
|
@ -497,7 +504,10 @@ describe('SessionCommands', () => {
|
|||
|
||||
SessionCommands.joinRoom(roomId);
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(RespContextError, 'The server thinks you are in the room but Cockatrice is unable to display it. Try restarting Cockatrice.');
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
RespContextError,
|
||||
'The server thinks you are in the room but Cockatrice is unable to display it. Try restarting Cockatrice.'
|
||||
);
|
||||
});
|
||||
|
||||
it('RespUserLevelTooLow should console error', () => {
|
||||
|
|
@ -572,7 +582,7 @@ describe('SessionCommands', () => {
|
|||
});
|
||||
|
||||
it('should call protobuf controller methods and sendCommand', () => {
|
||||
const addToList = { list: 'list', userName: 'userName'};
|
||||
const addToList = { list: 'list', userName: 'userName' };
|
||||
SessionCommands.addToList(addToList.list, addToList.userName);
|
||||
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
|
||||
|
|
@ -588,7 +598,7 @@ describe('SessionCommands', () => {
|
|||
});
|
||||
|
||||
it('should call protobuf controller methods and sendCommand', () => {
|
||||
const removeFromList = { list: 'list', userName: 'userName'};
|
||||
const removeFromList = { list: 'list', userName: 'userName' };
|
||||
SessionCommands.removeFromList(removeFromList.list, removeFromList.userName);
|
||||
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalled();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {StatusEnum} from 'types';
|
||||
import { StatusEnum } from 'types';
|
||||
|
||||
import {RoomPersistence, SessionPersistence} from '../persistence';
|
||||
import { RoomPersistence, SessionPersistence } from '../persistence';
|
||||
import webClient from '../WebClient';
|
||||
import {guid, hashPassword} from '../utils';
|
||||
import {WebSocketConnectReason, WebSocketOptions} from "../services/WebSocketService";
|
||||
import { guid, hashPassword } from '../utils';
|
||||
import { WebSocketConnectReason, WebSocketOptions } from '../services/WebSocketService';
|
||||
import {
|
||||
AccountActivationParams,
|
||||
ForgotPasswordChallengeParams,
|
||||
|
|
@ -11,8 +11,8 @@ import {
|
|||
ForgotPasswordResetParams,
|
||||
RequestPasswordSaltParams,
|
||||
ServerRegisterParams
|
||||
} from "../../store";
|
||||
import NormalizeService from "../utils/NormalizeService";
|
||||
} from '../../store';
|
||||
import NormalizeService from '../utils/NormalizeService';
|
||||
|
||||
export class SessionCommands {
|
||||
static connect(options: WebSocketOptions, reason: WebSocketConnectReason): void {
|
||||
|
|
@ -53,7 +53,7 @@ export class SessionCommands {
|
|||
const CmdLogin = webClient.protobuf.controller.Command_Login.create(loginConfig);
|
||||
|
||||
const command = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_Login.ext' : CmdLogin
|
||||
'.Command_Login.ext': CmdLogin
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(command, raw => {
|
||||
|
|
@ -73,7 +73,7 @@ export class SessionCommands {
|
|||
return;
|
||||
}
|
||||
|
||||
switch(raw.responseCode) {
|
||||
switch (raw.responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespClientUpdateRequired:
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: missing features');
|
||||
break;
|
||||
|
|
@ -127,23 +127,23 @@ export class SessionCommands {
|
|||
const CmdRequestPasswordSalt = webClient.protobuf.controller.Command_RequestPasswordSalt.create(registerConfig);
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
".Command_RequestPasswordSalt.ext" : CmdRequestPasswordSalt
|
||||
'.Command_RequestPasswordSalt.ext': CmdRequestPasswordSalt
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
switch (raw.responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const passwordSalt = raw[".Response_PasswordSalt.ext"].passwordSalt;
|
||||
const passwordSalt = raw['.Response_PasswordSalt.ext'].passwordSalt;
|
||||
SessionCommands.login(passwordSalt);
|
||||
break;
|
||||
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationRequired:
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, "Login failed: incorrect username or password");
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: incorrect username or password');
|
||||
SessionCommands.disconnect();
|
||||
break;
|
||||
|
||||
default:
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, "Login failed: Unknown Reason");
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Login failed: Unknown Reason');
|
||||
SessionCommands.disconnect();
|
||||
break;
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ export class SessionCommands {
|
|||
const CmdRegister = webClient.protobuf.controller.Command_Register.create(registerConfig);
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_Register.ext' : CmdRegister
|
||||
'.Command_Register.ext': CmdRegister
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
|
|
@ -203,12 +203,12 @@ export class SessionCommands {
|
|||
error = NormalizeService.normalizeBannedUserError(raw.reasonStr, raw.endTime);
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
|
||||
console.error("ResponseCode.RespUsernameInvalid", raw.reasonStr);
|
||||
console.error('ResponseCode.RespUsernameInvalid', raw.reasonStr);
|
||||
error = 'Invalid username';
|
||||
break;
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationFailed:
|
||||
default:
|
||||
console.error("ResponseCode Type", raw.responseCode);
|
||||
console.error('ResponseCode Type', raw.responseCode);
|
||||
error = 'Registration failed due to a server issue';
|
||||
break;
|
||||
}
|
||||
|
|
@ -238,13 +238,13 @@ export class SessionCommands {
|
|||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {
|
||||
SessionCommands.login();
|
||||
} else {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
|
||||
SessionCommands.disconnect();
|
||||
SessionPersistence.accountActivationFailed();
|
||||
}
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {
|
||||
SessionCommands.login();
|
||||
} else {
|
||||
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
|
||||
SessionCommands.disconnect();
|
||||
SessionPersistence.accountActivationFailed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -260,12 +260,12 @@ export class SessionCommands {
|
|||
const CmdForgotPasswordRequest = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig);
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_ForgotPasswordRequest.ext' : CmdForgotPasswordRequest
|
||||
'.Command_ForgotPasswordRequest.ext': CmdForgotPasswordRequest
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {
|
||||
const resp = raw[".Response_ForgotPasswordRequest.ext"];
|
||||
const resp = raw['.Response_ForgotPasswordRequest.ext'];
|
||||
|
||||
if (resp.challengeEmail) {
|
||||
SessionPersistence.resetPasswordChallenge();
|
||||
|
|
@ -293,7 +293,7 @@ export class SessionCommands {
|
|||
const CmdForgotPasswordChallenge = webClient.protobuf.controller.Command_ForgotPasswordChallenge.create(forgotPasswordChallengeConfig);
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_ForgotPasswordChallenge.ext' : CmdForgotPasswordChallenge
|
||||
'.Command_ForgotPasswordChallenge.ext': CmdForgotPasswordChallenge
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
|
|
@ -321,7 +321,7 @@ export class SessionCommands {
|
|||
const CmdForgotPasswordReset = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig);
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_ForgotPasswordReset.ext' : CmdForgotPasswordReset
|
||||
'.Command_ForgotPasswordReset.ext': CmdForgotPasswordReset
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
|
|
@ -339,7 +339,7 @@ export class SessionCommands {
|
|||
const CmdListUsers = webClient.protobuf.controller.Command_ListUsers.create();
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_ListUsers.ext' : CmdListUsers
|
||||
'.Command_ListUsers.ext': CmdListUsers
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, raw => {
|
||||
|
|
@ -363,7 +363,7 @@ export class SessionCommands {
|
|||
const CmdListRooms = webClient.protobuf.controller.Command_ListRooms.create();
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_ListRooms.ext' : CmdListRooms
|
||||
'.Command_ListRooms.ext': CmdListRooms
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc);
|
||||
|
|
@ -373,7 +373,7 @@ export class SessionCommands {
|
|||
const CmdJoinRoom = webClient.protobuf.controller.Command_JoinRoom.create({ roomId });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_JoinRoom.ext' : CmdJoinRoom
|
||||
'.Command_JoinRoom.ext': CmdJoinRoom
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, (raw) => {
|
||||
|
|
@ -381,7 +381,7 @@ export class SessionCommands {
|
|||
|
||||
let error;
|
||||
|
||||
switch(responseCode) {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { roomInfo } = raw['.Response_JoinRoom.ext'];
|
||||
|
||||
|
|
@ -400,7 +400,7 @@ export class SessionCommands {
|
|||
error = 'Failed to join the room due to an unknown error.';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
|
|
@ -427,7 +427,7 @@ export class SessionCommands {
|
|||
const CmdAddToList = webClient.protobuf.controller.Command_AddToList.create({ list, userName });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_AddToList.ext' : CmdAddToList
|
||||
'.Command_AddToList.ext': CmdAddToList
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
|
||||
|
|
@ -439,7 +439,7 @@ export class SessionCommands {
|
|||
const CmdRemoveFromList = webClient.protobuf.controller.Command_RemoveFromList.create({ list, userName });
|
||||
|
||||
const sc = webClient.protobuf.controller.SessionCommand.create({
|
||||
'.Command_RemoveFromList.ext' : CmdRemoveFromList
|
||||
'.Command_RemoveFromList.ext': CmdRemoveFromList
|
||||
});
|
||||
|
||||
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
|
||||
|
|
@ -451,7 +451,7 @@ export class SessionCommands {
|
|||
const CmdViewLogHistory = webClient.protobuf.controller.Command_ViewLogHistory.create(filters);
|
||||
|
||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({
|
||||
'.Command_ViewLogHistory.ext' : CmdViewLogHistory
|
||||
'.Command_ViewLogHistory.ext': CmdViewLogHistory
|
||||
});
|
||||
|
||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||
|
|
@ -459,7 +459,7 @@ export class SessionCommands {
|
|||
|
||||
let error;
|
||||
|
||||
switch(responseCode) {
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
const { logMessage } = raw['.Response_ViewLogHistory.ext'];
|
||||
SessionPersistence.viewLogs(logMessage)
|
||||
|
|
@ -468,7 +468,7 @@ export class SessionCommands {
|
|||
error = 'Failed to retrieve log history.';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
export { RoomCommands } from "./RoomCommands";
|
||||
export { SessionCommands } from "./SessionCommands";
|
||||
export { RoomCommands } from './RoomCommands';
|
||||
export { SessionCommands } from './SessionCommands';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue