111 lines
4.1 KiB
JavaScript
111 lines
4.1 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { financialReportFixture } from './fixtures/integral-financial-plan.mjs';
|
|
import { buildIntegralFinancialTables } from '../../resources/js/lib/integral-financial-report.ts';
|
|
import { financialPlanWarnings } from '../../resources/js/lib/financial-plan-warnings.ts';
|
|
import {
|
|
serializeBusinessPlanSnapshot,
|
|
restoreBusinessPlanSnapshot,
|
|
} from '../../resources/js/lib/business-financial-plan.ts';
|
|
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
|
|
|
const monthly = (plan, tables = buildIntegralFinancialTables(plan)) =>
|
|
financialPlanWarnings(plan, tables).filter((w) =>
|
|
w.id.startsWith('cash-negative-'),
|
|
);
|
|
const e15 = () => {
|
|
const plan = financialReportFixture(12);
|
|
plan.monthlyOperatingPaymentsByPeriod = ['3000', ...Array(11).fill('0')];
|
|
return plan;
|
|
};
|
|
|
|
void test('E15: exactly five monthly deficits remain visible despite a positive annual closing, without changing tables or inputs', () => {
|
|
const plan = e15(),
|
|
tables = buildIntegralFinancialTables(plan);
|
|
const before = JSON.stringify({ plan, tables });
|
|
const warnings = monthly(plan, tables);
|
|
const expected = [
|
|
['2027-01', 'Janeiro', '-1 720,00'],
|
|
['2027-02', 'Fevereiro', '-1 340,00'],
|
|
['2027-03', 'Março', '-960,00'],
|
|
['2027-04', 'Abril', '-580,00'],
|
|
['2027-05', 'Maio', '-200,00'],
|
|
];
|
|
assert.deepEqual(
|
|
warnings.map((w) => w.id),
|
|
expected.map(([date]) => `cash-negative-${date}`),
|
|
);
|
|
expected.forEach(([, month, value], index) => {
|
|
assert.ok(
|
|
warnings[index].message.includes(`${month} de 2027: ${value} MZN`),
|
|
);
|
|
});
|
|
assert.equal(
|
|
tables
|
|
.find((t) => t.id === 'cashflow')
|
|
.rows.find((r) => r[0] === 'Caixa final')[13],
|
|
'2460.00',
|
|
);
|
|
assert.equal(JSON.stringify({ plan, tables }), before);
|
|
assert.deepEqual(
|
|
monthly(
|
|
restoreBusinessPlanSnapshot(serializeBusinessPlanSnapshot(plan)),
|
|
),
|
|
warnings,
|
|
);
|
|
});
|
|
|
|
void test('nonnegative, zero, undetermined and invalid cash balances do not invent monthly deficits or dates', () => {
|
|
const plan = financialReportFixture(12);
|
|
assert.deepEqual(monthly(plan), []);
|
|
const tables = buildIntegralFinancialTables(plan);
|
|
const row = tables
|
|
.find((t) => t.id === 'cashflow')
|
|
.rows.find((r) => r[0] === 'Caixa final');
|
|
row[1] = '0.00';
|
|
row[2] = '-0.00';
|
|
row[3] = 'Por determinar';
|
|
assert.deepEqual(monthly(plan, tables), []);
|
|
const invalid = e15();
|
|
invalid.reportAssumptions.taxSource = '';
|
|
assert.deepEqual(monthly(invalid), []);
|
|
});
|
|
|
|
void test('all sixty negative months use the calendar headers once, excluding annual summary columns', () => {
|
|
const plan = financialReportFixture(60);
|
|
plan.monthlyOperatingPayments = '2000';
|
|
const warnings = monthly(plan);
|
|
assert.equal(warnings.length, 60);
|
|
assert.equal(new Set(warnings.map((w) => w.id)).size, 60);
|
|
assert.match(warnings[0].message, /Janeiro de 2027/);
|
|
assert.match(warnings[12].message, /Janeiro de 2028/);
|
|
assert.match(warnings[59].message, /Dezembro de 2031/);
|
|
});
|
|
|
|
void test('dossier report includes each monthly warning once, without copying it into individual tables', () => {
|
|
const plan = e15();
|
|
const report = createProjectDossierReport(
|
|
{
|
|
project_title: 'SINTÉTICO V11',
|
|
business_plan_snapshot: serializeBusinessPlanSnapshot(plan),
|
|
},
|
|
{
|
|
selectedSections: new Set(['finance']),
|
|
generatedAt: '2026-11-20T12:00:00Z',
|
|
},
|
|
);
|
|
const section = report.sections.find((s) => s.id === 'finance');
|
|
for (const warning of monthly(plan)) {
|
|
assert.equal(
|
|
section.paragraphs.filter((p) => p.includes(warning.message))
|
|
.length,
|
|
1,
|
|
);
|
|
assert.ok(
|
|
section.tables.every(
|
|
(t) => !JSON.stringify(t).includes(warning.message),
|
|
),
|
|
);
|
|
}
|
|
});
|