74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
samePlanningAmount,
|
|
fundingDifferences,
|
|
draftFundingDifferences,
|
|
} from '../../resources/js/lib/planning-finance-context.ts';
|
|
import {
|
|
serializeFinancialToolsSnapshot,
|
|
calculateFundingGap,
|
|
} from '../../resources/js/lib/financial-calculators.ts';
|
|
import { defaultCashflowDraftInputs } from '../../resources/js/lib/monthly-cashflow.ts';
|
|
|
|
test('funding reconciliation compares exact decimals without treating unknown as zero', () => {
|
|
assert.equal(samePlanningAmount('1000000', '1000000.00'), true);
|
|
assert.equal(samePlanningAmount('', '0'), false);
|
|
assert.equal(samePlanningAmount('', ''), true);
|
|
assert.equal(
|
|
samePlanningAmount('9007199254740993', '9007199254740992'),
|
|
false,
|
|
);
|
|
assert.deepEqual(
|
|
fundingDifferences(
|
|
{ total: '1000000', secured: '1000000' },
|
|
{ total: '1000000', secured: '250000' },
|
|
),
|
|
['secured'],
|
|
);
|
|
assert.equal(calculateFundingGap('1000000', '1000000').gap, '0.00');
|
|
});
|
|
|
|
test('a recovered snapshot retains deliberate values and reports conflicting funding origins', () => {
|
|
const data = {
|
|
budgetPeriod: 'Mensal',
|
|
loan: {
|
|
principal: '',
|
|
rate: '',
|
|
months: '',
|
|
rateType: 'nominal',
|
|
periodMonths: '1',
|
|
gracePeriods: '',
|
|
upfrontFee: '',
|
|
recurringFee: '',
|
|
},
|
|
breakEven: { fixed: '', price: '', variable: '' },
|
|
funding: { total: '2000000', secured: '250000' },
|
|
incomes: [{ label: 'Receitas', amount: '' }],
|
|
expenses: [{ label: 'Custos', amount: '' }],
|
|
};
|
|
const snapshot = serializeFinancialToolsSnapshot(data);
|
|
const draft = {
|
|
total_investment: '2000000',
|
|
secured_amount: '1000000',
|
|
financial_tools_snapshot: snapshot,
|
|
};
|
|
assert.deepEqual(draftFundingDifferences(draft), ['secured']);
|
|
assert.equal(
|
|
draft.financial_tools_snapshot,
|
|
snapshot,
|
|
'a check must not silently replace the restored calculator',
|
|
);
|
|
assert.deepEqual(
|
|
draftFundingDifferences({ ...draft, secured_amount: '250000.00' }),
|
|
[],
|
|
);
|
|
});
|
|
|
|
test('fresh cashflow assumptions contain no demonstration amounts', () => {
|
|
for (const [key, value] of Object.entries(defaultCashflowDraftInputs())) {
|
|
if (typeof value === 'string' && /^\d/.test(value))
|
|
assert.fail(`Unexpected automatic amount in ${key}`);
|
|
}
|
|
});
|