From aa97e92b419b48b2147e6efb9206f1347afede0f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 20:10:00 +0100 Subject: [PATCH] test: tighten voice call restore assertions --- .../voice-call/src/manager.restore.test.ts | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/extensions/voice-call/src/manager.restore.test.ts b/extensions/voice-call/src/manager.restore.test.ts index b00c4f8a8e3..6676b175de4 100644 --- a/extensions/voice-call/src/manager.restore.test.ts +++ b/extensions/voice-call/src/manager.restore.test.ts @@ -19,6 +19,18 @@ function requireSingleActiveCall(manager: CallManager) { return activeCall; } +function requireRecord(value: unknown, label: string): Record { + if (value === null || typeof value !== "object" || Array.isArray(value)) { + throw new Error(`expected ${label} to be a record`); + } + return value as Record; +} + +function requireSingleHangupCall(provider: FakeProvider) { + expect(provider.hangupCalls).toHaveLength(1); + return requireRecord(provider.hangupCalls[0], "hangup call"); +} + describe("CallManager verification on restore", () => { afterEach(() => { vi.useRealTimers(); @@ -90,11 +102,8 @@ describe("CallManager verification on restore", () => { }); expect(manager.getActiveCalls()).toHaveLength(0); - expect(provider.hangupCalls).toEqual([ - expect.objectContaining({ - reason: "timeout", - }), - ]); + const hangupCall = requireSingleHangupCall(provider); + expect(hangupCall.reason).toBe("timeout"); await flushPendingCallRecordWritesForTest(); expect(loadActiveCallsFromStore(storePath).activeCalls.size).toBe(0); @@ -215,13 +224,10 @@ describe("CallManager verification on restore", () => { .map((call) => call.callId) .toSorted(), ).toEqual(["active-a", "failure-a", "unknown-a"]); - expect(provider.hangupCalls).toEqual([ - expect.objectContaining({ - callId: "expired-a", - providerCallId: "expired-provider-a", - reason: "timeout", - }), - ]); + const hangupCall = requireSingleHangupCall(provider); + expect(hangupCall.callId).toBe("expired-a"); + expect(hangupCall.providerCallId).toBe("expired-provider-a"); + expect(hangupCall.reason).toBe("timeout"); expect(logSpy).toHaveBeenCalledWith( "[voice-call] Skipped 2 restored call(s) with no providerCallId", ); @@ -265,11 +271,8 @@ describe("CallManager verification on restore", () => { await vi.advanceTimersByTimeAsync(1_100); expect(manager.getActiveCalls()).toHaveLength(0); - expect(provider.hangupCalls).toEqual([ - expect.objectContaining({ - reason: "timeout", - }), - ]); + const hangupCall = requireSingleHangupCall(provider); + expect(hangupCall.reason).toBe("timeout"); }); it("restores dedupe keys from terminal persisted calls so replayed webhooks stay ignored", async () => {