feat: preserve grounded sector ideas through private investment dossiers in QA
This commit is contained in:
@@ -11,6 +11,59 @@ import {
|
||||
} from '../../resources/js/lib/project-dossier-report.ts';
|
||||
import { serializeFinancialToolsSnapshot } from '../../resources/js/lib/financial-calculators.ts';
|
||||
|
||||
void test('sector hypotheses preserve their exact passage, provincial scope and edition in the same private report', async () => {
|
||||
const data = fixture();
|
||||
data.content_sources = [
|
||||
{
|
||||
title: 'SYNTHETIC regional source',
|
||||
source_url: 'https://example.invalid/source',
|
||||
analyses: [
|
||||
{
|
||||
key: 'synthetic-key',
|
||||
title: 'SYNTHETIC hypothesis',
|
||||
quote: 'SYNTHETIC passage <script>private()</script>',
|
||||
section: 'Supporting passage',
|
||||
source_sha256: 'a'.repeat(64),
|
||||
source_version: 7,
|
||||
source_date: '2026-11-15',
|
||||
location_label: 'SYNTHETIC province',
|
||||
location_precision: 'province',
|
||||
href: '/synthetic-source',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const model = createInvestorDossierReport(data, '2026-11-15T00:00:00Z');
|
||||
const market = model.sections.find((s) => s.id === 'market');
|
||||
assert.equal(
|
||||
market.rows.find((r) => r.field.endsWith('SYNTHETIC hypothesis')).value,
|
||||
data.content_sources[0].analyses[0].quote,
|
||||
);
|
||||
assert.match(
|
||||
market.rows.find((r) => r.classification === 'province').value,
|
||||
/SYNTHETIC province/,
|
||||
);
|
||||
assert.match(
|
||||
market.rows.find((r) => r.value.startsWith('7; SHA256')).value,
|
||||
/7; SHA256/,
|
||||
);
|
||||
const html = await createProjectDossierPrintHtml(model, [], true);
|
||||
assert.ok(html.includes('SYNTHETIC hypothesis'));
|
||||
assert.ok(!html.includes('<script>private()</script>'));
|
||||
assert.equal(
|
||||
model.sections.filter((s) => s.id === 'market').length,
|
||||
1,
|
||||
'Existing SWOT and source evidence share one market section',
|
||||
);
|
||||
assert.equal(
|
||||
createInvestorDossierReport(fixture()).sections.filter(
|
||||
(s) => s.id === 'market',
|
||||
).length,
|
||||
1,
|
||||
'Unrelated dossiers retain their original SWOT section',
|
||||
);
|
||||
});
|
||||
|
||||
function fixture() {
|
||||
return {
|
||||
case: {
|
||||
@@ -233,7 +286,9 @@ void test('financial results from a different opportunity do not enter the conso
|
||||
id: 'other',
|
||||
context_opportunity: 'op-b',
|
||||
financial_snapshot: 'OTHER-PRIVATE-INPUTS',
|
||||
preparation_snapshot: { annual_revenue: 'OTHER-PRIVATE-PREPARATION' },
|
||||
preparation_snapshot: {
|
||||
annual_revenue: 'OTHER-PRIVATE-PREPARATION',
|
||||
},
|
||||
draft_id: 'other-draft',
|
||||
draft_version: 8,
|
||||
recorded_at: '2026-11-13',
|
||||
@@ -246,7 +301,12 @@ void test('financial results from a different opportunity do not enter the conso
|
||||
'OTHER-PRIVATE-INPUTS',
|
||||
),
|
||||
);
|
||||
assert.equal(JSON.stringify(createInvestorDossierReport(input)).includes('OTHER-PRIVATE-PREPARATION'), false);
|
||||
assert.equal(
|
||||
JSON.stringify(createInvestorDossierReport(input)).includes(
|
||||
'OTHER-PRIVATE-PREPARATION',
|
||||
),
|
||||
false,
|
||||
);
|
||||
assert.ok(
|
||||
!investorDossierReportIndex(input).some(
|
||||
(entry) => entry.id === 'finance:other',
|
||||
@@ -282,7 +342,28 @@ void test('the consolidated report reuses loan, break-even, financing and budget
|
||||
input.results = [
|
||||
{
|
||||
id: 'finance-a',
|
||||
preparation_snapshot: { total_investment: '100000', investment_budget_min: '1000000', investment_budget_max: '5000000', annual_revenue: '7500000', planning_assumptions_snapshot: JSON.stringify({ version: 1, data: { model: 'hotel', capacity: '10', price: '5000', occupancy: '50', frequency: '300', source: 'Synthetic assumptions', costs: [{ label: 'Energia', annual: '' }] } }), initial_budget_snapshot: JSON.stringify({ version: 1, rows: [{ label: 'Equipamento', amount: '100000' }] }) },
|
||||
preparation_snapshot: {
|
||||
total_investment: '100000',
|
||||
investment_budget_min: '1000000',
|
||||
investment_budget_max: '5000000',
|
||||
annual_revenue: '7500000',
|
||||
planning_assumptions_snapshot: JSON.stringify({
|
||||
version: 1,
|
||||
data: {
|
||||
model: 'hotel',
|
||||
capacity: '10',
|
||||
price: '5000',
|
||||
occupancy: '50',
|
||||
frequency: '300',
|
||||
source: 'Synthetic assumptions',
|
||||
costs: [{ label: 'Energia', annual: '' }],
|
||||
},
|
||||
}),
|
||||
initial_budget_snapshot: JSON.stringify({
|
||||
version: 1,
|
||||
rows: [{ label: 'Equipamento', amount: '100000' }],
|
||||
}),
|
||||
},
|
||||
context_opportunity: 'op-a',
|
||||
context_revision: 2,
|
||||
context_state: 'review_required',
|
||||
@@ -321,18 +402,74 @@ void test('the consolidated report reuses loan, break-even, financing and budget
|
||||
);
|
||||
assert.match(rows[0].classification, /Histórico/);
|
||||
assert.equal(input.results[0].financial_snapshot, financial_snapshot);
|
||||
assert.equal(rows.find(item => item.field === 'Receitas anuais estimadas').value, '7500000 MZN');
|
||||
assert.equal(rows.find(item => item.field === 'Quartos disponíveis').value, '10');
|
||||
assert.equal(rows.find(item => item.field === 'Custo anual — Energia').value, 'Por confirmar');
|
||||
assert.equal(rows.find(item => item.field === 'Investimento inicial — Equipamento').value, '100000');
|
||||
assert.equal(
|
||||
rows.find((item) => item.field === 'Receitas anuais estimadas').value,
|
||||
'7500000 MZN',
|
||||
);
|
||||
assert.equal(
|
||||
rows.find((item) => item.field === 'Quartos disponíveis').value,
|
||||
'10',
|
||||
);
|
||||
assert.equal(
|
||||
rows.find((item) => item.field === 'Custo anual — Energia').value,
|
||||
'Por confirmar',
|
||||
);
|
||||
assert.equal(
|
||||
rows.find((item) => item.field === 'Investimento inicial — Equipamento')
|
||||
.value,
|
||||
'100000',
|
||||
);
|
||||
});
|
||||
|
||||
test('funding remains calculable without presenting an unchosen empty loan or empty comparisons', () => {
|
||||
const input = fixture();
|
||||
input.results = [{ id: 'funding-only', context_opportunity: 'op-a', context_revision: 3, currency: 'MZN', draft_id: 'draft-a', draft_version: 1, recorded_at: '2026-11-15', engine: 'financial-calculators:v1', preparation_snapshot: { planning_loan: 'no' }, financial_snapshot: serializeFinancialToolsSnapshot({ budgetPeriod: 'Mensal', loan: { principal: '', rate: '', months: '', rateType: 'nominal', periodMonths: '1', gracePeriods: '', upfrontFee: '', recurringFee: '' }, breakEven: { fixed: '', price: '', variable: '' }, funding: { total: '1000000', secured: '1000000' }, incomes: [{ label: 'Receita', amount: '' }], expenses: [{ label: 'Custos', amount: '' }] }) }];
|
||||
const rows = createInvestorDossierReport(input).sections.find(section => section.id === 'finance').rows;
|
||||
assert.equal(rows.find(row => row.field === 'Financiamento — Diferença por financiar').value, '0.00 MZN');
|
||||
assert.equal(rows.some(row => /Empréstimo educativo|Ponto de equilíbrio|Orçamento —/.test(row.field)), false);
|
||||
input.results = [
|
||||
{
|
||||
id: 'funding-only',
|
||||
context_opportunity: 'op-a',
|
||||
context_revision: 3,
|
||||
currency: 'MZN',
|
||||
draft_id: 'draft-a',
|
||||
draft_version: 1,
|
||||
recorded_at: '2026-11-15',
|
||||
engine: 'financial-calculators:v1',
|
||||
preparation_snapshot: { planning_loan: 'no' },
|
||||
financial_snapshot: serializeFinancialToolsSnapshot({
|
||||
budgetPeriod: 'Mensal',
|
||||
loan: {
|
||||
principal: '',
|
||||
rate: '',
|
||||
months: '',
|
||||
rateType: 'nominal',
|
||||
periodMonths: '1',
|
||||
gracePeriods: '',
|
||||
upfrontFee: '',
|
||||
recurringFee: '',
|
||||
},
|
||||
breakEven: { fixed: '', price: '', variable: '' },
|
||||
funding: { total: '1000000', secured: '1000000' },
|
||||
incomes: [{ label: 'Receita', amount: '' }],
|
||||
expenses: [{ label: 'Custos', amount: '' }],
|
||||
}),
|
||||
},
|
||||
];
|
||||
const rows = createInvestorDossierReport(input).sections.find(
|
||||
(section) => section.id === 'finance',
|
||||
).rows;
|
||||
assert.equal(
|
||||
rows.find(
|
||||
(row) => row.field === 'Financiamento — Diferença por financiar',
|
||||
).value,
|
||||
'0.00 MZN',
|
||||
);
|
||||
assert.equal(
|
||||
rows.some((row) =>
|
||||
/Empréstimo educativo|Ponto de equilíbrio|Orçamento —/.test(
|
||||
row.field,
|
||||
),
|
||||
),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
void test('the existing Word and print exporters retain dossier identity, pending stages, source and history, escaping active HTML', async () => {
|
||||
|
||||
Reference in New Issue
Block a user