fix(analysis): mark sub-inflation growth orange and show 12 inflation months

Reserve red for negative variations across all currency columns and the total row. Show the last 12 months with inflation data plus the trailing months without it, and compute the accumulated inflation and total variation over the same 12-month window. Extend the monthly-last backend window to 15 months.
This commit is contained in:
Jose Selesan
2026-11-19 15:29:11 -03:00
parent e5382670a5
commit d156a2a8a4
3 changed files with 98 additions and 95 deletions

View File

@@ -24,24 +24,28 @@ type Row = { month: string; type: string; buy: number };
const originalFetch = globalThis.fetch;
// 12 meses con inflación + 2 aún sin dato + 1 mes base, de 2025-08 a 2026-10.
const MONTHS = [
"2025-08",
"2025-09",
"2025-10",
"2025-11",
"2025-12",
"2026-01",
"2026-02",
"2026-03",
"2026-04",
"2026-05",
"2026-06",
"2026-07",
"2026-08",
"2026-09",
"2026-10",
];
function fakeCasaData(casa: string): unknown[] {
// Un único día por mes, cubriendo de 2025-10 a 2026-10.
const months = [
"2025-10",
"2025-11",
"2025-12",
"2026-01",
"2026-02",
"2026-03",
"2026-04",
"2026-05",
"2026-06",
"2026-07",
"2026-08",
"2026-09",
"2026-10",
];
return months.map((m, i) => ({
// Un único día por mes.
return MONTHS.map((m, i) => ({
casa,
fecha: `${m}-15`,
compra: 1000 + i,
@@ -74,57 +78,28 @@ afterEach(() => {
});
describe("getMonthlyLast", () => {
test("trae 13 meses (12 a mostrar + 1 base) y no descarta el mes en curso del fallback externo", async () => {
test("trae 15 meses (12 con inflación + 2 sin dato + 1 base) y no descarta el mes en curso del fallback externo", async () => {
mockQueryRaw.mockResolvedValue([]);
mockExternalApi();
const rows = (await getMonthlyLast(context)) as Row[];
const months = [...new Set(rows.map((r) => r.month))].sort();
expect(months).toEqual([
"2025-10",
"2025-11",
"2025-12",
"2026-01",
"2026-02",
"2026-03",
"2026-04",
"2026-05",
"2026-06",
"2026-07",
"2026-08",
"2026-09",
"2026-10",
]);
expect(months).toEqual(MONTHS);
// Regresión: "2026-10-14" > "2026-10" siempre daba true y el mes más
// reciente nunca llegaba desde la API externa.
expect(rows).toContainEqual({
month: "2026-10",
type: "BELO",
buy: 1012,
buy: 1014,
source: "external",
});
});
test("usa la DB cuando el dato existe y no pega a la API externa", async () => {
const dbRows: Row[] = [];
const months = [
"2025-10",
"2025-11",
"2025-12",
"2026-01",
"2026-02",
"2026-03",
"2026-04",
"2026-05",
"2026-06",
"2026-07",
"2026-08",
"2026-09",
"2026-10",
];
for (const month of months) {
for (const month of MONTHS) {
for (const type of ["BELO", "BLUE", "BNA"]) {
dbRows.push({ month, type, buy: 500 });
}
@@ -138,6 +113,6 @@ describe("getMonthlyLast", () => {
expect(fetchMock).not.toHaveBeenCalled();
expect(rows.every((r) => r.source === "db")).toBe(true);
expect(rows).toHaveLength(13 * 3);
expect(rows).toHaveLength(MONTHS.length * 3);
});
});