84 lines
3.0 KiB
JavaScript
84 lines
3.0 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 associationCase(kind = 'participation', effectivelyTaxed = 'yes') {
|
|
const c = economicCase();
|
|
Object.assign(c.b.economicCredits.rows[0], {
|
|
kind: 'association',
|
|
association: {
|
|
kind,
|
|
effectivelyTaxed,
|
|
reference:
|
|
'SYNTHETIC QA contract and distributed income; documented adaptation64(4)',
|
|
},
|
|
nationalMethod: 'proportional',
|
|
nationalBasisReference:
|
|
'SYNTHETIC included100 plus nominal12 in current base4400',
|
|
});
|
|
return c;
|
|
}
|
|
void test('participation and quota use only the documented economic tax and preserve L6 and other deductions', () => {
|
|
for (const kind of ['participation', 'quota']) {
|
|
const c = associationCase(kind, kind === 'quota' ? '' : 'yes'),
|
|
before = c.d.modelo_a_snapshot,
|
|
m = calculateAnnual(c.d, c.b);
|
|
assert.deepEqual(m.pending, []);
|
|
assert.deepEqual(m.economicCredit.deducted, {
|
|
numerator: '12',
|
|
denominator: '1',
|
|
});
|
|
assert.deepEqual(m.arithmeticBalance, {
|
|
numerator: '688',
|
|
denominator: '1',
|
|
});
|
|
assert.equal(c.d.modelo_a_snapshot, before);
|
|
}
|
|
});
|
|
void test('participation cannot infer effective taxation and unknown contract stays recoverable but indeterminate', () => {
|
|
for (const patch of [
|
|
{ kind: 'participation', effectivelyTaxed: '' },
|
|
{ kind: 'participation', effectivelyTaxed: 'no' },
|
|
{ kind: '', effectivelyTaxed: 'yes' },
|
|
{ reference: '' },
|
|
]) {
|
|
const c = associationCase();
|
|
Object.assign(c.b.economicCredits.rows[0].association, patch);
|
|
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
|
}
|
|
});
|
|
void test('association adaptation survives recovery and both report consumers without resetting old inputs', () => {
|
|
const c = associationCase(),
|
|
b = recordAnnual(c.d, c.b, '2026-11-10T16:10:00+02:00'),
|
|
d = JSON.parse(
|
|
JSON.stringify({
|
|
...c.d,
|
|
modelo_a_snapshot: saveAnnualBook(c.d, b),
|
|
}),
|
|
),
|
|
back = annualBook(d);
|
|
assert.equal(annualCurrent(d, back), true);
|
|
assert.deepEqual(
|
|
calculateAnnual(d, back).economicCredit,
|
|
back.result.model.economicCredit,
|
|
);
|
|
assert.match(annualHtml(d), /IRPC-economic-association\/1/);
|
|
assert.match(
|
|
JSON.stringify(
|
|
createProjectDossierReport(d, {
|
|
selectedSections: new Set(['finance']),
|
|
generatedAt: '2026-11-10T16:10:00+02:00',
|
|
}),
|
|
),
|
|
/IRPC-economic-association\/1/,
|
|
);
|
|
});
|