diff --git a/extensions/voice-call/src/manager/outbound.test.ts b/extensions/voice-call/src/manager/outbound.test.ts index 33d64fff565..a2ad2da972c 100644 --- a/extensions/voice-call/src/manager/outbound.test.ts +++ b/extensions/voice-call/src/manager/outbound.test.ts @@ -50,6 +50,21 @@ vi.mock("./twiml.js", () => ({ import { endCall, initiateCall, speak } from "./outbound.js"; +function createActiveCallContext(params: { hangupCall?: ReturnType } = {}) { + const call = { callId: "call-1", providerCallId: "provider-1", state: "active" }; + const hangupCall = params.hangupCall ?? vi.fn(async () => {}); + const ctx = { + activeCalls: new Map([["call-1", call]]), + providerCallIdMap: new Map([["provider-1", "call-1"]]), + provider: { hangupCall }, + storePath: "/tmp/voice-call.json", + transcriptWaiters: new Map(), + maxDurationTimers: new Map(), + }; + + return { call, ctx, hangupCall }; +} + describe("voice-call outbound helpers", () => { beforeEach(() => { vi.clearAllMocks(); @@ -212,16 +227,7 @@ describe("voice-call outbound helpers", () => { }); it("ends connected calls, clears timers, and rejects pending transcripts", async () => { - const call = { callId: "call-1", providerCallId: "provider-1", state: "active" }; - const hangupCall = vi.fn(async () => {}); - const ctx = { - activeCalls: new Map([["call-1", call]]), - providerCallIdMap: new Map([["provider-1", "call-1"]]), - provider: { hangupCall }, - storePath: "/tmp/voice-call.json", - transcriptWaiters: new Map(), - maxDurationTimers: new Map(), - }; + const { call, ctx, hangupCall } = createActiveCallContext(); await expect(endCall(ctx as never, "call-1")).resolves.toEqual({ success: true }); expect(hangupCall).toHaveBeenCalledWith({ @@ -250,16 +256,7 @@ describe("voice-call outbound helpers", () => { }); it("preserves timeout reasons when ending timed out calls", async () => { - const call = { callId: "call-1", providerCallId: "provider-1", state: "active" }; - const hangupCall = vi.fn(async () => {}); - const ctx = { - activeCalls: new Map([["call-1", call]]), - providerCallIdMap: new Map([["provider-1", "call-1"]]), - provider: { hangupCall }, - storePath: "/tmp/voice-call.json", - transcriptWaiters: new Map(), - maxDurationTimers: new Map(), - }; + const { call, ctx, hangupCall } = createActiveCallContext(); await expect(endCall(ctx as never, "call-1", { reason: "timeout" })).resolves.toEqual({ success: true,