99 lines
3.8 KiB
JavaScript
99 lines
3.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
calculatePecObligation,
|
|
validatePecObligation,
|
|
} from '../../resources/js/lib/irpc-pec-obligation.ts';
|
|
import { plan } from './helpers/irpc-pec-obligation-case.mjs';
|
|
import { combinedCase } from './helpers/irpc-investment-combination-case.mjs';
|
|
import {
|
|
calculateAnnual,
|
|
recordAnnual,
|
|
annualCurrent,
|
|
annualBook,
|
|
saveAnnualBook,
|
|
annualHtml,
|
|
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
|
const f = (n) => ({ numerator: String(n), denominator: '1' }),
|
|
calc = (p) => calculatePecObligation(p, '123456789', '2026', 'normal');
|
|
test('PEC caps percentage before subtracting actual previous PPC; no PPC instalment rounding reused', () => {
|
|
let m = calc(plan());
|
|
assert.deepEqual(m.percentage, f(50000));
|
|
assert.deepEqual(m.total, f(40000));
|
|
assert.deepEqual(m.months, ['2026-06', '2026-08', '2026-10']);
|
|
assert.equal(m.paymentExecuted, false);
|
|
assert.equal(m.annualDeductionCreated, false);
|
|
assert.equal(m.instalmentAmountsDetermined, false);
|
|
assert.deepEqual(
|
|
calc({ ...plan(), previousTurnover: '1000000' }).total,
|
|
f(20000),
|
|
);
|
|
assert.deepEqual(
|
|
calc({ ...plan(), previousTurnover: '50000000' }).total,
|
|
f(90000),
|
|
);
|
|
assert.deepEqual(calc({ ...plan(), previousPpcPaid: '50000' }).total, f(0));
|
|
});
|
|
test('documented first activity year is not applicable without fabricating previous business figures', () => {
|
|
const m = calc({
|
|
...plan(),
|
|
activityStartYear: '2026',
|
|
previousTurnover: '',
|
|
previousPpcPaid: '',
|
|
turnoverReference: '',
|
|
ppcReference: '',
|
|
});
|
|
assert.deepEqual(m.pending, []);
|
|
assert.equal(m.notApplicable, true);
|
|
assert.deepEqual(m.total, f(0));
|
|
assert.deepEqual(m.months, []);
|
|
});
|
|
test('unknown turnover is distinct from zero; no turnover requires29(5),excess PPC never becomes refund', () => {
|
|
for (const change of [
|
|
{ previousTurnover: '' },
|
|
{ previousTurnover: '0' },
|
|
{ previousPpcPaid: '' },
|
|
{ previousPpcPaid: '60000' },
|
|
{ scope: 'other' },
|
|
{ subjectNuit: '999999999' },
|
|
{ previousYear: '2024' },
|
|
{ activityStartYear: '2027' },
|
|
{ activityReference: '' },
|
|
{ turnoverReference: '' },
|
|
{ ppcReference: '' },
|
|
]) {
|
|
const m = calc({ ...plan(), ...change });
|
|
assert.ok(m.pending.length);
|
|
assert.equal(m.total, null);
|
|
}
|
|
assert.match(
|
|
calc({ ...plan(), previousTurnover: '0' }).pending.join(' '),
|
|
/29\(5\)/,
|
|
);
|
|
assert.throws(() =>
|
|
validatePecObligation({ ...plan(), previousTurnover: null }),
|
|
);
|
|
});
|
|
test('existing private book and annual history retain PEC preparation without changing paid deductions or balance', () => {
|
|
const { d, b } = combinedCase(),
|
|
before = calculateAnnual(d, b);
|
|
const prior = recordAnnual(d, b, '2026-11-11T10:30:00Z');
|
|
prior.pecObligation = { ...plan(), subjectNuit: b.subjectNuit };
|
|
assert.equal(annualCurrent(d, prior), false);
|
|
const next = recordAnnual(d, prior, '2026-11-11T10:31:00Z');
|
|
d.modelo_a_snapshot = saveAnnualBook(d, next);
|
|
const back = annualBook(d);
|
|
assert.equal(back.history.length, 1);
|
|
assert.equal(annualCurrent(d, back), true);
|
|
assert.deepEqual(back.pecObligation, next.pecObligation);
|
|
assert.deepEqual(
|
|
back.result.model.arithmeticBalance,
|
|
before.arithmeticBalance,
|
|
);
|
|
assert.deepEqual(back.pecPayments, b.pecPayments);
|
|
assert.match(annualHtml(d), /PEC — estimativa fiscal/);
|
|
assert.match(annualHtml(d), /2026-06/);
|
|
});
|
|
|
|
test('documented old activity is not excluded by an invented1900 cut-off',()=>{assert.deepEqual(calc({...plan(),activityStartYear:'1899'}).total,f(40000));});
|