mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:40:44 +00:00
test(voice-call): share active call context helper
This commit is contained in:
@@ -50,6 +50,21 @@ vi.mock("./twiml.js", () => ({
|
||||
|
||||
import { endCall, initiateCall, speak } from "./outbound.js";
|
||||
|
||||
function createActiveCallContext(params: { hangupCall?: ReturnType<typeof vi.fn> } = {}) {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user