test(voice): cover gateway last-channel whatsapp
This commit is contained in:
@@ -108,6 +108,70 @@ async function startServerWithClient(token?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("gateway server", () => {
|
describe("gateway server", () => {
|
||||||
|
test("agent routes main last-channel whatsapp", async () => {
|
||||||
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-"));
|
||||||
|
testSessionStorePath = path.join(dir, "sessions.json");
|
||||||
|
await fs.writeFile(
|
||||||
|
testSessionStorePath,
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
main: {
|
||||||
|
sessionId: "sess-main-whatsapp",
|
||||||
|
updatedAt: Date.now(),
|
||||||
|
lastChannel: "whatsapp",
|
||||||
|
lastTo: "+1555",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
"utf-8",
|
||||||
|
);
|
||||||
|
|
||||||
|
const { server, ws } = await startServerWithClient();
|
||||||
|
ws.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "hello",
|
||||||
|
minProtocol: 1,
|
||||||
|
maxProtocol: 1,
|
||||||
|
client: { name: "test", version: "1", platform: "test", mode: "test" },
|
||||||
|
caps: [],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await onceMessage(ws, (o) => o.type === "hello-ok");
|
||||||
|
|
||||||
|
ws.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "req",
|
||||||
|
id: "agent-last-whatsapp",
|
||||||
|
method: "agent",
|
||||||
|
params: {
|
||||||
|
message: "hi",
|
||||||
|
sessionKey: "main",
|
||||||
|
channel: "last",
|
||||||
|
deliver: true,
|
||||||
|
idempotencyKey: "idem-agent-last-whatsapp",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await onceMessage(
|
||||||
|
ws,
|
||||||
|
(o) => o.type === "res" && o.id === "agent-last-whatsapp",
|
||||||
|
);
|
||||||
|
|
||||||
|
const spy = vi.mocked(agentCommand);
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
const call = spy.mock.calls.at(-1)?.[0] as Record<string, unknown>;
|
||||||
|
expect(call.provider).toBe("whatsapp");
|
||||||
|
expect(call.to).toBe("+1555");
|
||||||
|
expect(call.deliver).toBe(true);
|
||||||
|
expect(call.bestEffortDeliver).toBe(true);
|
||||||
|
expect(call.sessionId).toBe("sess-main-whatsapp");
|
||||||
|
|
||||||
|
ws.close();
|
||||||
|
await server.close();
|
||||||
|
});
|
||||||
|
|
||||||
test("agent routes main last-channel telegram", async () => {
|
test("agent routes main last-channel telegram", async () => {
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-"));
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-gw-"));
|
||||||
testSessionStorePath = path.join(dir, "sessions.json");
|
testSessionStorePath = path.join(dir, "sessions.json");
|
||||||
|
|||||||
Reference in New Issue
Block a user