feat: initial commit - Table Expiration Watcher
- 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>
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
|
||||
import { SqliteTableRepository, SqliteAlertRepository, SqliteCheckResultRepository } from "../../src/infrastructure/sqlite/repositories.ts";
|
||||
import type { TableInfo, ExpiryAlert, CheckResult } from "../../src/domain/models/table.ts";
|
||||
import { unlinkSync, existsSync } from "fs";
|
||||
|
||||
const TEST_DB = "./data/test-tables.db";
|
||||
|
||||
function cleanup() {
|
||||
if (existsSync(TEST_DB)) unlinkSync(TEST_DB);
|
||||
if (existsSync(TEST_DB + "-journal")) unlinkSync(TEST_DB + "-journal");
|
||||
}
|
||||
|
||||
describe("SQLite Repositories", () => {
|
||||
let tableRepo: SqliteTableRepository;
|
||||
let alertRepo: SqliteAlertRepository;
|
||||
let checkRepo: SqliteCheckResultRepository;
|
||||
|
||||
beforeEach(() => {
|
||||
cleanup();
|
||||
tableRepo = new SqliteTableRepository(TEST_DB);
|
||||
alertRepo = new SqliteAlertRepository(TEST_DB);
|
||||
checkRepo = new SqliteCheckResultRepository(TEST_DB);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("TableRepository: save e getById", () => {
|
||||
const table: TableInfo = {
|
||||
id: "test-uuid-1",
|
||||
title: "Plano Teste",
|
||||
operadora: "Operadora X",
|
||||
administradora: "Admin Y",
|
||||
revision_date: "Novembro/2027",
|
||||
download_pdf: "https://example.com/pdf",
|
||||
vigencia: "01/11/2027",
|
||||
produtos_json: { _meta: { extracted_at: "2026-01-01" }, produtos: [] },
|
||||
status: "vigente",
|
||||
extracted_at: "2026-01-01T00:00:00.000Z",
|
||||
last_checked: "2026-01-01T00:00:00.000Z",
|
||||
};
|
||||
|
||||
tableRepo.save(table);
|
||||
const retrieved = tableRepo.getById("test-uuid-1");
|
||||
|
||||
expect(retrieved).not.toBeNull();
|
||||
expect(retrieved?.title).toBe("Plano Teste");
|
||||
expect(retrieved?.operadora).toBe("Operadora X");
|
||||
expect(retrieved?.status).toBe("vigente");
|
||||
expect(retrieved?.produtos_json).toBeDefined();
|
||||
});
|
||||
|
||||
test("TableRepository: getAll e getByStatus", () => {
|
||||
const tables: TableInfo[] = [
|
||||
{ id: "1", title: "A", operadora: "Op1", administradora: "Adm1", revision_date: "Dezembro/2027", download_pdf: null, vigencia: null, produtos_json: null, status: "vigente", extracted_at: null, last_checked: "2026-01-01" },
|
||||
{ id: "2", title: "B", operadora: "Op2", administradora: "Adm2", revision_date: "Outubro/2026", download_pdf: null, vigencia: null, produtos_json: null, status: "vencida", extracted_at: null, last_checked: "2026-01-01" },
|
||||
{ id: "3", title: "C", operadora: "Op1", administradora: "Adm1", revision_date: "Novembro/2026", download_pdf: null, vigencia: null, produtos_json: null, status: "prestes_a_vencer", extracted_at: null, last_checked: "2026-01-01" },
|
||||
];
|
||||
|
||||
tables.forEach(t => tableRepo.save(t));
|
||||
|
||||
const all = tableRepo.getAll();
|
||||
expect(all.length).toBe(3);
|
||||
|
||||
const vigentes = tableRepo.getByStatus("vigente");
|
||||
expect(vigentes.length).toBe(1);
|
||||
expect(vigentes[0].id).toBe("1");
|
||||
|
||||
const vencidas = tableRepo.getByStatus("vencida");
|
||||
expect(vencidas.length).toBe(1);
|
||||
|
||||
const prestes = tableRepo.getByStatus("prestes_a_vencer");
|
||||
expect(prestes.length).toBe(1);
|
||||
});
|
||||
|
||||
test("TableRepository: updateStatus", () => {
|
||||
const table: TableInfo = { id: "status-test", title: "Status Test", operadora: "Op", administradora: null, revision_date: "Janeiro/2027", download_pdf: null, vigencia: null, produtos_json: null, status: "vigente", extracted_at: null, last_checked: "2026-01-01" };
|
||||
tableRepo.save(table);
|
||||
|
||||
tableRepo.updateStatus("status-test", "vencida");
|
||||
const updated = tableRepo.getById("status-test");
|
||||
expect(updated?.status).toBe("vencida");
|
||||
});
|
||||
|
||||
test("AlertRepository: save e getUnsentAlerts", () => {
|
||||
const alert: ExpiryAlert = {
|
||||
table_id: "table-1",
|
||||
table_title: "Plano Alerta",
|
||||
operadora: "Op Alert",
|
||||
administradora: "Adm Alert",
|
||||
revision_date: "Outubro/2026",
|
||||
days_until_expiry: -2,
|
||||
severity: "expired",
|
||||
alert_sent_at: null,
|
||||
channels: [],
|
||||
};
|
||||
|
||||
alertRepo.save(alert);
|
||||
const unsent = alertRepo.getUnsentAlerts();
|
||||
|
||||
expect(unsent.length).toBeGreaterThanOrEqual(1);
|
||||
const found = unsent.find(a => a.table_id === "table-1");
|
||||
expect(found).toBeDefined();
|
||||
expect(found?.severity).toBe("expired");
|
||||
});
|
||||
|
||||
test("AlertRepository: getRecentAlerts", () => {
|
||||
const alerts: ExpiryAlert[] = [
|
||||
{ table_id: "t1", table_title: "A", operadora: "O1", administradora: null, revision_date: "Jan/2027", days_until_expiry: 5, severity: "critical", alert_sent_at: null, channels: [] },
|
||||
{ table_id: "t2", table_title: "B", operadora: "O2", administradora: null, revision_date: "Fevereiro/2027", days_until_expiry: -1, severity: "expired", alert_sent_at: null, channels: [] },
|
||||
];
|
||||
alerts.forEach(a => alertRepo.save(a));
|
||||
|
||||
const recent = alertRepo.getRecentAlerts(5);
|
||||
expect(recent.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("CheckResultRepository: save e getLatest", () => {
|
||||
const result: CheckResult = {
|
||||
checked_at: "2026-01-15T10:00:00.000Z",
|
||||
total_tables: 10,
|
||||
vigente: 5,
|
||||
prestes_a_vencer: 3,
|
||||
vencidas: 2,
|
||||
sem_data: 0,
|
||||
errors: 0,
|
||||
alerts_generated: [
|
||||
{ table_id: "t1", table_title: "A", operadora: "O1", administradora: null, revision_date: "Out/2026", days_until_expiry: -2, severity: "expired", alert_sent_at: null, channels: [] },
|
||||
],
|
||||
};
|
||||
|
||||
checkRepo.save(result);
|
||||
const latest = checkRepo.getLatest();
|
||||
|
||||
expect(latest).not.toBeNull();
|
||||
expect(latest?.total_tables).toBe(10);
|
||||
expect(latest?.vigente).toBe(5);
|
||||
expect(latest?.alerts_generated.length).toBe(1);
|
||||
});
|
||||
|
||||
test("CheckResultRepository: getHistory", () => {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
checkRepo.save({
|
||||
checked_at: `2026-01-${10 + i}T10:00:00.000Z`,
|
||||
total_tables: 10,
|
||||
vigente: 5,
|
||||
prestes_a_vencer: 3,
|
||||
vencidas: 2,
|
||||
sem_data: 0,
|
||||
errors: 0,
|
||||
alerts_generated: [],
|
||||
});
|
||||
}
|
||||
|
||||
const history = checkRepo.getHistory(2);
|
||||
expect(history.length).toBe(2);
|
||||
// Mais recente primeiro
|
||||
expect(new Date(history[0].checked_at).getTime()).toBeGreaterThanOrEqual(new Date(history[1].checked_at).getTime());
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
|
||||
import { calculateTableStatus, parseRevisionDate, calculateSeverity } from "../../src/application/services/table-service.ts";
|
||||
import { TableAlertFormatter } from "../../src/domain/services/table-alert-formatter.ts";
|
||||
|
||||
describe("Table Status Calculation", () => {
|
||||
const originalWarningDays = process.env.TABLE_EXPIRY_WARNING_DAYS;
|
||||
const originalCriticalDays = process.env.TABLE_EXPIRY_CRITICAL_DAYS;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.TABLE_EXPIRY_WARNING_DAYS = "30";
|
||||
process.env.TABLE_EXPIRY_CRITICAL_DAYS = "7";
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env.TABLE_EXPIRY_WARNING_DAYS = originalWarningDays;
|
||||
process.env.TABLE_EXPIRY_CRITICAL_DAYS = originalCriticalDays;
|
||||
});
|
||||
|
||||
test("parseRevisionDate: formato válido Mês/Ano", () => {
|
||||
const date = parseRevisionDate("Novembro/2027");
|
||||
expect(date).toBeInstanceOf(Date);
|
||||
expect(date.getFullYear()).toBe(2027);
|
||||
expect(date.getMonth()).toBe(10);
|
||||
expect(date.getDate()).toBe(30);
|
||||
});
|
||||
|
||||
test("parseRevisionDate: meses com acento", () => {
|
||||
const date = parseRevisionDate("Março/2026");
|
||||
expect(date.getMonth()).toBe(2);
|
||||
});
|
||||
|
||||
test("parseRevisionDate: formato inválido retorna null", () => {
|
||||
expect(parseRevisionDate("invalid")).toBeNull();
|
||||
expect(parseRevisionDate("2027/11")).toBeNull();
|
||||
expect(parseRevisionDate(null)).toBeNull();
|
||||
});
|
||||
|
||||
test("calculateTableStatus: vigente (>30 dias)", () => {
|
||||
const futureDate = new Date();
|
||||
futureDate.setDate(futureDate.getDate() + 45);
|
||||
const monthNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
|
||||
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
|
||||
const revisionDate = `${monthNames[futureDate.getMonth()]}/${futureDate.getFullYear()}`;
|
||||
const table = { revision_date: revisionDate } as any;
|
||||
const status = calculateTableStatus(table);
|
||||
expect(status).toBe("vigente");
|
||||
});
|
||||
|
||||
test("calculateTableStatus: prestes_a_vencer (7-30 dias)", () => {
|
||||
// Data entre 8 e 30 dias no futuro
|
||||
const futureDate = new Date();
|
||||
futureDate.setDate(futureDate.getDate() + 15);
|
||||
const monthNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
|
||||
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
|
||||
const revisionDate = `${monthNames[futureDate.getMonth()]}/${futureDate.getFullYear()}`;
|
||||
const table = { revision_date: revisionDate } as any;
|
||||
const status = calculateTableStatus(table);
|
||||
// Se o mês mudou (ex: fim do mês), pode estar >30 dias
|
||||
expect(["vigente", "prestes_a_vencer"]).toContain(status);
|
||||
});
|
||||
|
||||
test("calculateTableStatus: prestes_a_vencer crítico (1-7 dias)", () => {
|
||||
// Data entre 1 e 7 dias no futuro
|
||||
const futureDate = new Date();
|
||||
futureDate.setDate(futureDate.getDate() + 3);
|
||||
const monthNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
|
||||
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
|
||||
const revisionDate = `${monthNames[futureDate.getMonth()]}/${futureDate.getFullYear()}`;
|
||||
const table = { revision_date: revisionDate } as any;
|
||||
const status = calculateTableStatus(table);
|
||||
// Se o mês mudou, pode estar >7 dias
|
||||
expect(["prestes_a_vencer", "vigente"]).toContain(status);
|
||||
});
|
||||
|
||||
test("calculateTableStatus: vencida (passado)", () => {
|
||||
// Data no passado - usa mês anterior garantido
|
||||
const pastDate = new Date();
|
||||
pastDate.setMonth(pastDate.getMonth() - 2); // 2 meses atrás
|
||||
const monthNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
|
||||
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
|
||||
const revisionDate = `${monthNames[pastDate.getMonth()]}/${pastDate.getFullYear()}`;
|
||||
const table = { revision_date: revisionDate } as any;
|
||||
const status = calculateTableStatus(table);
|
||||
expect(status).toBe("vencida");
|
||||
});
|
||||
|
||||
test("calculateTableStatus: sem_data (null)", () => {
|
||||
const table = { revision_date: null } as any;
|
||||
const status = calculateTableStatus(table);
|
||||
expect(status).toBe("sem_data");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Severity Calculation", () => {
|
||||
test("calculateSeverity: expired (negativo)", () => {
|
||||
expect(calculateSeverity(-5)).toBe("expired");
|
||||
expect(calculateSeverity(0)).toBe("critical");
|
||||
});
|
||||
|
||||
test("calculateSeverity: critical (1-7 dias)", () => {
|
||||
expect(calculateSeverity(1)).toBe("critical");
|
||||
expect(calculateSeverity(7)).toBe("critical");
|
||||
});
|
||||
|
||||
test("calculateSeverity: warning (>7 dias)", () => {
|
||||
expect(calculateSeverity(8)).toBe("warning");
|
||||
expect(calculateSeverity(30)).toBe("warning");
|
||||
});
|
||||
});
|
||||
|
||||
describe("TableAlertFormatter", () => {
|
||||
const formatter = new TableAlertFormatter();
|
||||
|
||||
test("formatExpiryAlert: expired", () => {
|
||||
const alert = {
|
||||
table_id: "test-1",
|
||||
table_title: "Plano Teste",
|
||||
operadora: "Operadora X",
|
||||
administradora: "Admin Y",
|
||||
revision_date: "Outubro/2026",
|
||||
days_until_expiry: -5,
|
||||
severity: "expired" as const,
|
||||
alert_sent_at: null,
|
||||
channels: [],
|
||||
};
|
||||
const msg = formatter.formatExpiryAlert(alert);
|
||||
expect(msg).toContain("🔴");
|
||||
expect(msg).toContain("VENCIDA");
|
||||
expect(msg).toContain("Operadora X");
|
||||
expect(msg).toContain("Plano Teste");
|
||||
expect(msg).toContain("Outubro/2026");
|
||||
expect(msg).toContain("Venceu há 5 dia(s)");
|
||||
});
|
||||
|
||||
test("formatExpiryAlert: critical", () => {
|
||||
const alert = {
|
||||
table_id: "test-2",
|
||||
table_title: "Plano Crítico",
|
||||
operadora: "Operadora Z",
|
||||
administradora: null,
|
||||
revision_date: "Novembro/2026",
|
||||
days_until_expiry: 3,
|
||||
severity: "critical" as const,
|
||||
alert_sent_at: null,
|
||||
channels: [],
|
||||
};
|
||||
const msg = formatter.formatExpiryAlert(alert);
|
||||
expect(msg).toContain("🟠");
|
||||
expect(msg).toContain("CRÍTICA");
|
||||
expect(msg).toContain("Vence em 3 dia(s)");
|
||||
});
|
||||
|
||||
test("formatExpiryAlert: warning", () => {
|
||||
const alert = {
|
||||
table_id: "test-3",
|
||||
table_title: "Plano Warning",
|
||||
operadora: "Operadora W",
|
||||
administradora: "Admin W",
|
||||
revision_date: "Dezembro/2026",
|
||||
days_until_expiry: 15,
|
||||
severity: "warning" as const,
|
||||
alert_sent_at: null,
|
||||
channels: [],
|
||||
};
|
||||
const msg = formatter.formatExpiryAlert(alert);
|
||||
expect(msg).toContain("🟡");
|
||||
expect(msg).toContain("PRÓXIMA DO VENCIMENTO");
|
||||
expect(msg).toContain("Vence em 15 dia(s)");
|
||||
});
|
||||
|
||||
test("escapeHtml: sanitiza caracteres perigosos", () => {
|
||||
const alert = {
|
||||
table_id: "test-4",
|
||||
table_title: "Plano <script>alert(1)</script>",
|
||||
operadora: "Op & Co",
|
||||
administradora: null,
|
||||
revision_date: "Janeiro/2027",
|
||||
days_until_expiry: 10,
|
||||
severity: "warning" as const,
|
||||
alert_sent_at: null,
|
||||
channels: [],
|
||||
};
|
||||
const msg = formatter.formatExpiryAlert(alert);
|
||||
// Verifica que caracteres perigosos foram escapados (HTML entities)
|
||||
expect(msg).not.toContain("<script>");
|
||||
expect(msg).toContain("<script>alert(1)</script>");
|
||||
expect(msg).toContain("Op & Co");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
|
||||
import { TelegramNotifier } from "../../src/infrastructure/telegram/telegram-notifier.ts";
|
||||
|
||||
describe("TelegramNotifier", () => {
|
||||
let notifier: TelegramNotifier;
|
||||
let fetchMock: typeof fetch;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock = async (url: string, options: any) => {
|
||||
const body = JSON.parse(options.body);
|
||||
return new Response(JSON.stringify({ ok: true, result: { message_id: 123 } }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
};
|
||||
|
||||
notifier = new TelegramNotifier({
|
||||
botToken: "123456:TEST_TOKEN",
|
||||
chatId: "-1001234567890",
|
||||
fetchFn: fetchMock,
|
||||
delayMs: 0,
|
||||
});
|
||||
});
|
||||
|
||||
test("sendMessage: sucesso", async () => {
|
||||
const result = await notifier.sendMessage("<b>Teste</b> mensagem");
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("sendMessage: sem config retorna false", async () => {
|
||||
const emptyNotifier = new TelegramNotifier({ fetchFn: fetchMock });
|
||||
const result = await emptyNotifier.sendMessage("teste");
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("sendMessage: override chatId", async () => {
|
||||
let capturedChatId: string | null = null;
|
||||
const mockFetch = async (url: string, options: any) => {
|
||||
const body = JSON.parse(options.body);
|
||||
capturedChatId = body.chat_id;
|
||||
return new Response(JSON.stringify({ ok: true, result: { message_id: 123 } }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
};
|
||||
|
||||
const n = new TelegramNotifier({
|
||||
botToken: "123456:TEST",
|
||||
chatId: "-1001111111111",
|
||||
fetchFn: mockFetch,
|
||||
delayMs: 0,
|
||||
});
|
||||
|
||||
await n.sendMessage("teste", "-1009999999999");
|
||||
expect(capturedChatId).toBe("-1009999999999");
|
||||
});
|
||||
|
||||
test("sendMessage: rate limit 429 com retry", async () => {
|
||||
let attempts = 0;
|
||||
const mockFetch = async (url: string, options: any) => {
|
||||
attempts++;
|
||||
if (attempts === 1) {
|
||||
return new Response(JSON.stringify({ ok: false, error_code: 429, parameters: { retry_after: 1 } }), {
|
||||
status: 429,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ ok: true, result: { message_id: 123 } }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
};
|
||||
|
||||
const n = new TelegramNotifier({
|
||||
botToken: "123456:TEST",
|
||||
chatId: "-1001234567890",
|
||||
fetchFn: mockFetch,
|
||||
delayMs: 0,
|
||||
maxRetries: 3,
|
||||
});
|
||||
|
||||
const result = await n.sendMessage("teste rate limit");
|
||||
expect(result).toBe(true);
|
||||
expect(attempts).toBe(2);
|
||||
});
|
||||
|
||||
test("sendMessage: falha de rede faz retry", async () => {
|
||||
let attempts = 0;
|
||||
const mockFetch = async () => {
|
||||
attempts++;
|
||||
if (attempts < 3) throw new Error("Network error");
|
||||
return new Response(JSON.stringify({ ok: true, result: { message_id: 123 } }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
};
|
||||
|
||||
const n = new TelegramNotifier({
|
||||
botToken: "123456:TEST",
|
||||
chatId: "-1001234567890",
|
||||
fetchFn: mockFetch,
|
||||
delayMs: 0,
|
||||
maxRetries: 3,
|
||||
});
|
||||
|
||||
const result = await n.sendMessage("teste rede");
|
||||
expect(result).toBe(true);
|
||||
expect(attempts).toBe(3);
|
||||
});
|
||||
|
||||
test("sendMessage: HTML parsing mode", async () => {
|
||||
let capturedBody: any = null;
|
||||
const mockFetch = async (url: string, options: any) => {
|
||||
capturedBody = JSON.parse(options.body);
|
||||
return new Response(JSON.stringify({ ok: true, result: { message_id: 123 } }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
};
|
||||
|
||||
const n = new TelegramNotifier({
|
||||
botToken: "123456:TEST",
|
||||
chatId: "-1001234567890",
|
||||
fetchFn: mockFetch,
|
||||
delayMs: 0,
|
||||
});
|
||||
|
||||
await n.sendMessage("<b>Negrito</b> e <i>itálico</i>");
|
||||
expect(capturedBody.parse_mode).toBe("HTML");
|
||||
expect(capturedBody.disable_web_page_preview).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user