From 69a1ab23199a7635bb7c8291c59169518ca81393 Mon Sep 17 00:00:00 2001 From: Vignesh Natarajan Date: Sat, 14 Feb 2026 18:57:05 -0800 Subject: [PATCH] test (telegram): assert webhook callback timeout-safe options --- src/telegram/webhook.test.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/telegram/webhook.test.ts b/src/telegram/webhook.test.ts index 6d4850e4db..9681a8b246 100644 --- a/src/telegram/webhook.test.ts +++ b/src/telegram/webhook.test.ts @@ -9,6 +9,7 @@ const handlerSpy = vi.fn( ); const setWebhookSpy = vi.fn(); const stopSpy = vi.fn(); +const webhookCallbackSpy = vi.fn(() => handlerSpy); const createTelegramBotSpy = vi.fn(() => ({ api: { setWebhook: setWebhookSpy }, @@ -17,7 +18,10 @@ const createTelegramBotSpy = vi.fn(() => ({ vi.mock("grammy", async (importOriginal) => { const actual = await importOriginal(); - return { ...actual, webhookCallback: () => handlerSpy }; + return { + ...actual, + webhookCallback: (...args: unknown[]) => webhookCallbackSpy(...args), + }; }); vi.mock("./bot.js", () => ({ @@ -27,6 +31,7 @@ vi.mock("./bot.js", () => ({ describe("startTelegramWebhook", () => { it("starts server, registers webhook, and serves health", async () => { createTelegramBotSpy.mockClear(); + webhookCallbackSpy.mockClear(); const abort = new AbortController(); const cfg = { bindings: [] }; const { server } = await startTelegramWebhook({ @@ -52,6 +57,19 @@ describe("startTelegramWebhook", () => { const health = await fetch(`${url}/healthz`); expect(health.status).toBe(200); expect(setWebhookSpy).toHaveBeenCalled(); + expect(webhookCallbackSpy).toHaveBeenCalledWith( + expect.objectContaining({ + api: expect.objectContaining({ + setWebhook: expect.any(Function), + }), + }), + "http", + { + secretToken: "secret", + onTimeout: "return", + timeoutMilliseconds: 10_000, + }, + ); abort.abort(); });