101 lines
4.0 KiB
JavaScript
101 lines
4.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
newPecCorrection,
|
|
validatePecCorrection,
|
|
} from '../../resources/js/lib/irpc-pec-correction.ts';
|
|
import { calculatePecObligation } from '../../resources/js/lib/irpc-pec-obligation.ts';
|
|
import {
|
|
calculatePecPlan,
|
|
newPecPlan,
|
|
} from '../../resources/js/lib/irpc-pec-plan.ts';
|
|
import { plan } from './helpers/irpc-pec-obligation-case.mjs';
|
|
import { combinedCase } from './helpers/irpc-investment-combination-case.mjs';
|
|
import {
|
|
recordAnnual,
|
|
annualCurrent,
|
|
annualBook,
|
|
saveAnnualBook,
|
|
annualHtml,
|
|
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
|
const f = (n) => ({ numerator: String(n), denominator: '1' }),
|
|
corrected = (p = plan()) => ({
|
|
...p,
|
|
correction: {
|
|
...newPecCorrection(p.previousTurnover, p.subjectNuit),
|
|
apply: 'yes',
|
|
revisedTurnover: '50000000',
|
|
reference: 'SYNTHETIC corrected sales2025 reviewed2026',
|
|
},
|
|
}),
|
|
calc = (p) => calculatePecObligation(p, p.subjectNuit, p.year, 'normal');
|
|
test('documented correction preserves original and recomputes percentage,cap and previous PPC once', () => {
|
|
const p = corrected(),
|
|
m = calc(p);
|
|
assert.equal(p.previousTurnover, '10000000');
|
|
assert.deepEqual(m.total, f(90000));
|
|
assert.deepEqual(calc(plan()).total, f(40000));
|
|
assert.equal(m.turnoverCorrection.applied, true);
|
|
assert.equal(m.annualDeductionCreated, false);
|
|
});
|
|
test('explicitly retaining original leaves corrective values recoverable without using them', () => {
|
|
const p = corrected();
|
|
p.correction.apply = 'no';
|
|
assert.deepEqual(calc(p).total, f(40000));
|
|
assert.equal(p.correction.revisedTurnover, '50000000');
|
|
const {d,b}=combinedCase();b.pecObligation={...p,subjectNuit:b.subjectNuit,correction:{...p.correction,subjectNuit:b.subjectNuit}};d.modelo_a_snapshot=saveAnnualBook(d,recordAnnual(d,b,'2026-11-11T12:05:00Z'));assert.match(annualHtml(d),/Estimativa original: 40000/);assert.match(annualHtml(d),/efeito na estimativa: 0/);
|
|
p.correction.apply = '';
|
|
assert.equal(calc(p).total, null);
|
|
});
|
|
test('changed original,titular,year and absent evidence cannot silently qualify correction;zero uses29(5)', () => {
|
|
for (const patch of [
|
|
{ originalTurnover: '1' },
|
|
{ subjectNuit: '999999999' },
|
|
{ turnoverYear: '2024' },
|
|
{ reference: '' },
|
|
{ revisedTurnover: '' },
|
|
]) {
|
|
const p = corrected();
|
|
Object.assign(p.correction, patch);
|
|
assert.equal(calc(p).total, null);
|
|
}
|
|
const p = corrected();
|
|
p.correction.revisedTurnover = '0';
|
|
assert.match(calc(p).pending.join(' '), /29\(5\)/);
|
|
assert.throws(() =>
|
|
validatePecCorrection({ ...p.correction, revisedTurnover: null }),
|
|
);
|
|
});
|
|
test('correction invalidates old cash-flow allocation and annual snapshot;history/deductions remain intact', () => {
|
|
const { d, b } = combinedCase();
|
|
b.pecObligation = { ...plan(), subjectNuit: b.subjectNuit };
|
|
let current = recordAnnual(d, b, '2026-11-11T12:00:00Z');
|
|
current.pecObligation = corrected(current.pecObligation);
|
|
current.pecObligation.plan = {
|
|
...newPecPlan(),
|
|
mode: 'three',
|
|
reference: 'SYNTHETIC old cash hypothesis',
|
|
june: '10000',
|
|
august: '15000',
|
|
october: '15000',
|
|
};
|
|
assert.equal(annualCurrent(d, current), false);
|
|
const m = calc(current.pecObligation);
|
|
assert.ok(
|
|
calculatePecPlan(
|
|
current.pecObligation.plan,
|
|
m.total,
|
|
m.notApplicable,
|
|
'2026',
|
|
).pending.length,
|
|
);
|
|
current = recordAnnual(d, current, '2026-11-11T12:01:00Z');
|
|
d.modelo_a_snapshot = saveAnnualBook(d, current);
|
|
const back = annualBook(d);
|
|
assert.deepEqual(back.result.model.arithmeticBalance, f(138));
|
|
assert.deepEqual(back.pecPayments, b.pecPayments);
|
|
assert.equal(back.history.length, 1);
|
|
assert.equal(annualCurrent(d, back), true);
|
|
assert.match(annualHtml(d), /efeito na estimativa: 50000/);
|
|
});
|