fix build and lint

This commit is contained in:
seavor 2026-04-12 03:03:01 -05:00
parent 35be723ebf
commit d96d5e1589
8 changed files with 42 additions and 20 deletions

View file

@ -19,7 +19,9 @@ export function makeCallbackHelpers(mockFn: jest.Mock, optsArgIndex = 2) {
function invokeResponseCode(code: number, raw: any = { responseCode: code }) {
const opts = getLastSendOpts();
if (opts?.onResponseCode?.[code]) opts.onResponseCode[code](raw);
if (opts?.onResponseCode?.[code]) {
opts.onResponseCode[code](raw);
}
}
function invokeOnError(code: number = 99, raw: any = {}) {
@ -28,7 +30,9 @@ export function makeCallbackHelpers(mockFn: jest.Mock, optsArgIndex = 2) {
function invokeCallback(callbackName: string, ...args: any[]) {
const opts = getLastSendOpts();
if (opts?.[callbackName]) opts[callbackName](...args);
if (opts?.[callbackName]) {
opts[callbackName](...args);
}
}
return { getLastSendOpts, invokeOnSuccess, invokeResponseCode, invokeOnError, invokeCallback };

View file

@ -13,9 +13,9 @@ export function makeMockProtoRoot() {
encode: jest.fn().mockReturnValue(encode),
},
SessionCommand: { create: jest.fn(args => ({ ...args })) },
RoomCommand: { create: jest.fn(args => ({ ...args })) },
RoomCommand: { create: jest.fn(args => ({ ...args })) },
ModeratorCommand: { create: jest.fn(args => ({ ...args })) },
AdminCommand: { create: jest.fn(args => ({ ...args })) },
AdminCommand: { create: jest.fn(args => ({ ...args })) },
ServerMessage: {
decode: jest.fn(),
MessageType: {

View file

@ -18,7 +18,8 @@ import { RoomPersistence } from '../../persistence';
const { getLastSendOpts, invokeOnSuccess } = makeCallbackHelpers(
BackendService.sendRoomCommand as jest.Mock,
3 // sendRoomCommand(roomId, commandName, params, options) — options at index 3
// sendRoomCommand(roomId, commandName, params, options) — options at index 3
3
);
beforeEach(() => jest.clearAllMocks());

View file

@ -360,7 +360,9 @@ describe('forgotPasswordChallenge', () => {
it('sends Command_ForgotPasswordChallenge', () => {
forgotPasswordChallenge({ userName: 'alice', email: 'a@b.com' } as any);
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_ForgotPasswordChallenge', expect.any(Object), expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_ForgotPasswordChallenge', expect.any(Object), expect.any(Object)
);
});
it('onSuccess calls resetPassword and disconnect', () => {

View file

@ -170,7 +170,9 @@ describe('deckNewDir', () => {
it('sends Command_DeckNewDir', () => {
deckNewDir('/path', 'dir');
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_DeckNewDir', { path: '/path', dirName: 'dir' }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_DeckNewDir', { path: '/path', dirName: 'dir' }, expect.any(Object)
);
});
it('calls createServerDeckDir on success', () => {
@ -295,7 +297,9 @@ describe('message', () => {
it('sends Command_Message', () => {
message('bob', 'hi');
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_Message', { userName: 'bob', message: 'hi' }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_Message', { userName: 'bob', message: 'hi' }, expect.any(Object)
);
});
it('calls directMessageSent on success', () => {
@ -363,7 +367,9 @@ describe('replayModifyMatch', () => {
it('sends Command_ReplayModifyMatch', () => {
replayModifyMatch(7, true);
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_ReplayModifyMatch', { gameId: 7, doNotHide: true }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_ReplayModifyMatch', { gameId: 7, doNotHide: true }, expect.any(Object)
);
});
it('calls replayModifyMatch on success', () => {
@ -379,12 +385,16 @@ describe('addToList / addToBuddyList / addToIgnoreList', () => {
it('addToBuddyList sends Command_AddToList with list=buddy', () => {
addToBuddyList('alice');
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_AddToList', { list: 'buddy', userName: 'alice' }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_AddToList', { list: 'buddy', userName: 'alice' }, expect.any(Object)
);
});
it('addToIgnoreList sends Command_AddToList with list=ignore', () => {
addToIgnoreList('bob');
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_AddToList', { list: 'ignore', userName: 'bob' }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_AddToList', { list: 'ignore', userName: 'bob' }, expect.any(Object)
);
});
it('onSuccess calls SessionPersistence.addToList', () => {
@ -400,12 +410,16 @@ describe('removeFromList / removeFromBuddyList / removeFromIgnoreList', () => {
it('removeFromBuddyList sends Command_RemoveFromList with list=buddy', () => {
removeFromBuddyList('alice');
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_RemoveFromList', { list: 'buddy', userName: 'alice' }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_RemoveFromList', { list: 'buddy', userName: 'alice' }, expect.any(Object)
);
});
it('removeFromIgnoreList sends Command_RemoveFromList with list=ignore', () => {
removeFromIgnoreList('bob');
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith('Command_RemoveFromList', { list: 'ignore', userName: 'bob' }, expect.any(Object));
expect(BackendService.sendSessionCommand).toHaveBeenCalledWith(
'Command_RemoveFromList', { list: 'ignore', userName: 'bob' }, expect.any(Object)
);
});
it('onSuccess calls SessionPersistence.removeFromList', () => {

View file

@ -34,11 +34,11 @@ function captureCallback(sendFn: jest.Mock) {
describe('BackendService', () => {
describe('send commands', () => {
it.each<[string, () => void]>([
it.each([
['sendSessionCommand', () => BackendService.sendSessionCommand('Command_Test', { x: 1 }, {})],
['sendRoomCommand', () => BackendService.sendRoomCommand(5, 'Command_Room', { y: 2 }, {})],
['sendRoomCommand', () => BackendService.sendRoomCommand(5, 'Command_Room', { y: 2 }, {})],
['sendModeratorCommand', () => BackendService.sendModeratorCommand('Command_Mod', { z: 3 }, {})],
['sendAdminCommand', () => BackendService.sendAdminCommand('Command_Admin', {}, {})],
['sendAdminCommand', () => BackendService.sendAdminCommand('Command_Admin', {}, {})],
])('%s creates the command and delegates to protobuf', (methodName, invoke) => {
invoke();
expect((webClient.protobuf as any)[methodName]).toHaveBeenCalled();

View file

@ -23,7 +23,7 @@ describe('ProtoController', () => {
it('calls initialized when callback succeeds', () => {
const loadSpy = jest.spyOn(protobuf.Root.prototype, 'load').mockImplementation(
(_files: any, _opts: any, cb: any) => cb(null)
((_files: any, _opts: any, cb: any) => cb(null)) as any
);
ProtoController.load();
expect(SessionPersistence.initialized).toHaveBeenCalled();
@ -32,7 +32,7 @@ describe('ProtoController', () => {
it('throws when callback receives an error', () => {
const loadSpy = jest.spyOn(protobuf.Root.prototype, 'load').mockImplementation(
(_files: any, _opts: any, cb: any) => cb(new Error('load failed'))
((_files: any, _opts: any, cb: any) => cb(new Error('load failed'))) as any
);
expect(() => ProtoController.load()).toThrow('load failed');
loadSpy.mockRestore();

View file

@ -131,7 +131,7 @@ describe('WebSocketService', () => {
const startSpy = jest.spyOn((service as any).keepAliveService, 'startPingLoop');
service.connect({ host: 'h', port: 1 } as any, 'ws');
mockInstance.onopen();
const pingCb = startSpy.mock.calls[0][1];
const pingCb = startSpy.mock.calls[0][1] as (done: Function) => void;
const done = jest.fn();
pingCb(done);
expect(mockWebClient.keepAlive).toHaveBeenCalledWith(done);
@ -212,7 +212,8 @@ describe('WebSocketService', () => {
it('returns false when readyState does not match', () => {
const service = createConnectedService();
mockInstance.readyState = 3; // CLOSED
// CLOSED
mockInstance.readyState = 3;
expect(service.checkReadyState(WebSocket.OPEN)).toBe(false);
});