37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { test, expect, describe } from "bun:test";
|
|
import { AstraCallsClient } from "../../src/infrastructure/astracalls/astracalls-client.ts";
|
|
|
|
describe("AstraCallsClient", () => {
|
|
test("sendText: envia mensagem com bearer token", async () => {
|
|
let capturedHeaders: any = null;
|
|
const mockFetch = async (url: string, options: any) => {
|
|
capturedHeaders = options.headers;
|
|
return new Response(JSON.stringify({
|
|
jsonrpc: "2.0", id: 1,
|
|
result: { content: [{ type: "text", text: JSON.stringify({ messageId: "ok" }) }] }
|
|
}), { status: 200, headers: { "content-type": "application/json" } });
|
|
};
|
|
|
|
const c = new AstraCallsClient({
|
|
mcpUrl: "https://astra.test/mcp",
|
|
bearerToken: "my-secret-token",
|
|
}, mockFetch as any);
|
|
|
|
await c.sendText("5527999998888", "teste");
|
|
expect(capturedHeaders?.Authorization).toBe("Bearer my-secret-token");
|
|
});
|
|
|
|
test("sendText: timeout de 15s respeitado", async () => {
|
|
const mockFetch = async (url: string, options: any) => {
|
|
expect(options.signal).toBeDefined();
|
|
return new Response(JSON.stringify({
|
|
jsonrpc: "2.0", id: 1,
|
|
result: { content: [{ type: "text", text: JSON.stringify({ messageId: "ok" }) }] }
|
|
}), { status: 200, headers: { "content-type": "application/json" } });
|
|
};
|
|
|
|
const c = new AstraCallsClient({ mcpUrl: "https://astra.test/mcp" }, mockFetch as any);
|
|
await c.sendText("5527999998888", "teste");
|
|
});
|
|
});
|