import { correctionFieldHints, fieldLabelMatches, } from '../../resources/js/lib/field-corrections.ts'; import test from 'node:test'; import assert from 'node:assert/strict'; import { complementaryFixture } from './fixtures/complementary-plan.mjs'; import { buildComplementaryTables } from '../../resources/js/lib/complementary-report.ts'; import { financialPlanWarnings } from '../../resources/js/lib/financial-plan-warnings.ts'; void test('V09 P0078 identifies the actual personnel quantity field with literal guidance without changing totals or input', () => { const { plan, draft, team } = complementaryFixture(); const bad = { ...draft, project_team_snapshot: JSON.stringify([ { ...team[0], quantity: '2.5' }, ]), }; const before = JSON.stringify(bad); const report = buildComplementaryTables(bad, plan)[2]; assert.match( report.issues.join(' '), /Introduza um n\u00famero inteiro de pessoas\./, ); assert.match(report.issues.join(' '), /Quantidade de pessoas/); assert.equal(JSON.stringify(bad), before); const hints = correctionFieldHints( report.issues.find((i) => i.includes('n\u00famero inteiro de pessoas')), ); assert.ok( hints.some((h) => fieldLabelMatches('Quantidade de pessoas (inteiro)', h), ), ); assert.ok( !hints.some((h) => fieldLabelMatches('Remunera\u00e7\u00e3o mensal', h), ), ); assert.equal( report.rows.find((r) => r[0] === 'Folha salarial prevista')[1], 'Por determinar', ); const good = buildComplementaryTables( { ...bad, project_team_snapshot: JSON.stringify([ { ...team[0], quantity: '2' }, ]), }, plan, )[2]; assert.ok( !good.issues.some((i) => i.includes('n\u00famero inteiro de pessoas')), ); }); void test('V09 P0079/P0080 messages use calculated monthly values, group periods once, and never change tables', () => { const plan = { currency: 'MZN', periods: 3 }; const tables = [ { id: 'sales', headers: ['Rubrica', '2027-01', '2027-02', '2027-03'], rows: [['Vendas totais', '0.00', '100.00', '100.00']], issues: [], notes: [], }, { id: 'profit-loss', headers: ['Rubrica', '2027-01', '2027-02', '2027-03'], rows: [ ['Custo directo', '0.00', '100.00', '150.00'], ['Despesas operacionais', '10.00', '10.00', '10.00'], ], issues: [], notes: [], }, ]; tables.push({ id: 'cashflow', headers: ['Rubrica', '2027-01', '2027-02', '2027-03'], rows: [['Caixa final', '-1.00', '0.00', '0.00']], issues: [], notes: [], }); const before = JSON.stringify(tables); const w = financialPlanWarnings(plan, tables); assert.equal(w.filter((w) => w.id === 'cash-negative-2027-01').length, 1); assert.equal( w.filter((x) => x.message.includes( 'Com este custo vari\u00e1vel n\u00e3o h\u00e1 margem para cobrir os custos fixos. Reveja o custo vari\u00e1vel ou o pre\u00e7o.', ), ).length, 1, ); assert.equal( w.filter((x) => x.message.includes( 'Indique as vendas previstas para calcular a margem e o ponto de equil\u00edbrio.', ), ).length, 1, ); assert.equal(JSON.stringify(tables), before); const clear = structuredClone(tables); clear[0].rows[0] = ['Vendas totais', '100.00', '200.00', '200.00']; assert.ok( !financialPlanWarnings(plan, clear).some( (x) => x.id === 'period-no-contribution' || x.id === 'period-sales-required', ), ); const missing = structuredClone(tables); missing[0].rows[0][1] = 'Por determinar'; assert.ok( !financialPlanWarnings(plan, missing).some( (x) => x.id === 'period-sales-required', ), ); const invalidTable = structuredClone(tables); invalidTable[0].issues = ['SYNTHETIC unresolved input']; assert.ok( !financialPlanWarnings(plan, invalidTable).some( (x) => x.id === 'period-no-contribution' || x.id === 'period-sales-required', ), ); });