mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
cleanup testing utilities, documentation, and AI commentary
This commit is contained in:
parent
bd2382c94e
commit
ef6cea6f6c
150 changed files with 891 additions and 1233 deletions
|
|
@ -20,9 +20,6 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
2
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// adjustMod
|
||||
// ----------------------------------------------------------------
|
||||
describe('adjustMod', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_AdjustMod extension and fields', () => {
|
||||
|
|
@ -41,9 +38,6 @@ describe('adjustMod', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// reloadConfig
|
||||
// ----------------------------------------------------------------
|
||||
describe('reloadConfig', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_ReloadConfig extension', () => {
|
||||
|
|
@ -62,9 +56,6 @@ describe('reloadConfig', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// shutdownServer
|
||||
// ----------------------------------------------------------------
|
||||
describe('shutdownServer', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_ShutdownServer extension and fields', () => {
|
||||
|
|
@ -83,9 +74,6 @@ describe('shutdownServer', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// updateServerMessage
|
||||
// ----------------------------------------------------------------
|
||||
describe('updateServerMessage', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_UpdateServerMessage extension', () => {
|
||||
|
|
|
|||
|
|
@ -39,9 +39,6 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
2
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// banFromServer
|
||||
// ----------------------------------------------------------------
|
||||
describe('banFromServer', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_BanFromServer', () => {
|
||||
|
|
@ -60,9 +57,6 @@ describe('banFromServer', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// forceActivateUser
|
||||
// ----------------------------------------------------------------
|
||||
describe('forceActivateUser', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_ForceActivateUser', () => {
|
||||
|
|
@ -79,9 +73,6 @@ describe('forceActivateUser', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// getAdminNotes
|
||||
// ----------------------------------------------------------------
|
||||
describe('getAdminNotes', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_GetAdminNotes', () => {
|
||||
|
|
@ -101,9 +92,6 @@ describe('getAdminNotes', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// getBanHistory
|
||||
// ----------------------------------------------------------------
|
||||
describe('getBanHistory', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_GetBanHistory', () => {
|
||||
|
|
@ -123,9 +111,6 @@ describe('getBanHistory', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// getWarnHistory
|
||||
// ----------------------------------------------------------------
|
||||
describe('getWarnHistory', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_GetWarnHistory', () => {
|
||||
|
|
@ -145,9 +130,6 @@ describe('getWarnHistory', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// getWarnList
|
||||
// ----------------------------------------------------------------
|
||||
describe('getWarnList', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_GetWarnList', () => {
|
||||
|
|
@ -167,9 +149,6 @@ describe('getWarnList', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// grantReplayAccess
|
||||
// ----------------------------------------------------------------
|
||||
describe('grantReplayAccess', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_GrantReplayAccess', () => {
|
||||
|
|
@ -186,9 +165,6 @@ describe('grantReplayAccess', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// updateAdminNotes
|
||||
// ----------------------------------------------------------------
|
||||
describe('updateAdminNotes', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_UpdateAdminNotes', () => {
|
||||
|
|
@ -205,9 +181,6 @@ describe('updateAdminNotes', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// viewLogHistory
|
||||
// ----------------------------------------------------------------
|
||||
describe('viewLogHistory', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_ViewLogHistory', () => {
|
||||
|
|
@ -229,9 +202,6 @@ describe('viewLogHistory', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// warnUser
|
||||
// ----------------------------------------------------------------
|
||||
describe('warnUser', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_WarnUser', () => {
|
||||
|
|
|
|||
|
|
@ -24,9 +24,6 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
3
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// createGame
|
||||
// ----------------------------------------------------------------
|
||||
describe('createGame', () => {
|
||||
|
||||
it('calls sendRoomCommand with Command_CreateGame', () => {
|
||||
|
|
@ -43,9 +40,6 @@ describe('createGame', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// joinGame
|
||||
// ----------------------------------------------------------------
|
||||
describe('joinGame', () => {
|
||||
|
||||
it('calls sendRoomCommand with Command_JoinGame', () => {
|
||||
|
|
@ -62,9 +56,6 @@ describe('joinGame', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// leaveRoom
|
||||
// ----------------------------------------------------------------
|
||||
describe('leaveRoom', () => {
|
||||
|
||||
it('calls sendRoomCommand with Command_LeaveRoom', () => {
|
||||
|
|
@ -81,9 +72,6 @@ describe('leaveRoom', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// roomSay
|
||||
// ----------------------------------------------------------------
|
||||
describe('roomSay', () => {
|
||||
|
||||
it('calls sendRoomCommand with trimmed message', () => {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import {
|
|||
type ActivateParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { disconnect, login, updateStatus } from './';
|
||||
|
||||
export function activate(options: ConnectTarget & ActivateParams, password?: string, passwordSalt?: string): void {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
|
||||
export function connect(target: ConnectTarget): void {
|
||||
WebClient.instance.connect(target);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import {
|
|||
type ForgotPasswordChallengeParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function forgotPasswordChallenge(options: ConnectTarget & ForgotPasswordChallengeParams): void {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import {
|
|||
type ForgotPasswordRequestParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function forgotPasswordRequest(options: ConnectTarget & ForgotPasswordRequestParams): void {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import {
|
|||
type ForgotPasswordResetParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { hashPassword } from '../../utils';
|
||||
import { disconnect, updateStatus } from '.';
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import {
|
|||
type LoginParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { hashPassword } from '../../utils';
|
||||
import {
|
||||
disconnect,
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import {
|
|||
type RegisterParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { hashPassword } from '../../utils';
|
||||
import { login, disconnect, updateStatus } from './';
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import {
|
|||
type RequestPasswordSaltParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import type { ConnectTarget } from '../../types/WebClientConfig';
|
||||
import { updateStatus } from './';
|
||||
|
||||
export function requestPasswordSalt(
|
||||
|
|
|
|||
|
|
@ -18,8 +18,16 @@ import { Mock } from 'vitest';
|
|||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import * as SessionIndexMocks from './';
|
||||
import { Enriched } from '@app/types';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import {
|
||||
WebSocketConnectReason,
|
||||
type LoginConnectOptions,
|
||||
type RegisterConnectOptions,
|
||||
type ActivateConnectOptions,
|
||||
type PasswordResetRequestConnectOptions,
|
||||
type PasswordResetChallengeConnectOptions,
|
||||
type PasswordResetConnectOptions,
|
||||
} from '../../types/ConnectOptions';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import {
|
||||
Command_Activate_ext,
|
||||
Command_ForgotPasswordChallenge_ext,
|
||||
|
|
@ -56,50 +64,50 @@ const { invokeOnSuccess, invokeResponseCode, invokeOnError } = makeCallbackHelpe
|
|||
);
|
||||
|
||||
const baseTransport = { host: 'h', port: '1' };
|
||||
const makeLoginOpts = (overrides: Partial<Enriched.LoginConnectOptions> = {}): Enriched.LoginConnectOptions => ({
|
||||
const makeLoginOpts = (overrides: Partial<LoginConnectOptions> = {}): LoginConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
reason: Enriched.WebSocketConnectReason.LOGIN,
|
||||
reason: WebSocketConnectReason.LOGIN,
|
||||
...overrides,
|
||||
});
|
||||
const makeRegisterOpts = (
|
||||
overrides: Partial<Enriched.RegisterConnectOptions> = {}
|
||||
): Enriched.RegisterConnectOptions => ({
|
||||
overrides: Partial<RegisterConnectOptions> = {}
|
||||
): RegisterConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
password: 'pw',
|
||||
email: 'a@b.com',
|
||||
country: 'US',
|
||||
realName: 'Al',
|
||||
reason: Enriched.WebSocketConnectReason.REGISTER,
|
||||
reason: WebSocketConnectReason.REGISTER,
|
||||
...overrides,
|
||||
});
|
||||
const makeActivateOpts = (
|
||||
overrides: Partial<Enriched.ActivateConnectOptions> = {}
|
||||
): Enriched.ActivateConnectOptions => ({
|
||||
overrides: Partial<ActivateConnectOptions> = {}
|
||||
): ActivateConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
token: 'tok',
|
||||
reason: Enriched.WebSocketConnectReason.ACTIVATE_ACCOUNT,
|
||||
reason: WebSocketConnectReason.ACTIVATE_ACCOUNT,
|
||||
...overrides,
|
||||
});
|
||||
const makeForgotRequestOpts = (): Enriched.PasswordResetRequestConnectOptions => ({
|
||||
const makeForgotRequestOpts = (): PasswordResetRequestConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
reason: Enriched.WebSocketConnectReason.PASSWORD_RESET_REQUEST,
|
||||
reason: WebSocketConnectReason.PASSWORD_RESET_REQUEST,
|
||||
});
|
||||
const makeForgotChallengeOpts = (): Enriched.PasswordResetChallengeConnectOptions => ({
|
||||
const makeForgotChallengeOpts = (): PasswordResetChallengeConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
email: 'a@b.com',
|
||||
reason: Enriched.WebSocketConnectReason.PASSWORD_RESET_CHALLENGE,
|
||||
reason: WebSocketConnectReason.PASSWORD_RESET_CHALLENGE,
|
||||
});
|
||||
const makeForgotResetOpts = (): Enriched.PasswordResetConnectOptions => ({
|
||||
const makeForgotResetOpts = (): PasswordResetConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
token: 'tok',
|
||||
newPassword: 'newpw',
|
||||
reason: Enriched.WebSocketConnectReason.PASSWORD_RESET,
|
||||
reason: WebSocketConnectReason.PASSWORD_RESET,
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -109,9 +117,6 @@ beforeEach(() => {
|
|||
(passwordSaltSupported as Mock).mockReturnValue(0);
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// connect.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('connect', () => {
|
||||
|
||||
it('calls WebClient.instance.connect with the target', () => {
|
||||
|
|
@ -128,9 +133,6 @@ describe('testConnect', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// updateStatus.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('updateStatus', () => {
|
||||
|
||||
it('calls WebClient.instance.response.session.updateStatus and WebClient.instance.updateStatus', () => {
|
||||
|
|
@ -140,9 +142,6 @@ describe('updateStatus', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// login.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('login', () => {
|
||||
|
||||
it('sends Command_Login with plain password when no salt', () => {
|
||||
|
|
@ -194,7 +193,7 @@ describe('login', () => {
|
|||
});
|
||||
|
||||
it('onSuccess passes hashedPassword to loginSuccessful when salt is used', () => {
|
||||
login({ host: 'h', port: '1', userName: 'alice', reason: Enriched.WebSocketConnectReason.LOGIN }, 'pw', 'salt');
|
||||
login({ host: 'h', port: '1', userName: 'alice', reason: WebSocketConnectReason.LOGIN }, 'pw', 'salt');
|
||||
const loginResp = { buddyList: [], ignoreList: [], userInfo: { name: 'alice' } };
|
||||
invokeOnSuccess(loginResp, { responseCode: 0 });
|
||||
const calledWith = (WebClient.instance.response.session.loginSuccessful as Mock).mock.calls[0][0];
|
||||
|
|
@ -266,9 +265,6 @@ describe('login', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// register.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('register', () => {
|
||||
|
||||
it('sends Command_Register with plain password when no salt', () => {
|
||||
|
|
@ -371,9 +367,6 @@ describe('register', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// activate.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('activate', () => {
|
||||
|
||||
it('sends Command_Activate with userName and token, not password', () => {
|
||||
|
|
@ -405,9 +398,6 @@ describe('activate', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// forgotPasswordChallenge.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('forgotPasswordChallenge', () => {
|
||||
|
||||
it('sends Command_ForgotPasswordChallenge', () => {
|
||||
|
|
@ -432,9 +422,6 @@ describe('forgotPasswordChallenge', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// forgotPasswordRequest.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('forgotPasswordRequest', () => {
|
||||
|
||||
it('sends Command_ForgotPasswordRequest', () => {
|
||||
|
|
@ -470,9 +457,6 @@ describe('forgotPasswordRequest', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// forgotPasswordReset.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('forgotPasswordReset', () => {
|
||||
|
||||
it('sends Command_ForgotPasswordReset with plain newPassword when no salt', () => {
|
||||
|
|
@ -508,9 +492,6 @@ describe('forgotPasswordReset', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// requestPasswordSalt.ts
|
||||
// ----------------------------------------------------------------
|
||||
describe('requestPasswordSalt', () => {
|
||||
|
||||
it('sends Command_RequestPasswordSalt', () => {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ beforeEach(() => {
|
|||
(passwordSaltSupported as Mock).mockReturnValue(0);
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
describe('accountEdit', () => {
|
||||
it('sends Command_AccountEdit with correct params', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { StatusEnum } from '../../types/StatusEnum';
|
||||
import { WebClient } from '../../WebClient';
|
||||
|
||||
export function updateStatus(status: StatusEnum, description: string): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue