fix: target literal financial diagnostics and document V09 QA coverage
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
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',
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
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';
|
||||
const message =
|
||||
'A data de t\u00e9rmino n\u00e3o pode ser anterior \u00e0 data de in\u00edcio.';
|
||||
void test('V09 P0077 diagnoses only reversed valid milestone dates with exact requested text and actual field', () => {
|
||||
const { plan, draft, milestones } = complementaryFixture();
|
||||
const rows = [
|
||||
{ ...milestones[0], start_date: '2027-03-10', due_date: '2027-03-01' },
|
||||
];
|
||||
const input = {
|
||||
...draft,
|
||||
project_execution_snapshot: JSON.stringify(rows),
|
||||
},
|
||||
before = JSON.stringify(input);
|
||||
const bad = buildComplementaryTables(input, plan)[1];
|
||||
assert.equal(bad.issues.filter((i) => i.includes(message)).length, 1);
|
||||
assert.match(bad.issues.join(' '), /Marco 1/);
|
||||
assert.match(bad.issues.join(' '), /Prazo previsto/);
|
||||
assert.equal(JSON.stringify(input), before);
|
||||
const fixed = buildComplementaryTables(
|
||||
{
|
||||
...input,
|
||||
project_execution_snapshot: JSON.stringify([
|
||||
{ ...rows[0], due_date: '2027-03-20' },
|
||||
]),
|
||||
},
|
||||
plan,
|
||||
)[1];
|
||||
assert.equal(fixed.issues.filter((i) => i.includes(message)).length, 0);
|
||||
assert.deepEqual(fixed.rows.at(-1), bad.rows.at(-1));
|
||||
const missing = buildComplementaryTables(
|
||||
{
|
||||
...input,
|
||||
project_execution_snapshot: JSON.stringify([
|
||||
{ ...rows[0], start_date: '' },
|
||||
]),
|
||||
},
|
||||
plan,
|
||||
)[1];
|
||||
assert.ok(missing.issues.length);
|
||||
assert.ok(!missing.issues.some((i) => i.includes(message)));
|
||||
});
|
||||
Reference in New Issue
Block a user