From fc5ba0e58bb43903054ee03cf0970ccaaa9e6566 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Tue, 30 Jun 2026 22:44:55 -0700 Subject: [PATCH] test(gateway): remove cron redaction casts --- src/gateway/server-cron-notifications.test.ts | 23 ++++++++++------ src/gateway/server-cron.test.ts | 26 +++++++++---------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/gateway/server-cron-notifications.test.ts b/src/gateway/server-cron-notifications.test.ts index beff902930e6..4811a27f04e7 100644 --- a/src/gateway/server-cron-notifications.test.ts +++ b/src/gateway/server-cron-notifications.test.ts @@ -23,6 +23,19 @@ vi.mock("../cron/delivery.js", async (importOriginal) => { import { dispatchGatewayCronFinishedNotifications } from "./server-cron-notifications.js"; +function requireRecord(value: unknown, label: string): Record { + if (!value || typeof value !== "object") { + throw new Error(`expected ${label}`); + } + return value as Record; +} + +function webhookRequestBody() { + const request = requireRecord(mocks.fetchWithSsrFGuard.mock.calls[0]?.[0], "webhook request"); + const init = requireRecord(request.init, "webhook request init"); + return JSON.parse(String(init.body)); +} + describe("dispatchGatewayCronFinishedNotifications", () => { beforeEach(() => { vi.clearAllMocks(); @@ -182,10 +195,7 @@ describe("dispatchGatewayCronFinishedNotifications", () => { }); await vi.waitFor(() => expect(mocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1)); - const [request] = mocks.fetchWithSsrFGuard.mock.calls[0] as unknown as [ - { init?: { body?: string } }, - ]; - const body = JSON.parse(String(request.init?.body)); + const body = webhookRequestBody(); expect(body.summary).toContain("[redacted-url]"); expect(body.summary).toContain("[redacted-code]"); expect(body.summary).toContain("token=***"); @@ -267,10 +277,7 @@ describe("dispatchGatewayCronFinishedNotifications", () => { }); await vi.waitFor(() => expect(mocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1)); - const [request] = mocks.fetchWithSsrFGuard.mock.calls[0] as unknown as [ - { init?: { body?: string } }, - ]; - const body = JSON.parse(String(request.init?.body)); + const body = webhookRequestBody(); expect(body).toMatchObject({ action: "finished", jobId: job.id, diff --git a/src/gateway/server-cron.test.ts b/src/gateway/server-cron.test.ts index 6a72ac9fd559..0ee2a09d4453 100644 --- a/src/gateway/server-cron.test.ts +++ b/src/gateway/server-cron.test.ts @@ -620,12 +620,10 @@ describe("buildGatewayCronService", () => { runCronChangedMock.mockClear(); await state.cron.run(job.id, "force"); - const hookEvents = runCronChangedMock.mock.calls as unknown as Array< - [{ action?: string; summary?: string }] - >; - const event = hookEvents.find(([hookEvent]) => hookEvent.action === "finished")?.[0]; - expect(event).toBeDefined(); - const summary = event?.summary ?? ""; + const event = runCronChangedMock.mock.calls + .map((call) => requireRecord(call[0], "cron_changed event")) + .find((hookEvent) => hookEvent.action === "finished"); + const summary = String(event?.summary ?? ""); expect(summary).toContain("[redacted-url]"); expect(summary).toContain("[redacted-code]"); expect(summary).toContain("token=***"); @@ -671,10 +669,11 @@ describe("buildGatewayCronService", () => { await state.cron.run(job.id, "force"); - const announceCalls = sendCronAnnouncePayloadStrictMock.mock.calls as unknown as Array< - [{ message?: string }] - >; - const message = announceCalls[0]?.[0]?.message ?? ""; + const announcePayload = requireRecord( + callArg(sendCronAnnouncePayloadStrictMock, 0, 0, "cron announce payload"), + "cron announce payload", + ); + const message = String(announcePayload.message ?? ""); expect(message).toContain("token=***"); expect(message).not.toContain("opaque-secret-value"); } finally { @@ -714,10 +713,9 @@ describe("buildGatewayCronService", () => { expect(sendCronAnnouncePayloadStrictMock).not.toHaveBeenCalled(); - const hookEvents = runCronChangedMock.mock.calls as unknown as Array< - [{ action?: string; summary?: string }] - >; - const event = hookEvents.find(([hookEvent]) => hookEvent.action === "finished")?.[0]; + const event = runCronChangedMock.mock.calls + .map((call) => requireRecord(call[0], "cron_changed event")) + .find((hookEvent) => hookEvent.action === "finished"); expect(event?.summary).toBe(summary); } finally { state.cron.stop();