feat(qa): integrate official Mozambique CAE into saved financial plans
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { mozambiqueCaeSubclasses } from '../../resources/js/lib/cae-mozambique-data.ts';
|
||||
import { describePlanCae, selectPlanCae, mozambiqueCaeSource } from '../../resources/js/lib/cae-mozambique.ts';
|
||||
import { serializeBusinessPlanSnapshot, restoreBusinessPlanSnapshot } from '../../resources/js/lib/business-financial-plan.ts';
|
||||
import { buildIntegralFinancialTables } from '../../resources/js/lib/integral-financial-report.ts';
|
||||
import { createIntegralFinancialReport, createProjectDossierPrintHtml, generateProjectDossierDocx } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
import { complementaryFixture } from './fixtures/complementary-plan.mjs';
|
||||
import JSZip from 'jszip';
|
||||
import { matchesChoice } from '../../resources/js/lib/catalogue-choice.ts';
|
||||
import { planCaeChoices } from '../../resources/js/lib/cae-mozambique.ts';
|
||||
|
||||
void test('searching Hotel includes the official plural Hotéis without assigning a code', () => {
|
||||
const hotel = planCaeChoices.find(n => n.value === '55111');
|
||||
assert.equal(matchesChoice('hotel', [hotel.label, ...hotel.keywords]), true);
|
||||
assert.equal(describePlanCae(undefined).value, 'Não documentado');
|
||||
});
|
||||
|
||||
void test('official structure preserves 579 unique five digit subclasses and source pages', () => {
|
||||
assert.equal(mozambiqueCaeSubclasses.length, 579);
|
||||
assert.equal(new Set(mozambiqueCaeSubclasses.map(n => n.code)).size, 579);
|
||||
for (const n of mozambiqueCaeSubclasses) {
|
||||
assert.match(n.code, /^\d{5}$/);
|
||||
assert.ok(n.label && n.page >= 38 && n.page <= 65);
|
||||
assert.doesNotMatch(n.label, /Secção\*|NÍVEL|\s[Pp]\d{4}$/);
|
||||
}
|
||||
assert.equal(describePlanCae(selectPlanCae('01120')).value, '01120 — Cultura de arroz');
|
||||
assert.match(describePlanCae(selectPlanCae('55111')).value, /Hotéis com restaurante/);
|
||||
assert.match(describePlanCae(selectPlanCae('90000')).value, /ACTIVIDADES/i);
|
||||
});
|
||||
|
||||
void test('official reference does not silently reuse divergent eBAU entries', () => {
|
||||
const existing = JSON.parse(fs.readFileSync(new URL('../../database/data/proactive-supply-classification.json', import.meta.url))).nodes;
|
||||
const normalize = s => s.toLocaleLowerCase('pt').replace(/[^\p{L}\p{N}]/gu, '');
|
||||
for (const n of mozambiqueCaeSubclasses.filter(n => n.code !== '96090'))
|
||||
assert.ok(existing.some(e => e.code === n.code && normalize(e.label) === normalize(n.label)), n.code);
|
||||
assert.match(describePlanCae(selectPlanCae('96090')).value, /Outras actividades de serviços pessoais/);
|
||||
for (const code of ['47210', '23962', 'hotel', 'turismo']) assert.throws(() => selectPlanCae(code));
|
||||
assert.equal(describePlanCae(undefined).value, 'Não documentado');
|
||||
assert.equal(selectPlanCae(''), undefined);
|
||||
});
|
||||
|
||||
void test('classification survives existing snapshot persistence without changing financial tables', () => {
|
||||
const { plan } = complementaryFixture();
|
||||
const before = buildIntegralFinancialTables(plan);
|
||||
const changed = { ...plan, economicClassification: selectPlanCae('55111') };
|
||||
const recovered = restoreBusinessPlanSnapshot(serializeBusinessPlanSnapshot(changed));
|
||||
assert.deepEqual(recovered.economicClassification, changed.economicClassification);
|
||||
assert.deepEqual(buildIntegralFinancialTables(recovered), before);
|
||||
assert.equal(restoreBusinessPlanSnapshot(serializeBusinessPlanSnapshot(plan)).economicClassification, undefined);
|
||||
});
|
||||
|
||||
void test('mismatched source or unknown selection remains unconfirmed without suppressing financial values', () => {
|
||||
for (const selection of [selectPlanCae('55111'), { ...selectPlanCae('55111'), sourceSha256: 'different' }, { ...selectPlanCae('55111'), code: '47210' }, {}]) {
|
||||
const { plan, draft } = complementaryFixture();
|
||||
const snapshot = serializeBusinessPlanSnapshot({ ...plan, economicClassification: selection });
|
||||
const report = createIntegralFinancialReport({ ...draft, business_plan_snapshot: snapshot });
|
||||
assert.equal(report.sections[0].tables.length, 11);
|
||||
assert.equal(describePlanCae(selection).confirmed, selection.sourceSha256 === mozambiqueCaeSource.sha256 && selection.code === '55111');
|
||||
assert.deepEqual(report.sections[0].tables.filter(t => !['ratios','market-analysis','personnel','milestones'].includes(t.id)), buildIntegralFinancialTables(plan));
|
||||
}
|
||||
});
|
||||
|
||||
void test('consolidated report and both existing exports carry canonical CAE and source without inventing a twelfth table', async () => {
|
||||
const { plan, draft } = complementaryFixture();
|
||||
const report = createIntegralFinancialReport({ ...draft, business_plan_snapshot: serializeBusinessPlanSnapshot({ ...plan, economicClassification: selectPlanCae('01120') }) });
|
||||
assert.equal(report.sections[0].tables.length, 11);
|
||||
const row = report.sections[0].rows.find(r => r.field === 'Classificação CAE do plano');
|
||||
assert.equal(row.value, '01120 — Cultura de arroz');
|
||||
assert.match(row.origin, /INE, 2008, página PDF 38/);
|
||||
const html = await createProjectDossierPrintHtml(report, []);
|
||||
assert.match(html, /01120/);
|
||||
const file = await generateProjectDossierDocx(report, []), zip = await JSZip.loadAsync(file instanceof Blob ? await file.arrayBuffer() : file);
|
||||
assert.match(await zip.file('word/document.xml').async('string'), /01120/);
|
||||
});
|
||||
Reference in New Issue
Block a user