94 lines
3.3 KiB
JavaScript
94 lines
3.3 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { economicCase } from './helpers/irpc-economic-case.mjs';
|
|
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';
|
|
|
|
function quotaCase() {
|
|
const c = economicCase();
|
|
Object.assign(c.b.economicCredits.rows[0], {
|
|
nationalMethod: 'proportional',
|
|
nationalBasisReference:
|
|
'SYNTHETIC QA: profits100 plus nominal60 already included and reconciled in current ordinary base4400',
|
|
taxAmount: '100',
|
|
proofAmount: '100',
|
|
grossUpIncluded: '60',
|
|
grossUpReference:
|
|
'SYNTHETIC QA: nominal60 already included; no base change',
|
|
});
|
|
return c;
|
|
}
|
|
void test('economic quota derives from profits plus the existing gross-up, without changing L6', () => {
|
|
const c = quotaCase(),
|
|
before = c.d.modelo_a_snapshot;
|
|
const m = calculateAnnual(c.d, c.b);
|
|
assert.deepEqual(m.pending, []);
|
|
assert.deepEqual(m.economicCredit.rows[0].nationalLimit, {
|
|
numerator: '256',
|
|
denominator: '5',
|
|
});
|
|
assert.deepEqual(m.economicCredit.deducted, {
|
|
numerator: '256',
|
|
denominator: '5',
|
|
});
|
|
assert.deepEqual(m.payable, { numerator: '3244', denominator: '5' });
|
|
assert.equal(c.d.modelo_a_snapshot, before);
|
|
assert.equal(m.economicCredit.rows[0].input.nationalLimit, '32');
|
|
});
|
|
void test('economic quota survives saving and recovery into both report consumers with its origin', () => {
|
|
const c = quotaCase();
|
|
const book = recordAnnual(c.d, c.b, '2026-11-10T14:00:00+02:00');
|
|
const d = JSON.parse(
|
|
JSON.stringify({
|
|
...c.d,
|
|
modelo_a_snapshot: saveAnnualBook(c.d, book),
|
|
}),
|
|
);
|
|
const recovered = annualBook(d);
|
|
assert.equal(annualCurrent(d, recovered), true);
|
|
assert.deepEqual(
|
|
calculateAnnual(d, recovered).economicCredit,
|
|
recovered.result.model.economicCredit,
|
|
);
|
|
assert.match(annualHtml(d), /IRPC-economic-quota\/1/);
|
|
assert.match(
|
|
JSON.stringify(
|
|
createProjectDossierReport(d, {
|
|
selectedSections: new Set(['finance']),
|
|
generatedAt: '2026-11-10T14:00:00+02:00',
|
|
}),
|
|
),
|
|
/256\/5/,
|
|
);
|
|
});
|
|
void test('economic quota requires support, positive matched base and a still-current assessment', () => {
|
|
for (const patch of [
|
|
{ nationalBasisReference: '' },
|
|
{ income: '4500' },
|
|
{ assessmentKey: 'obsolete' },
|
|
{ grossUpIncluded: '0' },
|
|
]) {
|
|
const c = quotaCase();
|
|
Object.assign(c.b.economicCredits.rows[0], patch);
|
|
const m = calculateAnnual(c.d, c.b);
|
|
assert.equal(m.status, 'indeterminate');
|
|
assert.equal(m.arithmeticBalance, null);
|
|
}
|
|
});
|
|
void test('economic quota defaults to the accepted documented path for old books', () => {
|
|
const c = economicCase();
|
|
const m = calculateAnnual(c.d, c.b);
|
|
assert.equal(m.economicCredit.rows[0].nationalDerivation, undefined);
|
|
assert.deepEqual(m.economicCredit.rows[0].nationalLimit, {
|
|
numerator: '32',
|
|
denominator: '1',
|
|
});
|
|
});
|