



























@@ -154,10 +154,9 @@ describe("voice-call outbound helpers", () => {
154154mode: "notify",
155155message: "hello there",
156156});
157-expect(result).toEqual({
158-callId: expect.any(String),
159-success: true,
160-});
157+expect(result.success).toBe(true);
158+expect(result.callId).toBeTypeOf("string");
159+expect(result.callId).not.toBe("");
161160const callId = result.callId;
162161163162expect(mapVoiceToPollyMock).toHaveBeenCalledWith("nova");
@@ -192,10 +191,9 @@ describe("voice-call outbound helpers", () => {
192191193192const result = await initiateCall(ctx as never, "+14155550123");
194193195-expect(result).toEqual({
196-callId: expect.any(String),
197-success: true,
198-});
194+expect(result.success).toBe(true);
195+expect(result.callId).toBeTypeOf("string");
196+expect(result.callId).not.toBe("");
199197expect(ctx.activeCalls.get(result.callId)?.sessionKey).toBe(`voice:call:${result.callId}`);
200198});
201199@@ -220,10 +218,9 @@ describe("voice-call outbound helpers", () => {
220218dtmfSequence: "ww123456#",
221219});
222220223-expect(result).toEqual({
224-callId: expect.any(String),
225-success: true,
226-});
221+expect(result.success).toBe(true);
222+expect(result.callId).toBeTypeOf("string");
223+expect(result.callId).not.toBe("");
227224const callId = result.callId;
228225229226expect(generateDtmfRedirectTwimlMock).toHaveBeenCalledWith(
@@ -292,11 +289,11 @@ describe("voice-call outbound helpers", () => {
292289webhookUrl: "https://example.com/webhook",
293290};
294291295-await expect(initiateCall(ctx as never, "+14155550123")).resolves.toEqual({
296- callId: expect.any(String),
297- success: false,
298- error: "provider down",
299-});
292+const result = await initiateCall(ctx as never, "+14155550123");
293+expect(result.success).toBe(false);
294+expect(result.error).toBe("provider down");
295+expect(result.callId).toBeTypeOf("string");
296+expect(result.callId).not.toBe("");
300297expect(ctx.activeCalls.size).toBe(0);
301298});
302299@@ -443,18 +440,21 @@ describe("voice-call outbound helpers", () => {
443440it("ends connected calls, clears timers, and rejects pending transcripts", async () => {
444441const { call, ctx, hangupCall } = createActiveCallContext();
445442443+const beforeEndMs = Date.now();
446444await expect(endCall(ctx as never, "call-1")).resolves.toEqual({ success: true });
445+const afterEndMs = Date.now();
447446expect(hangupCall).toHaveBeenCalledWith({
448447callId: "call-1",
449448providerCallId: "provider-1",
450449reason: "hangup-bot",
451450});
452-expect(call).toEqual(
453-expect.objectContaining({
454-endReason: "hangup-bot",
455-endedAt: expect.any(Number),
456-}),
457-);
451+expect(call).toMatchObject({ endReason: "hangup-bot" });
452+const endedAt = (call as { endedAt?: unknown }).endedAt;
453+expect(endedAt).toBeTypeOf("number");
454+if (typeof endedAt === "number") {
455+expect(endedAt).toBeGreaterThanOrEqual(beforeEndMs);
456+expect(endedAt).toBeLessThanOrEqual(afterEndMs);
457+}
458458expect(transitionStateMock).toHaveBeenCalledWith(call, "hangup-bot");
459459expect(clearMaxDurationTimerMock).toHaveBeenCalledWith(
460460{ maxDurationTimers: ctx.maxDurationTimers },
@@ -472,20 +472,23 @@ describe("voice-call outbound helpers", () => {
472472it("preserves timeout reasons when ending timed out calls", async () => {
473473const { call, ctx, hangupCall } = createActiveCallContext();
474474475+const beforeEndMs = Date.now();
475476await expect(endCall(ctx as never, "call-1", { reason: "timeout" })).resolves.toEqual({
476477success: true,
477478});
479+const afterEndMs = Date.now();
478480expect(hangupCall).toHaveBeenCalledWith({
479481callId: "call-1",
480482providerCallId: "provider-1",
481483reason: "timeout",
482484});
483-expect(call).toEqual(
484-expect.objectContaining({
485-endReason: "timeout",
486-endedAt: expect.any(Number),
487-}),
488-);
485+expect(call).toMatchObject({ endReason: "timeout" });
486+const endedAt = (call as { endedAt?: unknown }).endedAt;
487+expect(endedAt).toBeTypeOf("number");
488+if (typeof endedAt === "number") {
489+expect(endedAt).toBeGreaterThanOrEqual(beforeEndMs);
490+expect(endedAt).toBeLessThanOrEqual(afterEndMs);
491+}
489492expect(transitionStateMock).toHaveBeenCalledWith(call, "timeout");
490493expect(rejectTranscriptWaiterMock).toHaveBeenCalledWith(
491494{ transcriptWaiters: ctx.transcriptWaiters },
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。