116 lines
4.6 KiB
JavaScript
116 lines
4.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { internationalCase } from './helpers/irpc-international-case.mjs';
|
|
import { newPtMzRoyaltyPreparation } from '../../resources/js/lib/irpc-international-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';
|
|
function governmentCase(payer = 'state') {
|
|
const c = internationalCase();
|
|
Object.assign(c.b.internationalCredits.positions[0], {
|
|
country: 'PT',
|
|
qualificationCountry: 'PT',
|
|
incomeAmount: '40',
|
|
treaty: 'yes',
|
|
treatyMethod: 'ptMzInterest',
|
|
treatyReference:
|
|
'SYNTHETIC QA PT-MZ11(3)a and23(3)a, not a real entitlement assertion',
|
|
treatyPreparation: {
|
|
...newPtMzRoyaltyPreparation(),
|
|
gross: '60',
|
|
from: '2026-01-01',
|
|
to: '2026-12-31',
|
|
reference:
|
|
'SYNTHETIC residence, interest and nonlinked EP conditions documented',
|
|
residentMz: 'yes',
|
|
beneficialOwner: 'yes',
|
|
sourcePortugal: 'yes',
|
|
payerResidentPt: 'yes',
|
|
noLinkedEstablishment: 'yes',
|
|
armLength: 'yes',
|
|
capitalDefinition: 'yes',
|
|
governmentInterestExemption: 'yes',
|
|
governmentPayer: payer,
|
|
governmentPayerReference:
|
|
'SYNTHETIC Portuguese public payer identified by supported legal status',
|
|
},
|
|
});
|
|
return c;
|
|
}
|
|
void test('documented Portuguese state,subdivision and local public payers yield zero treaty ceiling,not a tax refund', () => {
|
|
for (const payer of ['state', 'subdivision', 'local']) {
|
|
const c = governmentCase(payer),
|
|
before = c.d.modelo_a_snapshot,
|
|
m = calculateAnnual(c.d, c.b),
|
|
p = m.internationalCredit.positions[0];
|
|
assert.deepEqual(m.pending, []);
|
|
assert.deepEqual(p.treatyLimit, { numerator: '0', denominator: '1' });
|
|
assert.deepEqual(p.eligible, { numerator: '0', denominator: '1' });
|
|
assert.deepEqual(p.aboveLimit, { numerator: '10', denominator: '1' });
|
|
assert.deepEqual(m.arithmeticBalance, {
|
|
numerator: '708',
|
|
denominator: '1',
|
|
});
|
|
assert.equal(p.treatyDerivation.rate, '0');
|
|
assert.equal(c.d.modelo_a_snapshot, before);
|
|
assert.equal(m.internationalCredit.carryCreated, false);
|
|
}
|
|
});
|
|
void test('government exemption cannot be inferred from a flag,name,unknown payer or undocumented classification', () => {
|
|
for (const patch of [
|
|
{ governmentPayer: '' },
|
|
{ governmentPayerReference: '' },
|
|
{ governmentInterestExemption: '' },
|
|
{ capitalDefinition: '' },
|
|
{ noLinkedEstablishment: '' },
|
|
]) {
|
|
const c = governmentCase();
|
|
Object.assign(
|
|
c.b.internationalCredits.positions[0].treatyPreparation,
|
|
patch,
|
|
);
|
|
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
|
}
|
|
});
|
|
void test('documented absence of governmental exemption keeps the accepted ordinary10percent path', () => {
|
|
const c = governmentCase();
|
|
c.b.internationalCredits.positions[0].treatyPreparation.governmentInterestExemption =
|
|
'no';
|
|
const p = calculateAnnual(c.d, c.b).internationalCredit.positions[0];
|
|
assert.deepEqual(p.treatyLimit, { numerator: '6', denominator: '1' });
|
|
assert.equal(p.treatyDerivation.governmentExemption, undefined);
|
|
});
|
|
void test('government exemption and noncreditable paid tax recover into HTML and dossier without rewriting L6', () => {
|
|
const c = governmentCase(),
|
|
b = recordAnnual(c.d, c.b, '2026-11-10T18:00: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).internationalCredit,
|
|
back.result.model.internationalCredit,
|
|
);
|
|
assert.match(annualHtml(d), /IRPC-PT-MZ-government-interest\/1/);
|
|
assert.match(annualHtml(d), /SYNTHETIC Portuguese public payer identified/);
|
|
assert.match(
|
|
JSON.stringify(
|
|
createProjectDossierReport(d, {
|
|
selectedSections: new Set(['finance']),
|
|
generatedAt: '2026-11-10T18:00:00+02:00',
|
|
}),
|
|
),
|
|
/IRPC-PT-MZ-government-interest\/1/,
|
|
);
|
|
});
|