mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 15:14:45 +00:00
test: guard voice-call realtime mock calls
This commit is contained in:
@@ -135,6 +135,14 @@ async function waitForRealtimeTest(
|
||||
await vi.waitFor(callback, { interval: 1, ...options });
|
||||
}
|
||||
|
||||
function requireFirstMockCall(calls: readonly unknown[][], label: string): unknown[] {
|
||||
const call = calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
describe("RealtimeCallHandler path routing", () => {
|
||||
it("uses the request host and stream path in TwiML", () => {
|
||||
const handler = makeHandler();
|
||||
@@ -224,7 +232,9 @@ describe("RealtimeCallHandler path routing", () => {
|
||||
expect(createBridge).toHaveBeenCalled();
|
||||
});
|
||||
callbacks?.onReady?.();
|
||||
const event = processEvent.mock.calls[0]?.[0] as NormalizedEvent | undefined;
|
||||
const event = requireFirstMockCall(processEvent.mock.calls, "processed event")[0] as
|
||||
| NormalizedEvent
|
||||
| undefined;
|
||||
expect(event?.type).toBe("call.initiated");
|
||||
if (event?.type !== "call.initiated") {
|
||||
throw new Error("expected outbound realtime stream to emit call.initiated");
|
||||
@@ -816,7 +826,7 @@ describe("RealtimeCallHandler path routing", () => {
|
||||
await waitForRealtimeTest(() => {
|
||||
expect(consult).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const [args, callId, context] = consult.mock.calls[0] ?? [];
|
||||
const [args, callId, context] = requireFirstMockCall(consult.mock.calls, "consult");
|
||||
expect(args).toEqual({
|
||||
question: "Create a smoke test file for me.",
|
||||
context:
|
||||
@@ -826,7 +836,7 @@ describe("RealtimeCallHandler path routing", () => {
|
||||
expect(context).toEqual({});
|
||||
await waitForRealtimeTest(() => {
|
||||
expect(sendUserMessage).toHaveBeenCalledTimes(1);
|
||||
expect(sendUserMessage.mock.calls[0]).toEqual([
|
||||
expect(requireFirstMockCall(sendUserMessage.mock.calls, "user message")).toEqual([
|
||||
"Internal OpenClaw consult result is ready.\nDo not call tools for this internal result.\nSpeak the following answer to the caller now, briefly and naturally:\nI created the smoke test file.",
|
||||
]);
|
||||
});
|
||||
@@ -988,7 +998,7 @@ describe("RealtimeCallHandler path routing", () => {
|
||||
},
|
||||
{ timeout: 2_000 },
|
||||
);
|
||||
const [args, callId, context] = consult.mock.calls[0] ?? [];
|
||||
const [args, callId, context] = requireFirstMockCall(consult.mock.calls, "consult");
|
||||
const consultArgs = args as { question?: string; context?: string } | undefined;
|
||||
expect(consultArgs?.question).toBe("Send a Discord message.");
|
||||
expect(consultArgs?.context).toBe(
|
||||
|
||||
Reference in New Issue
Block a user