feat: protect owner-only supply aggregates and record target CAE blocker
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { compileFunction } from 'node:vm';
|
||||
import { createRequire } from 'node:module';
|
||||
import React from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import ts from 'typescript';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const file = new URL(
|
||||
'../../resources/js/components/investment-supply-aggregate.tsx',
|
||||
import.meta.url,
|
||||
);
|
||||
const code = ts.transpileModule(fs.readFileSync(file, 'utf8'), {
|
||||
compilerOptions: {
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
},
|
||||
}).outputText;
|
||||
const module = { exports: {} };
|
||||
compileFunction(code, ['require', 'module', 'exports'])(
|
||||
(name) => {
|
||||
if (name === '@inertiajs/react') return { router: { reload() {} } };
|
||||
if (name === '@/lib/investor-context') return { contextApi() {} };
|
||||
if (name === '@/lib/operation-key')
|
||||
return { createOperationKey: () => 'SYNTHETIC' };
|
||||
if (name === './catalogue-choice-select')
|
||||
return {
|
||||
default: ({ label, options }) =>
|
||||
React.createElement(
|
||||
'label',
|
||||
null,
|
||||
label,
|
||||
React.createElement(
|
||||
'select',
|
||||
null,
|
||||
options.map((o) =>
|
||||
React.createElement(
|
||||
'option',
|
||||
{ key: o.value },
|
||||
o.label,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
};
|
||||
return require(name);
|
||||
},
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
const Component = module.exports.default;
|
||||
const fixture = () => ({
|
||||
privacy_version: 1,
|
||||
privacy_policy: 'fixed_district_cae_division_v1',
|
||||
context_revision: 1,
|
||||
recorded_at: '2026-11-15',
|
||||
requested_territory: { id: 'local', name: 'Local conhecido' },
|
||||
scope: { id: 'district', name: 'Distrito conhecido', level: 'district' },
|
||||
broader_context: true,
|
||||
entities: 987654321,
|
||||
repeated: 987654321,
|
||||
uncertain: 987654321,
|
||||
source_summary: {
|
||||
label: 'Originais reservados à equipa',
|
||||
period: '2020',
|
||||
incomplete_periods: true,
|
||||
},
|
||||
filters: {
|
||||
sector_id: 1,
|
||||
activity_id: 'published-activity',
|
||||
activity_label: 'Agricultura',
|
||||
division_code: '01',
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
code: '01',
|
||||
label: 'Agricultura',
|
||||
total: 987654321,
|
||||
entities_band: '5–9',
|
||||
observations_band: '10–14',
|
||||
scope: {
|
||||
id: 'district',
|
||||
name: 'Distrito conhecido',
|
||||
level: 'district',
|
||||
},
|
||||
first_year: 'PRIVATE-DATE',
|
||||
last_year: null,
|
||||
},
|
||||
],
|
||||
interpretation: 'Não somar grupos nem inferir procura.',
|
||||
limitations: 'Cobertura desconhecida.',
|
||||
privacy_notice: 'Grupos pequenos não divulgados.',
|
||||
});
|
||||
const render = (history) =>
|
||||
renderToStaticMarkup(
|
||||
React.createElement(Component, {
|
||||
caseId: 'synthetic',
|
||||
version: 1,
|
||||
revision: 2,
|
||||
history,
|
||||
protectedMode: true,
|
||||
activityOptions: [
|
||||
{
|
||||
id: 'published-activity',
|
||||
code: '01110',
|
||||
label: 'Agricultura',
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
void test('protected presentation shows documentary identities and observations as separate bands, not raw marginal totals or dates', () => {
|
||||
const html = render([fixture()]);
|
||||
assert.match(html, /5–9/);
|
||||
assert.match(html, /10–14/);
|
||||
assert.match(html, /Identidades documentais/);
|
||||
assert.match(html, /Observações consolidadas/);
|
||||
assert.match(html, /Contexto distrital/);
|
||||
assert.match(html, /Local conhecido/);
|
||||
assert.match(html, /2020/);
|
||||
assert.match(html, /períodos não indicados/);
|
||||
assert.match(html, /O contexto mudou/);
|
||||
assert.match(html, /Actividade a comparar/);
|
||||
assert.ok(!html.includes('987654321'));
|
||||
assert.ok(!html.includes('PRIVATE-DATE'));
|
||||
});
|
||||
void test('suppressed and absent results use the same non-inference message, never zero businesses', () => {
|
||||
const row = fixture();
|
||||
row.groups = [];
|
||||
const html = render([row]);
|
||||
assert.match(html, /podem faltar registos ou existir grupos protegidos/);
|
||||
assert.match(html, /não significa ausência de empresas/);
|
||||
assert.ok(!html.includes('987654321'));
|
||||
});
|
||||
void test('legacy exact QA snapshots are not displayed in protected mode and current protected history is recoverable', () => {
|
||||
const legacy = {
|
||||
...fixture(),
|
||||
privacy_version: undefined,
|
||||
entities: 987654321,
|
||||
};
|
||||
const html = render([
|
||||
legacy,
|
||||
fixture(),
|
||||
{ ...fixture(), recorded_at: '2026-11-16' },
|
||||
]);
|
||||
assert.match(html, /Análise guardada/);
|
||||
assert.match(html, /2026-11-16/);
|
||||
assert.ok(!html.includes('987654321'));
|
||||
assert.ok(!render([legacy]).includes('Identidades documentais'));
|
||||
});
|
||||
Reference in New Issue
Block a user