Files
Investidor-V2/tests/frontend/public-opportunity-offline.test.mjs
T
2026-11-02 20:31:15 +02:00

76 lines
2.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { publicOpportunityOfflineHtml } from '../../resources/js/lib/public-opportunity-offline.ts';
import { publicRecordOfflineHtml } from '../../resources/js/lib/public-record-offline.ts';
await test('opportunity offline projection keeps public content, precise values and source while excluding private context and attachments', () => {
const html = publicOpportunityOfflineHtml(
{
title: 'Synthetic opportunity',
slug: 'synthetic',
reference: 'SYN-1',
summary: 'Summary',
description: '<img src=x onerror=alert(1)>',
expected_impact: 'Expected jobs, not measured results',
estimated_investment_amount: '9007199254740993.25',
estimated_investment_currency: 'MZN',
district: 'Synthetic district',
province: 'Synthetic province',
last_validated_at: '2026-10-01',
payload: 'PRIVATE-PAYLOAD',
context: 'PRIVATE-CONTEXT',
documents: ['PRIVATE-FILE'],
},
'https://portal.example.invalid',
new Date('2026-11-02T12:00:00Z'),
);
assert.match(html, /9007199254740993\.25 MZN/);
assert.match(html, /SYN-1/);
assert.match(html, /2026-10-01/);
assert.match(html, /Synthetic district, Synthetic province/);
assert.match(html, /Contexto territorial/);
assert.match(
html,
/href="https:\/\/portal\.example\.invalid\/oportunidades\/synthetic"/,
);
assert.doesNotMatch(html, /PRIVATE-|<(?:img|script|iframe|link)\b/);
assert.match(html, /&lt;img/);
assert.match(html, /não confirma a implantação/);
});
await test('shared offline renderer rejects source paths outside the portal and preserves unknown fields as unknown', () => {
const content = {
title: 'Synthetic',
kind: 'Ficha',
sourcePath: '//external.invalid',
rows: [],
sections: [],
notice: '',
};
assert.throws(
() =>
publicRecordOfflineHtml(
content,
'https://portal.example.invalid',
new Date(),
),
/inválida/,
);
assert.throws(
() =>
publicRecordOfflineHtml(
{ ...content, sourcePath: '/\\external.invalid' },
'https://portal.example.invalid',
new Date(),
),
/inválida/,
);
const html = publicOpportunityOfflineHtml(
{ title: 'Unknown', slug: 'unknown', reference: 'SYN-2' },
'https://portal.example.invalid',
new Date(),
);
assert.match(html, /Investimento estimado<\/dt><dd>Não indicado/);
assert.doesNotMatch(html, /<dd>0/);
});