115 lines
4.0 KiB
JavaScript
115 lines
4.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { economicCase } from './helpers/irpc-economic-case.mjs';
|
|
import { economicIncome } from '../../resources/js/lib/irpc-economic-credit.ts';
|
|
import {
|
|
calculateAnnual,
|
|
recordAnnual,
|
|
saveAnnualBook,
|
|
annualBook,
|
|
annualCurrent,
|
|
annualHtml,
|
|
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
|
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
|
export function liquidationCase() {
|
|
const c = economicCase();
|
|
Object.assign(c.b.economicCredits.rows[0], {
|
|
kind: 'liquidation',
|
|
income: '150',
|
|
liquidation: {
|
|
attributed: '200',
|
|
paidInCapital: '100',
|
|
reference:
|
|
'SYNTHETIC QA partilha: capital income150 documented; eligible100 and excess50 separately classified',
|
|
},
|
|
nationalMethod: 'proportional',
|
|
nationalBasisReference:
|
|
'SYNTHETIC eligible100 plus nominal12 in ordinary base4400',
|
|
incomeReference:
|
|
'SYNTHETIC150 included in current L6, eligible100 and capital gain50 distinguished',
|
|
});
|
|
return c;
|
|
}
|
|
void test('liquidation caps the economic-credit component and separates capital gain without changing L6', () => {
|
|
const c = liquidationCase(),
|
|
before = c.d.modelo_a_snapshot,
|
|
m = calculateAnnual(c.d, c.b),
|
|
r = m.economicCredit.rows[0];
|
|
assert.deepEqual(m.pending, []);
|
|
assert.deepEqual(r.liquidation.eligibleIncome, {
|
|
numerator: '100',
|
|
denominator: '1',
|
|
});
|
|
assert.deepEqual(r.liquidation.excessCapitalGain, {
|
|
numerator: '50',
|
|
denominator: '1',
|
|
});
|
|
assert.deepEqual(r.nationalLimit, { numerator: '896', denominator: '25' });
|
|
assert.deepEqual(r.nominal, { numerator: '12', denominator: '1' });
|
|
assert.equal(c.d.modelo_a_snapshot, before);
|
|
});
|
|
void test('liquidation handles documented lower capital income and nonpositive capital ceiling', () => {
|
|
const c = liquidationCase(),
|
|
r = c.b.economicCredits.rows[0];
|
|
r.income = '40';
|
|
assert.deepEqual(economicIncome(r).income, {
|
|
numerator: '40',
|
|
denominator: '1',
|
|
});
|
|
r.liquidation.paidInCapital = '250';
|
|
assert.deepEqual(economicIncome(r).income, {
|
|
numerator: '0',
|
|
denominator: '1',
|
|
});
|
|
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
|
});
|
|
void test('liquidation rejects unknown evidence, attribution contradictions and stale collection', () => {
|
|
for (const patch of [
|
|
{ liquidation: undefined },
|
|
{
|
|
liquidation: {
|
|
attributed: '',
|
|
paidInCapital: '0',
|
|
reference: 'QA',
|
|
},
|
|
},
|
|
{
|
|
liquidation: {
|
|
attributed: '100',
|
|
paidInCapital: '0',
|
|
reference: 'QA',
|
|
},
|
|
},
|
|
{ assessmentKey: 'stale' },
|
|
]) {
|
|
const c = liquidationCase();
|
|
Object.assign(c.b.economicCredits.rows[0], patch);
|
|
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
|
}
|
|
});
|
|
void test('liquidation recovers the exact cap and excess in both report consumers, retaining old history', () => {
|
|
const c = liquidationCase(),
|
|
book = recordAnnual(c.d, c.b, '2026-11-10T16:00:00+02:00');
|
|
const d = JSON.parse(
|
|
JSON.stringify({
|
|
...c.d,
|
|
modelo_a_snapshot: saveAnnualBook(c.d, book),
|
|
}),
|
|
),
|
|
b = annualBook(d);
|
|
assert.equal(annualCurrent(d, b), true);
|
|
assert.deepEqual(
|
|
calculateAnnual(d, b).economicCredit,
|
|
b.result.model.economicCredit,
|
|
);
|
|
assert.match(annualHtml(d), /IRPC-economic-liquidation\/1/);
|
|
const report = JSON.stringify(
|
|
createProjectDossierReport(d, {
|
|
selectedSections: new Set(['finance']),
|
|
generatedAt: '2026-11-10T16:00:00+02:00',
|
|
}),
|
|
);
|
|
assert.match(report, /IRPC-economic-liquidation\/1/);
|
|
assert.match(report, /mais-valia/);
|
|
});
|