


















@@ -144,6 +144,14 @@ function requireBoundRequestUrl(server: VoiceCallWebhookServer, baseUrl: string)
144144return requestUrl;
145145}
146146147+function requireFirstMockCall(calls: readonly unknown[][], label: string): unknown[] {
148+const call = calls.at(0);
149+if (!call) {
150+throw new Error(`expected ${label} call`);
151+}
152+return call;
153+}
154+147155function expectWebhookUrl(url: string, expectedPath: string) {
148156const parsed = new URL(url);
149157expect(parsed.pathname).toBe(expectedPath);
@@ -971,15 +979,17 @@ describe("VoiceCallWebhookServer replay handling", () => {
971979972980expect(response.status).toBe(200);
973981expect(parseWebhookEvent).toHaveBeenCalledTimes(1);
974-const parseOptions = parseWebhookEvent.mock.calls[0]?.[1];
982+const parseOptions = requireFirstMockCall(parseWebhookEvent.mock.calls, "webhook parse")[1];
975983if (!parseOptions) {
976984throw new Error("webhook server did not pass verified parse options");
977985}
978986expect(parseOptions).toEqual({
979987verifiedRequestKey: "verified:req:123",
980988});
981989expect(processEvent).toHaveBeenCalledTimes(1);
982-const firstEvent = processEvent.mock.calls[0]?.[0];
990+const firstEvent = requireFirstMockCall(processEvent.mock.calls, "processed event")[0] as
991+| NormalizedEvent
992+| undefined;
983993if (!firstEvent) {
984994throw new Error("webhook server did not forward the parsed event");
985995}
@@ -1477,8 +1487,10 @@ describe("VoiceCallWebhookServer barge-in suppression during initial message", (
14771487expect(clearTtsQueue).toHaveBeenCalledTimes(2);
14781488expect(handleInboundResponse).toHaveBeenCalledTimes(1);
14791489expect(processEvent).toHaveBeenCalledTimes(1);
1480-const [calledCallId, calledTranscript] = (handleInboundResponse.mock.calls[0] ??
1481-[]) as unknown as [string | undefined, string | undefined];
1490+const [calledCallId, calledTranscript] = requireFirstMockCall(
1491+handleInboundResponse.mock.calls,
1492+"inbound response",
1493+) as [string | undefined, string | undefined];
14821494expect(calledCallId).toBe(call.callId);
14831495expect(calledTranscript).toBe("hello after greeting");
14841496} finally {
@@ -1534,7 +1546,9 @@ describe("VoiceCallWebhookServer barge-in suppression during initial message", (
15341546media.config.onTranscript?.("CA-inbound", "hello");
15351547expect(clearTtsQueue).toHaveBeenCalledTimes(2);
15361548expect(processEvent).toHaveBeenCalledTimes(1);
1537-const event = processEvent.mock.calls[0]?.[0] as NormalizedEvent | undefined;
1549+const event = requireFirstMockCall(processEvent.mock.calls, "inbound processed event")[0] as
1550+| NormalizedEvent
1551+| undefined;
15381552expect(event?.type).toBe("call.speech");
15391553if (event?.type !== "call.speech") {
15401554throw new Error("expected media transcript callback to emit a speech event");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。