Preserve installed dossier and support presentation while delivering authorised quick search
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import JSZip from 'jszip';
|
||||
import { createInvestorStageReport } from '../../resources/js/lib/investor-dossier-report.ts';
|
||||
import {
|
||||
createProjectDossierPrintHtml,
|
||||
generateProjectDossierDocx,
|
||||
} from '../../resources/js/lib/project-dossier-report.ts';
|
||||
|
||||
const input = {
|
||||
case: {
|
||||
id: 'synthetic-stage-dossier',
|
||||
title: 'Ensaio sintético',
|
||||
version: 3,
|
||||
},
|
||||
context_opportunity: null,
|
||||
opportunity_options: [],
|
||||
investment_context: {
|
||||
revision: 1,
|
||||
fields: { project_title: 'Fábrica sintética', province: 'Sofala' },
|
||||
},
|
||||
phases: { 1: 'Preparação sintética' },
|
||||
results: [],
|
||||
documents: [],
|
||||
steps: Array.from({ length: 19 }, (_, i) => ({
|
||||
code: `S${String(i + 1).padStart(2, '0')}`,
|
||||
title: `Etapa sintética ${i + 1}`,
|
||||
phase: 1,
|
||||
version: i + 2,
|
||||
state: 'preparing',
|
||||
reason: `Fundamento sintético exclusivo ${i + 1}.`,
|
||||
detail: { recorded_at: '2026-11-13' },
|
||||
})),
|
||||
};
|
||||
|
||||
void test('all 19 stage reports can be consulted and exported without inventing outcomes or changing source data', async () => {
|
||||
const before = JSON.stringify(input);
|
||||
for (const step of input.steps) {
|
||||
const model = createInvestorStageReport(
|
||||
input,
|
||||
step.code,
|
||||
'2026-11-13T15:00:00Z',
|
||||
);
|
||||
assert.match(model.title, new RegExp(step.code));
|
||||
const execution = model.sections.find((s) => s.id === 'execution');
|
||||
assert.equal(execution.rows.length, 1);
|
||||
assert.ok(execution.rows[0].value.includes(step.reason));
|
||||
assert.ok(
|
||||
model.sections
|
||||
.find((s) => s.id === 'summary')
|
||||
.rows.every((r) => r.field.startsWith(step.code)),
|
||||
);
|
||||
assert.ok(
|
||||
!model.sections.some((s) => s.id === 'finance') ||
|
||||
step.code === 'S03',
|
||||
);
|
||||
const html = await createProjectDossierPrintHtml(model, [], true);
|
||||
assert.ok(html.includes(step.reason));
|
||||
assert.ok(html.includes('synthetic-stage-dossier'));
|
||||
const blob = await generateProjectDossierDocx(model, [], true);
|
||||
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
|
||||
const xml = await zip.file('word/document.xml').async('string');
|
||||
assert.ok(xml.includes(step.reason));
|
||||
assert.ok(xml.includes('não cria documentos'));
|
||||
}
|
||||
assert.equal(JSON.stringify(input), before);
|
||||
assert.throws(
|
||||
() => createInvestorStageReport(input, 'S99'),
|
||||
/não encontrada/,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createInvestorStageReport(
|
||||
{ ...input, opportunity_options: ['a', 'b'] },
|
||||
'S01',
|
||||
),
|
||||
/Seleccione/,
|
||||
);
|
||||
});
|
||||
|
||||
void test('exported limitations retain literal text and cannot inject active HTML', async () => {
|
||||
const model = createInvestorStageReport(input, 'S08');
|
||||
model.limitations.push('Limite <script>alert(1)</script> & origem');
|
||||
const html = await createProjectDossierPrintHtml(model, [], true);
|
||||
assert.ok(
|
||||
html.includes(
|
||||
'Limite <script>alert(1)</script> & origem',
|
||||
),
|
||||
);
|
||||
assert.ok(!html.includes('<script>alert(1)</script>'));
|
||||
const zip = await JSZip.loadAsync(
|
||||
await (await generateProjectDossierDocx(model, [], true)).arrayBuffer(),
|
||||
);
|
||||
assert.ok(
|
||||
(await zip.file('word/document.xml').async('string')).includes(
|
||||
'Limite <script>alert(1)</script> & origem',
|
||||
),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user