mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
fix unit tests and refactor types
This commit is contained in:
parent
decebc25c7
commit
fea21b5057
75 changed files with 908 additions and 501 deletions
|
|
@ -1,31 +1,20 @@
|
|||
vi.mock('../../WebClient', () => ({
|
||||
WebClient: {
|
||||
instance: {
|
||||
protobuf: { sendAdminCommand: vi.fn() },
|
||||
response: {
|
||||
admin: {
|
||||
adjustMod: vi.fn(),
|
||||
reloadConfig: vi.fn(),
|
||||
shutdownServer: vi.fn(),
|
||||
updateServerMessage: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
vi.mock('../../WebClient');
|
||||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { useWebClientCleanup } from '../../__mocks__/helpers';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import { adjustMod } from './adjustMod';
|
||||
import { reloadConfig } from './reloadConfig';
|
||||
import { shutdownServer } from './shutdownServer';
|
||||
import { updateServerMessage } from './updateServerMessage';
|
||||
import {
|
||||
Command_AdjustMod_ext,
|
||||
Command_ReloadConfig_ext,
|
||||
Command_ShutdownServer_ext,
|
||||
Command_UpdateServerMessage_ext,
|
||||
} from '@app/generated';
|
||||
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
useWebClientCleanup();
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
WebClient.instance.protobuf.sendAdminCommand as Mock,
|
||||
2
|
||||
|
|
@ -36,9 +25,13 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
// ----------------------------------------------------------------
|
||||
describe('adjustMod', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_AdjustMod', () => {
|
||||
it('calls sendAdminCommand with Command_AdjustMod extension and fields', () => {
|
||||
adjustMod('alice', true, false);
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(
|
||||
Command_AdjustMod_ext,
|
||||
expect.objectContaining({ userName: 'alice', shouldBeMod: true, shouldBeJudge: false }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls response.admin.adjustMod', () => {
|
||||
|
|
@ -53,9 +46,13 @@ describe('adjustMod', () => {
|
|||
// ----------------------------------------------------------------
|
||||
describe('reloadConfig', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_ReloadConfig', () => {
|
||||
it('calls sendAdminCommand with Command_ReloadConfig extension', () => {
|
||||
reloadConfig();
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(
|
||||
Command_ReloadConfig_ext,
|
||||
expect.any(Object),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls response.admin.reloadConfig', () => {
|
||||
|
|
@ -70,9 +67,13 @@ describe('reloadConfig', () => {
|
|||
// ----------------------------------------------------------------
|
||||
describe('shutdownServer', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_ShutdownServer', () => {
|
||||
it('calls sendAdminCommand with Command_ShutdownServer extension and fields', () => {
|
||||
shutdownServer('maintenance', 10);
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(
|
||||
Command_ShutdownServer_ext,
|
||||
expect.objectContaining({ reason: 'maintenance', minutes: 10 }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls response.admin.shutdownServer', () => {
|
||||
|
|
@ -87,9 +88,13 @@ describe('shutdownServer', () => {
|
|||
// ----------------------------------------------------------------
|
||||
describe('updateServerMessage', () => {
|
||||
|
||||
it('calls sendAdminCommand with Command_UpdateServerMessage', () => {
|
||||
it('calls sendAdminCommand with Command_UpdateServerMessage extension', () => {
|
||||
updateServerMessage();
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
expect(WebClient.instance.protobuf.sendAdminCommand).toHaveBeenCalledWith(
|
||||
Command_UpdateServerMessage_ext,
|
||||
expect.any(Object),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls response.admin.updateServerMessage', () => {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,6 @@
|
|||
vi.mock('../../WebClient', () => ({
|
||||
WebClient: {
|
||||
instance: {
|
||||
protobuf: { sendGameCommand: vi.fn() },
|
||||
response: { game: {} },
|
||||
},
|
||||
},
|
||||
}));
|
||||
vi.mock('../../WebClient');
|
||||
|
||||
import { WebClient } from '../../WebClient';
|
||||
import { useWebClientCleanup } from '../../__mocks__/helpers';
|
||||
|
||||
useWebClientCleanup();
|
||||
import { create, setExtension } from '@bufbuild/protobuf';
|
||||
import {
|
||||
Command_AttachCard_ext,
|
||||
|
|
|
|||
|
|
@ -1,27 +1,6 @@
|
|||
vi.mock('../../WebClient', () => ({
|
||||
WebClient: {
|
||||
instance: {
|
||||
protobuf: { sendModeratorCommand: vi.fn() },
|
||||
response: {
|
||||
moderator: {
|
||||
banFromServer: vi.fn(),
|
||||
forceActivateUser: vi.fn(),
|
||||
getAdminNotes: vi.fn(),
|
||||
banHistory: vi.fn(),
|
||||
warnHistory: vi.fn(),
|
||||
warnListOptions: vi.fn(),
|
||||
grantReplayAccess: vi.fn(),
|
||||
updateAdminNotes: vi.fn(),
|
||||
viewLogs: vi.fn(),
|
||||
warnUser: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
vi.mock('../../WebClient');
|
||||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { useWebClientCleanup } from '../../__mocks__/helpers';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import {
|
||||
Command_BanFromServer_ext,
|
||||
|
|
@ -55,8 +34,6 @@ import { warnUser } from './warnUser';
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
useWebClientCleanup();
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
WebClient.instance.protobuf.sendModeratorCommand as Mock,
|
||||
2
|
||||
|
|
|
|||
|
|
@ -1,20 +1,6 @@
|
|||
vi.mock('../../WebClient', () => ({
|
||||
WebClient: {
|
||||
instance: {
|
||||
protobuf: { sendRoomCommand: vi.fn() },
|
||||
response: {
|
||||
room: {
|
||||
gameCreated: vi.fn(),
|
||||
joinedGame: vi.fn(),
|
||||
leaveRoom: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
vi.mock('../../WebClient');
|
||||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { useWebClientCleanup } from '../../__mocks__/helpers';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import {
|
||||
Command_CreateGame_ext,
|
||||
|
|
@ -32,8 +18,6 @@ import { roomSay } from './roomSay';
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
useWebClientCleanup();
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
WebClient.instance.protobuf.sendRoomCommand as Mock,
|
||||
// sendRoomCommand(roomId, ext, value, options) — options at index 3
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import {
|
|||
type ActivateParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/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 '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
|
||||
export function connect(target: ConnectTarget): void {
|
||||
WebClient.instance.connect(target);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import {
|
|||
type ForgotPasswordChallengeParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/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 '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/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 '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import { hashPassword } from '../../utils';
|
||||
import { disconnect, updateStatus } from '.';
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import {
|
|||
type LoginParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import { hashPassword } from '../../utils';
|
||||
import {
|
||||
disconnect,
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import {
|
|||
type RegisterParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import { hashPassword } from '../../utils';
|
||||
import { login, disconnect, updateStatus } from './';
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import {
|
|||
type RequestPasswordSaltParams,
|
||||
} from '@app/generated';
|
||||
|
||||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import type { ConnectTarget } from '../../WebClientConfig';
|
||||
import type { ConnectTarget } from '../../interfaces/WebClientConfig';
|
||||
import { updateStatus } from './';
|
||||
|
||||
export function requestPasswordSalt(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
// Tests for complex session commands that call WebClient directly
|
||||
// or have multiple branching callbacks.
|
||||
|
||||
vi.mock('../../WebClient', async () => {
|
||||
const { makeWebClientMock } = await import('../../__mocks__/sessionCommandMocks');
|
||||
return { WebClient: { instance: makeWebClientMock() } };
|
||||
});
|
||||
vi.mock('../../WebClient');
|
||||
|
||||
vi.mock('../../utils', async () => {
|
||||
const { makeUtilsMock } = await import('../../__mocks__/sessionCommandMocks');
|
||||
|
|
@ -19,11 +16,10 @@ vi.mock('./', async () => {
|
|||
|
||||
import { Mock } from 'vitest';
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { useWebClientCleanup } from '../../__mocks__/helpers';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import * as SessionIndexMocks from './';
|
||||
import { App, Enriched } from '@app/types';
|
||||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import {
|
||||
Command_Activate_ext,
|
||||
Command_ForgotPasswordChallenge_ext,
|
||||
|
|
@ -54,8 +50,6 @@ import { forgotPasswordRequest } from './forgotPasswordRequest';
|
|||
import { forgotPasswordReset } from './forgotPasswordReset';
|
||||
import { requestPasswordSalt } from './requestPasswordSalt';
|
||||
|
||||
useWebClientCleanup();
|
||||
|
||||
const { invokeOnSuccess, invokeResponseCode, invokeOnError } = makeCallbackHelpers(
|
||||
WebClient.instance.protobuf.sendSessionCommand as Mock,
|
||||
2
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
// Shared mock setup for session command tests
|
||||
|
||||
vi.mock('../../WebClient', async () => {
|
||||
const { makeWebClientMock } = await import('../../__mocks__/sessionCommandMocks');
|
||||
return { WebClient: { instance: makeWebClientMock() } };
|
||||
});
|
||||
vi.mock('../../WebClient');
|
||||
|
||||
vi.mock('../../utils', async () => {
|
||||
const { makeUtilsMock } = await import('../../__mocks__/sessionCommandMocks');
|
||||
|
|
@ -19,7 +16,6 @@ vi.mock('./', async () => {
|
|||
|
||||
import { Mock } from 'vitest';
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { useWebClientCleanup } from '../../__mocks__/helpers';
|
||||
import { WebClient } from '../../WebClient';
|
||||
import { hashPassword, generateSalt, passwordSaltSupported } from '../../utils';
|
||||
|
||||
|
|
@ -85,8 +81,6 @@ import {
|
|||
Response_ReplayList_ext,
|
||||
} from '@app/generated';
|
||||
|
||||
useWebClientCleanup();
|
||||
|
||||
const { invokeOnSuccess, invokeCallback } = makeCallbackHelpers(
|
||||
WebClient.instance.protobuf.sendSessionCommand as Mock,
|
||||
2
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { StatusEnum } from '../../StatusEnum';
|
||||
import { StatusEnum } from '../../interfaces/StatusEnum';
|
||||
import { WebClient } from '../../WebClient';
|
||||
|
||||
export function updateStatus(status: StatusEnum, description: string): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue