215 lines
6.9 KiB
JavaScript
215 lines
6.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
getSimulationSections,
|
|
simulationFieldsForSection,
|
|
simulationFieldAvailableAtDetailLevel,
|
|
simulationDraftFingerprint,
|
|
validateSimulationDraft,
|
|
partitionSimulationDraft,
|
|
restoreSimulationDraft,
|
|
} from '../../resources/js/lib/simulation-form.ts';
|
|
import {
|
|
emptyOperatingAssumptions,
|
|
estimateOperatingRevenue,
|
|
estimateOperatingCosts,
|
|
restoreOperatingAssumptions,
|
|
} from '../../resources/js/lib/investment-operating-assistance.ts';
|
|
|
|
test('confirmed nullable empty inputs match their HTTP-normalised recovery without accepting changed values', () => {
|
|
const local = {
|
|
purpose: 'own_investment',
|
|
context_opportunity: '',
|
|
total_investment: '2000000',
|
|
secured_amount: '1000000',
|
|
};
|
|
const snapshots = partitionSimulationDraft(local);
|
|
snapshots.economic_snapshot.context_opportunity = null;
|
|
const saved = restoreSimulationDraft(
|
|
snapshots.economic_snapshot,
|
|
snapshots.personal_snapshot,
|
|
);
|
|
const versionedLocal = {
|
|
...local,
|
|
project_questionnaire_version: 'legacy-unversioned',
|
|
};
|
|
assert.equal(
|
|
simulationDraftFingerprint(saved),
|
|
simulationDraftFingerprint(versionedLocal),
|
|
);
|
|
assert.notEqual(
|
|
simulationDraftFingerprint(saved),
|
|
simulationDraftFingerprint({
|
|
...versionedLocal,
|
|
secured_amount: '250000',
|
|
}),
|
|
);
|
|
assert.notEqual(
|
|
simulationDraftFingerprint(saved),
|
|
simulationDraftFingerprint({
|
|
...versionedLocal,
|
|
context_opportunity: 'another-opportunity',
|
|
}),
|
|
);
|
|
assert.notEqual(
|
|
simulationDraftFingerprint({ ...versionedLocal, secured_amount: '' }),
|
|
simulationDraftFingerprint({ ...versionedLocal, secured_amount: '0' }),
|
|
);
|
|
});
|
|
|
|
test('Hotel and Agronegocio reuse a controlled stage contract without requiring adverts, zones or formal financing facts', () => {
|
|
for (const project_title of ['Criar Hotel', 'Agronegócio em Matola Rio']) {
|
|
const draft = {
|
|
journey_type: 'investor',
|
|
detail_level: 'simple',
|
|
purpose: 'own_investment',
|
|
preferred_language: 'pt-MZ',
|
|
project_title,
|
|
province_id: 'province-qa',
|
|
district_id: 'boane-qa',
|
|
locality_id: 'matola-rio-qa',
|
|
currency: 'MZN',
|
|
investment_budget_min: '1000000',
|
|
investment_budget_max: '5000000',
|
|
};
|
|
const sections = getSimulationSections(draft);
|
|
assert.equal(sections.length, 8);
|
|
assert.ok(
|
|
simulationFieldsForSection(draft, 'purpose').some(
|
|
(field) => field.key === 'locality_id',
|
|
),
|
|
);
|
|
for (const stage of [
|
|
'market',
|
|
'investment',
|
|
'financial',
|
|
'operating',
|
|
'cashflow',
|
|
'tax',
|
|
])
|
|
assert.deepEqual(
|
|
validateSimulationDraft(draft, stage),
|
|
{},
|
|
`${stage} must permit unknown preparation facts`,
|
|
);
|
|
const finance = simulationFieldsForSection(draft, 'financial').map(
|
|
(field) => field.key,
|
|
);
|
|
assert.ok(finance.includes('secured_amount'));
|
|
assert.equal(finance.includes('annual_revenue'), false);
|
|
assert.ok(
|
|
simulationFieldsForSection(draft, 'operating').some(
|
|
(field) => field.key === 'annual_revenue',
|
|
),
|
|
);
|
|
const editableOperating = simulationFieldsForSection(
|
|
draft,
|
|
'operating',
|
|
).filter((field) =>
|
|
simulationFieldAvailableAtDetailLevel(
|
|
draft,
|
|
'operating',
|
|
field.key,
|
|
),
|
|
);
|
|
assert.ok(
|
|
editableOperating.some((field) => field.key === 'annual_revenue'),
|
|
);
|
|
assert.ok(
|
|
editableOperating.some(
|
|
(field) => field.key === 'annual_operating_costs',
|
|
),
|
|
);
|
|
assert.equal(
|
|
simulationFieldAvailableAtDetailLevel(draft, 'operating', 'nuit'),
|
|
false,
|
|
);
|
|
const snapshot = JSON.stringify({
|
|
version: 1,
|
|
data: {
|
|
...emptyOperatingAssumptions(),
|
|
model: 'hotel',
|
|
capacity: '10',
|
|
price: '5000',
|
|
occupancy: '50',
|
|
frequency: '300',
|
|
source: 'Synthetic assumptions explicitly entered',
|
|
},
|
|
});
|
|
const original = {
|
|
...draft,
|
|
preparation_step: 'operating',
|
|
planning_assumptions_snapshot: snapshot,
|
|
};
|
|
const partitioned = partitionSimulationDraft(original);
|
|
const recovered = restoreSimulationDraft(
|
|
partitioned.economic_snapshot,
|
|
partitioned.personal_snapshot,
|
|
);
|
|
for (const key of [
|
|
'locality_id',
|
|
'currency',
|
|
'investment_budget_min',
|
|
'investment_budget_max',
|
|
'preparation_step',
|
|
'planning_assumptions_snapshot',
|
|
])
|
|
assert.equal(recovered[key], original[key]);
|
|
assert.equal(recovered.total_investment, undefined);
|
|
}
|
|
});
|
|
|
|
test('guided estimates require explicit assumptions, preserve the model and do not use population as revenue', () => {
|
|
const empty = emptyOperatingAssumptions();
|
|
assert.throws(() => estimateOperatingRevenue(empty), /Escolha/);
|
|
const hotel = {
|
|
...empty,
|
|
model: 'hotel',
|
|
capacity: '10',
|
|
price: '5000',
|
|
occupancy: '50',
|
|
frequency: '300',
|
|
};
|
|
assert.equal(estimateOperatingRevenue(hotel), '7500000.00');
|
|
assert.throws(
|
|
() => estimateOperatingRevenue({ ...hotel, occupancy: '101' }),
|
|
/100%/,
|
|
);
|
|
assert.throws(
|
|
() => estimateOperatingRevenue({ ...hotel, price: '' }),
|
|
/falta/,
|
|
);
|
|
assert.equal(
|
|
estimateOperatingRevenue({
|
|
...hotel,
|
|
model: 'agriculture',
|
|
capacity: '1200',
|
|
price: '25.50',
|
|
frequency: '2',
|
|
}),
|
|
'61200.00',
|
|
);
|
|
assert.throws(() => estimateOperatingCosts(empty), /não são zero/);
|
|
assert.throws(
|
|
() =>
|
|
estimateOperatingCosts({
|
|
...hotel,
|
|
costs: [{ label: 'Energia', annual: '' }],
|
|
}),
|
|
/falta/,
|
|
);
|
|
const data = {
|
|
...hotel,
|
|
costs: [
|
|
{ label: 'Energia', annual: '100.10' },
|
|
{ label: 'Pessoal', annual: '200.20' },
|
|
],
|
|
};
|
|
assert.equal(estimateOperatingCosts(data), '300.30');
|
|
assert.deepEqual(
|
|
restoreOperatingAssumptions(JSON.stringify({ version: 1, data })),
|
|
data,
|
|
);
|
|
assert.deepEqual(restoreOperatingAssumptions('{broken'), empty);
|
|
});
|