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: '', 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, /<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>
Não indicado/); assert.doesNotMatch(html, /
0/); });