101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
import { test, expect, describe, beforeEach } from "bun:test";
|
||
import { TableService, calculateTableStatus } from "../../src/application/services/table-service.js";
|
||
import type { TableInfo } from "../../src/domain/models/table.js";
|
||
|
||
describe("Table Service Status Evaluation & Publish Filtering", () => {
|
||
test("Tabela em dia (como exemplo do usuario) e avaliada como vigente", () => {
|
||
const table: TableInfo = {
|
||
id: "55c02939-aadd-4403-8766-f5da1a506454",
|
||
title: "SBS Up Health – Empresarial – SINTRAMASSAS",
|
||
operadora: "São Bernardo Samp",
|
||
administradora: "Up Health",
|
||
revision_date: "Setembro/2027",
|
||
download_pdf: "https://media.rmscorretora.com.br/uploads/pdf.pdf",
|
||
vigencia: null,
|
||
produtos_json: {
|
||
_meta: {
|
||
extracted_at: "2026-11-26T20:04:10.700782+00:00",
|
||
},
|
||
produtos: [{ nome: "Plano 1", tipo: "Ambulatorial", faixas: [] }],
|
||
},
|
||
status: "sem_data",
|
||
extracted_at: "2026-11-26T20:04:10.700782+00:00",
|
||
last_checked: "2026-11-27T00:00:00.000Z",
|
||
vesting_status: "em_dia",
|
||
is_stale: false,
|
||
modified_gmt: "2026-11-26 20:06:09",
|
||
};
|
||
|
||
const status = calculateTableStatus(table, 30, 7);
|
||
expect(status).toBe("vigente");
|
||
});
|
||
|
||
test("Tabela com vesting_status vencido ou is_stale e avaliada como vencida", () => {
|
||
const table: TableInfo = {
|
||
id: "stale-1",
|
||
title: "Tabela Vencida por Stale",
|
||
operadora: "Op",
|
||
administradora: null,
|
||
revision_date: "Setembro/2027",
|
||
download_pdf: null,
|
||
vigencia: null,
|
||
produtos_json: null,
|
||
status: "sem_data",
|
||
extracted_at: null,
|
||
last_checked: "2026-11-27T00:00:00.000Z",
|
||
vesting_status: "vencido",
|
||
is_stale: true,
|
||
modified_gmt: "2026-11-26 20:06:09",
|
||
};
|
||
|
||
expect(calculateTableStatus(table, 30, 7)).toBe("vencida");
|
||
});
|
||
|
||
test("Tabela sem revision_date ou com * e avaliada como sem_data (falta)", () => {
|
||
const tableStar: TableInfo = {
|
||
id: "star-1",
|
||
title: "Tabela com Asterisco",
|
||
operadora: "Op",
|
||
administradora: null,
|
||
revision_date: "*",
|
||
download_pdf: null,
|
||
vigencia: null,
|
||
produtos_json: null,
|
||
status: "sem_data",
|
||
extracted_at: null,
|
||
last_checked: "2026-11-27T00:00:00.000Z",
|
||
vesting_status: "em_dia",
|
||
is_stale: false,
|
||
modified_gmt: null,
|
||
};
|
||
expect(calculateTableStatus(tableStar, 30, 7)).toBe("sem_data");
|
||
|
||
const tableEmpty: TableInfo = {
|
||
...tableStar,
|
||
id: "empty-1",
|
||
revision_date: null,
|
||
};
|
||
expect(calculateTableStatus(tableEmpty, 30, 7)).toBe("sem_data");
|
||
});
|
||
|
||
test("Tabela com vesting_status a_vencer e classificada como prestes_a_vencer", () => {
|
||
const table: TableInfo = {
|
||
id: "avencer-1",
|
||
title: "Tabela A Vencer",
|
||
operadora: "Op",
|
||
administradora: null,
|
||
revision_date: "Dezembro/2027",
|
||
download_pdf: null,
|
||
vigencia: null,
|
||
produtos_json: null,
|
||
status: "sem_data",
|
||
extracted_at: null,
|
||
last_checked: "2026-11-27T00:00:00.000Z",
|
||
vesting_status: "a_vencer",
|
||
is_stale: false,
|
||
modified_gmt: null,
|
||
};
|
||
expect(calculateTableStatus(table, 30, 7)).toBe("prestes_a_vencer");
|
||
});
|
||
});
|