import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; void test('V09 missing year in an existing F22 snapshot uses the same literal without changing financial modules', () => { const p = JSON.parse( fs.readFileSync( 'docs/investmoz/v2/auditoria-portal/e32-f22-20261121/saved-plan.json', 'utf8', ), ).plan; p.reportAssumptions.startYear = ''; assert.throws( () => forecastBusinessPlan(p), /«Ano inicial»: Preencha este campo para continuar\./, ); }); void test('V09 report year and fiscal source use required-field literal with actual labels', () => { const p = financialReportFixture(12); for (const [key, label] of [ ['startYear', 'Ano inicial'], ['taxSource', 'Fonte ou pressuposto dos impostos estimados'], ]) { const next = structuredClone(p); next.reportAssumptions[key] = ''; assert.ok( buildIntegralFinancialTables(next)[0].issues.some( (x) => x.includes(`«${label}»`) && x.includes('Preencha este campo para continuar.'), ), ); } }); import { fieldLabelMatches } from '../../resources/js/lib/field-corrections.ts'; import { forecastBusinessPlan } from '../../resources/js/lib/business-financial-plan.ts'; void test('V09 exact capital field does not link to another prefix field', () => { const names = ['Capital', 'Capital e resultados anteriores']; assert.equal( fieldLabelMatches('Capital', 'Capital e resultados anteriores', names), false, ); assert.equal( fieldLabelMatches( 'Capital e resultados anteriores', 'Capital e resultados anteriores', names, ), true, ); }); void test('V09 shared numeric consumers and bounded percentages retain rejection with literal guidance', () => { const base = financialReportFixture(12); for (const [value, message] of [ ['', 'Preencha este campo'], ['abc', 'Introduza apenas números'], ['-1', 'Este valor não pode ser negativo'], ]) assert.throws( () => forecastBusinessPlan({ ...base, equity: value }), new RegExp(message), ); for (const patch of [ { salesCollectionPercent: '101' }, { openingReceivablesCollectionPercent: '101' }, { openingReceivablesInstallments: [{ month: 1, percent: '101' }] }, { openingPayablesInstallments: [{ month: 1, percent: '101' }] }, { salesRecoverySchedule: [{ month: 1, percent: '101' }] }, ]) assert.throws( () => forecastBusinessPlan({ ...base, ...patch }), /Introduza uma percentagem entre 0% e 100%\./, ); }); import { financialReportFixture } from './fixtures/integral-financial-plan.mjs'; import { buildIntegralFinancialTables } from '../../resources/js/lib/integral-financial-report.ts'; void test('V09 report opening balances and startup amounts use literal diagnostics without changing valid tables', () => { const base = financialReportFixture(12), original = buildIntegralFinancialTables(base); for (const [key, label] of [ ['openingFixedAssets', 'Activos fixos anteriores'], ['openingOtherAssets', 'Outros activos anteriores'], ['openingEquity', 'Capital e resultados anteriores'], ]) for (const [value, message] of [ ['', 'Preencha este campo'], ['abc', 'Introduza apenas números'], ['-1', 'Este valor não pode ser negativo'], ['1.234', 'duas casas decimais'], ]) { const plan = structuredClone(base); plan.reportAssumptions[key] = value; const input = JSON.stringify(plan), t = buildIntegralFinancialTables(plan); assert.ok( t.every((x) => x.issues.some( (s) => s.includes(label) && s.includes(message), ), ), ); assert.equal(JSON.stringify(plan), input); } for (const [key, value, label, message] of [ ['amount', '', 'Montante de arranque 1', 'Preencha este campo'], ['amount', 'abc', 'Montante de arranque 1', 'Introduza apenas números'], ['amount', '-1', 'Montante de arranque 1', 'não pode ser negativo'], ['label', '', 'Despesa 1', 'Preencha este campo'], ]) { const p = structuredClone(base); p.reportAssumptions.startupExpenses[0][key] = value; assert.ok( buildIntegralFinancialTables(p)[0].issues.some( (s) => s.includes(label) && s.includes(message), ), ); } assert.deepEqual(buildIntegralFinancialTables(base), original); }); void test('V09 monthly tax diagnostics distinguish absent, malformed, negative and precision with exact month label', () => { const base = financialReportFixture(12); for (const [key, label] of [ ['taxExpenseByMonth', 'Imposto reconhecido'], ['taxPaymentByMonth', 'Pagamento fiscal previsto'], ]) for (const [value, message] of [ ['', 'Preencha este campo'], ['abc', 'Introduza apenas números'], ['-1', 'Este valor não pode ser negativo'], ['0.001', 'duas casas decimais'], ]) { const p = structuredClone(base); p.reportAssumptions[key][1] = value; const t = buildIntegralFinancialTables(p); assert.ok( t.every((x) => x.issues.some( (s) => s.includes(`«${label} — mês 2»`) && s.includes(message), ), ), ); p.reportAssumptions[key][1] = base.reportAssumptions[key][1]; assert.deepEqual( buildIntegralFinancialTables(p), buildIntegralFinancialTables(base), ); } });