From 21c00165efd3d7f4a3e7f68aed9e6363da8cb7ea Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Sat, 28 Mar 2026 01:11:24 -0400 Subject: [PATCH] test: fix gateway handler and typing lease helper types --- .../server-methods/channels.status.test.ts | 41 +++++++++++++------ .../runtime/typing-lease.test-support.ts | 11 ++--- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/gateway/server-methods/channels.status.test.ts b/src/gateway/server-methods/channels.status.test.ts index c90a02e00e2..a5871380e19 100644 --- a/src/gateway/server-methods/channels.status.test.ts +++ b/src/gateway/server-methods/channels.status.test.ts @@ -1,4 +1,5 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { GatewayRequestHandlerOptions } from "./types.js"; const mocks = vi.hoisted(() => ({ loadConfig: vi.fn(), @@ -42,6 +43,26 @@ vi.mock("../../infra/channel-activity.js", () => ({ import { channelsHandlers } from "./channels.js"; +function createOptions( + params: Record, + overrides?: Partial, +): GatewayRequestHandlerOptions { + return { + req: { type: "req", id: "req-1", method: "channels.status", params }, + params, + client: null, + isWebchatConnect: () => false, + respond: vi.fn(), + context: { + getRuntimeSnapshot: () => ({ + channels: {}, + channelAccounts: {}, + }), + }, + ...overrides, + } as unknown as GatewayRequestHandlerOptions; +} + describe("channelsHandlers channels.status", () => { beforeEach(() => { vi.clearAllMocks(); @@ -80,20 +101,14 @@ describe("channelsHandlers channels.status", () => { const autoEnabledConfig = { autoEnabled: true }; mocks.applyPluginAutoEnable.mockReturnValue({ config: autoEnabledConfig, changes: [] }); const respond = vi.fn(); + const opts = createOptions( + { probe: false, timeoutMs: 2000 }, + { + respond, + }, + ); - await channelsHandlers["channels.status"]({ - req: {} as never, - params: { probe: false, timeoutMs: 2000 } as never, - client: null, - isWebchatConnect: () => false, - respond, - context: { - getRuntimeSnapshot: () => ({ - channels: {}, - channelAccounts: {}, - }), - } as never, - }); + await channelsHandlers["channels.status"](opts); expect(mocks.applyPluginAutoEnable).toHaveBeenCalledWith({ config: {}, diff --git a/src/plugins/runtime/typing-lease.test-support.ts b/src/plugins/runtime/typing-lease.test-support.ts index f4a8406b981..b4fec61c017 100644 --- a/src/plugins/runtime/typing-lease.test-support.ts +++ b/src/plugins/runtime/typing-lease.test-support.ts @@ -1,4 +1,5 @@ import { expect, vi } from "vitest"; +import type { MockFn } from "../../test-utils/vitest-mock-fn.js"; export function expectTypingPulseCount(pulse: { mock: { calls: unknown[] } }, expected: number) { expect(pulse.mock.calls).toHaveLength(expected); @@ -8,13 +9,13 @@ export function createPulseWithBackgroundFailure< TPulse extends (...args: never[]) => Promise, >() { let callCount = 0; - const pulse = vi.fn((() => { + const pulse: MockFn = vi.fn(async () => { callCount += 1; if (callCount === 2) { - return Promise.reject(new Error("boom")); + throw new Error("boom"); } - return Promise.resolve(undefined); - }) as TPulse); + return undefined; + }) as MockFn; return pulse; } @@ -26,7 +27,7 @@ export async function expectIndependentTypingLeases< buildParams: (pulse: TParams["pulse"]) => TParams; }) { vi.useFakeTimers(); - const pulse = vi.fn(async () => undefined) as TParams["pulse"]; + const pulse: MockFn = vi.fn(async () => undefined) as MockFn; const leaseA = await params.createLease(params.buildParams(pulse)); const leaseB = await params.createLease(params.buildParams(pulse));