From a5f5504b0d47eaaf1c0bd756fd2bfdddf2d93e77 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 13 May 2026 04:05:29 +0100 Subject: [PATCH] test: dedupe telegram monitor mock reads --- extensions/telegram/src/monitor.test.ts | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/extensions/telegram/src/monitor.test.ts b/extensions/telegram/src/monitor.test.ts index f617cf57a3e..54e5964fb94 100644 --- a/extensions/telegram/src/monitor.test.ts +++ b/extensions/telegram/src/monitor.test.ts @@ -290,6 +290,14 @@ function expectRecoverableRetryState( expect(runSpy).toHaveBeenCalledTimes(expectedRunCalls); } +function latestMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] { + const call = mock.mock.calls[mock.mock.calls.length - 1]; + if (!call) { + throw new Error(`expected ${label} call`); + } + return call; +} + async function monitorWithAutoAbort(opts: Omit = {}) { const abort = new AbortController(); mockRunOnceAndAbort(abort); @@ -449,8 +457,8 @@ describe("monitorTelegramProvider (grammY)", () => { sink?: { concurrency?: number }; runner?: { silent?: boolean; maxRetryTime?: number; retryInterval?: string }; }; - const runCall = runSpy.mock.calls.at(-1) as unknown as [unknown, RunOptions] | undefined; - const runOptions = runCall?.[1]; + const runCall = latestMockCall(runSpy, "run") as [unknown, RunOptions]; + const runOptions = runCall[1]; expect(runOptions?.sink?.concurrency).toBe(3); expect(runOptions?.runner?.silent).toBe(true); expect(runOptions?.runner?.maxRetryTime).toBe(60 * 60 * 1000); @@ -847,10 +855,10 @@ describe("monitorTelegramProvider (grammY)", () => { }, }); - const webhookCall = startTelegramWebhookSpy.mock.calls.at(-1) as - | [{ host?: string; setStatus?: unknown }] - | undefined; - const webhookOptions = webhookCall?.[0]; + const webhookCall = latestMockCall(startTelegramWebhookSpy, "startTelegramWebhook") as [ + { host?: string; setStatus?: unknown }, + ]; + const webhookOptions = webhookCall[0]; expect(webhookOptions?.host).toBe("0.0.0.0"); expect(webhookOptions?.setStatus).toBe(setStatus); expect(runSpy).not.toHaveBeenCalled(); @@ -1018,10 +1026,10 @@ describe("monitorTelegramProvider (grammY)", () => { }, }); - const webhookCall = startTelegramWebhookSpy.mock.calls.at(-1) as - | [{ secret?: string }] - | undefined; - expect(webhookCall?.[0]?.secret).toBe("secret-from-config"); + const webhookCall = latestMockCall(startTelegramWebhookSpy, "startTelegramWebhook") as [ + { secret?: string }, + ]; + expect(webhookCall[0].secret).toBe("secret-from-config"); expect(runSpy).not.toHaveBeenCalled(); }); });