fix: reconcile annual example ledger and illustrative months in QA

This commit is contained in:
2026-11-20 11:01:28 +02:00
parent e27b354192
commit 65a52aa3c9
10 changed files with 935 additions and 7 deletions
+76 -1
View File
@@ -61,7 +61,11 @@ void test('insufficient funding and growth above 100 percent remain valid, saved
assert.equal(restored.annualGrowthPercent, '250');
const result = forecastBusinessPlan(restored);
assert.equal(result.fundingGap, '200.00');
assert.equal(result.totalRevenue, '12000.00', 'a growth target must not overwrite declared sales');
assert.equal(
result.totalRevenue,
'12000.00',
'a growth target must not overwrite declared sales',
);
assert.equal(
validateSimulationDraft(
{ business_plan_snapshot: snapshot },
@@ -115,6 +119,50 @@ void test('owner annual reference reconciles exact startup, margins, profits, ca
assert.equal(result.years[2].closingCash, '93498.00');
assert.equal(result.monthlyStatus, 'por reconciliar');
assert.equal('monthlyRows' in result, false);
assert.deepEqual(
result.years.map((year) => year.operatingLiabilities),
['1641.00', '1417.00', '1598.00'],
);
assert.deepEqual(
result.years.map((year) => year.receivables),
['469.00', '694.00', '771.00'],
);
assert.deepEqual(
result.years.map((year) => year.closingAssets),
['501475.00', '502707.00', '504519.00'],
);
assert.equal(result.capitalToMobilise, '1825250.00');
const cents = (value) => BigInt(value.replace('.', ''));
for (const [index, year] of result.years.entries()) {
assert.equal(year.balanceDifference, '0.00');
assert.equal(year.illustrativeMonths.length, 12);
for (const key of [
'sales',
'directCosts',
'netProfit',
'cashReceived',
'cashSpent',
]) {
const expected =
key === 'netProfit' ? year[key] : source.years[index][key];
assert.equal(
year.illustrativeMonths.reduce(
(sum, row) => sum + cents(row[key]),
0n,
),
cents(Number(expected).toFixed(2)),
);
}
for (const month of year.illustrativeMonths)
assert.equal(month.balanceDifference, '0.00');
const last = year.illustrativeMonths.at(-1);
for (const key of [
'closingCash',
'receivables',
'operatingLiabilities',
])
assert.equal(last[key], year[key]);
}
const warnings = businessPlanWarnings({
fundingGap: Number(result.fundingGap),
netProfit: Number(first.netProfit),
@@ -127,6 +175,33 @@ void test('owner annual reference reconciles exact startup, margins, profits, ca
assert.equal(JSON.stringify(source), before);
});
void test('derived ledger reconciles edited cents and surplus funding without altering annual inputs', () => {
const plan = newAnnualReferencePlan();
plan.ownerCapital = '2000000.01';
plan.years[0].sales = '14537.01';
plan.years[0].cashSpent = '15783.01';
plan.years[0].payrollCharges = '315.01';
plan.years[0].vatPaid = '2470.99';
const before = JSON.stringify(plan);
const result = calculateAnnualReferencePlan(plan);
assert.equal(result.capitalToMobilise, '0.00');
assert.equal(result.years[0].closingCash, '265506.00');
assert.equal(result.years[0].receivables, '469.01');
assert.equal(result.years[0].vatBalance, '0.01');
for (const year of result.years) {
assert.equal(year.balanceDifference, '0.00');
for (const month of year.illustrativeMonths)
assert.equal(month.balanceDifference, '0.00');
assert.equal(
year.illustrativeMonths.at(-1).closingCash,
year.closingCash,
);
}
assert.equal(JSON.stringify(plan), before);
plan.years[0].vatReceived = '16539.01';
assert.throws(() => calculateAnnualReferencePlan(plan), /IVA/);
});
void test('reference edits update dependent totals and preserve data when an input is invalid', () => {
const source = newAnnualReferencePlan();
source.startupExpenses[0].amount = '25000.25';