mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor: preserve explicit mock voice-call values
This commit is contained in:
78
extensions/voice-call/src/providers/mock.test.ts
Normal file
78
extensions/voice-call/src/providers/mock.test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { WebhookContext } from "../types.js";
|
||||
import { MockProvider } from "./mock.js";
|
||||
|
||||
function createWebhookContext(rawBody: string): WebhookContext {
|
||||
return {
|
||||
headers: {},
|
||||
rawBody,
|
||||
url: "http://localhost/voice/webhook",
|
||||
method: "POST",
|
||||
query: {},
|
||||
};
|
||||
}
|
||||
|
||||
describe("MockProvider", () => {
|
||||
it("preserves explicit falsy event values", () => {
|
||||
const provider = new MockProvider();
|
||||
const result = provider.parseWebhookEvent(
|
||||
createWebhookContext(
|
||||
JSON.stringify({
|
||||
events: [
|
||||
{
|
||||
id: "evt-error",
|
||||
type: "call.error",
|
||||
callId: "call-1",
|
||||
timestamp: 0,
|
||||
error: "",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
id: "evt-ended",
|
||||
type: "call.ended",
|
||||
callId: "call-2",
|
||||
reason: "",
|
||||
},
|
||||
{
|
||||
id: "evt-speech",
|
||||
type: "call.speech",
|
||||
callId: "call-3",
|
||||
transcript: "",
|
||||
isFinal: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
expect(result.events).toEqual([
|
||||
{
|
||||
id: "evt-error",
|
||||
type: "call.error",
|
||||
callId: "call-1",
|
||||
providerCallId: undefined,
|
||||
timestamp: 0,
|
||||
error: "",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
id: "evt-ended",
|
||||
type: "call.ended",
|
||||
callId: "call-2",
|
||||
providerCallId: undefined,
|
||||
timestamp: expect.any(Number),
|
||||
reason: "",
|
||||
},
|
||||
{
|
||||
id: "evt-speech",
|
||||
type: "call.speech",
|
||||
callId: "call-3",
|
||||
providerCallId: undefined,
|
||||
timestamp: expect.any(Number),
|
||||
transcript: "",
|
||||
isFinal: false,
|
||||
confidence: undefined,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -65,10 +65,10 @@ export class MockProvider implements VoiceCallProvider {
|
||||
}
|
||||
|
||||
const base = {
|
||||
id: evt.id || crypto.randomUUID(),
|
||||
id: evt.id ?? crypto.randomUUID(),
|
||||
callId: evt.callId,
|
||||
providerCallId: evt.providerCallId,
|
||||
timestamp: evt.timestamp || Date.now(),
|
||||
timestamp: evt.timestamp ?? Date.now(),
|
||||
};
|
||||
|
||||
switch (evt.type) {
|
||||
@@ -83,7 +83,7 @@ export class MockProvider implements VoiceCallProvider {
|
||||
return {
|
||||
...base,
|
||||
type: evt.type,
|
||||
text: payload.text || "",
|
||||
text: payload.text ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ export class MockProvider implements VoiceCallProvider {
|
||||
return {
|
||||
...base,
|
||||
type: evt.type,
|
||||
transcript: payload.transcript || "",
|
||||
transcript: payload.transcript ?? "",
|
||||
isFinal: payload.isFinal ?? true,
|
||||
confidence: payload.confidence,
|
||||
};
|
||||
@@ -109,7 +109,7 @@ export class MockProvider implements VoiceCallProvider {
|
||||
return {
|
||||
...base,
|
||||
type: evt.type,
|
||||
durationMs: payload.durationMs || 0,
|
||||
durationMs: payload.durationMs ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export class MockProvider implements VoiceCallProvider {
|
||||
return {
|
||||
...base,
|
||||
type: evt.type,
|
||||
digits: payload.digits || "",
|
||||
digits: payload.digits ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ export class MockProvider implements VoiceCallProvider {
|
||||
return {
|
||||
...base,
|
||||
type: evt.type,
|
||||
reason: payload.reason || "completed",
|
||||
reason: payload.reason ?? "completed",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ export class MockProvider implements VoiceCallProvider {
|
||||
return {
|
||||
...base,
|
||||
type: evt.type,
|
||||
error: payload.error || "unknown error",
|
||||
error: payload.error ?? "unknown error",
|
||||
retryable: payload.retryable,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user