- Monitor de tabelas de planos de saúde prestes a vencer/vencidas - Stack: Bun + Hono + SQLite + Zod + date-fns - Alertas via Telegram e WhatsApp (AstraCalls MCP) - UI de configuração estilo Apple/Planium em /configs - Scheduler periódico com intervalo configurável - Testes unitários e de integração (30 testes passando) Co-Authored-By: Coder <coder@agent.local> Co-Authored-By: Review <review@agent.local> Co-Authored-By: Testing <testing@agent.local>
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);
|
|
|
|
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);
|
|
await c.sendText("5527999998888", "teste");
|
|
});
|
|
});
|