Files
Investidor-V2/tests/frontend/milestone-date-diagnostic.test.mjs
T

45 lines
1.8 KiB
JavaScript

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)));
});