82 lines
2.7 KiB
JavaScript
82 lines
2.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import {
|
|
ispcWithholdingBook,
|
|
saveIspcWithholdingBook,
|
|
recordIspcWithholding,
|
|
ispcWithholdingReportRows,
|
|
} from '../../resources/js/lib/ispc-withholding.ts';
|
|
const seed = JSON.parse(
|
|
fs.readFileSync(
|
|
new URL('./fixtures/ispc-quarter-preserved.json', import.meta.url),
|
|
'utf8',
|
|
),
|
|
);
|
|
function evaluate(p = {}) {
|
|
const d = structuredClone(seed),
|
|
b = ispcWithholdingBook(d);
|
|
b.input = {
|
|
...b.input,
|
|
applicable: 'yes',
|
|
base: '10000',
|
|
priorAnnualPurchases: '0',
|
|
naturalOccasional: 'yes',
|
|
unregistered: 'yes',
|
|
related: 'yes',
|
|
activity: 'agriculture',
|
|
reference: 'SYNTHETIC QA fornecedor e aquisição',
|
|
...p,
|
|
};
|
|
return { d, b, r: recordIspcWithholding(d, b) };
|
|
}
|
|
void test('fivepercent withholding notownquartertax;small withholding notexempt via500minimum', () => {
|
|
let { r } = evaluate();
|
|
assert.deepEqual(r.result.withheld, { numerator: '500', denominator: '1' });
|
|
r = evaluate({ base: '100' }).r;
|
|
assert.deepEqual(r.result.withheld, { numerator: '5', denominator: '1' });
|
|
});
|
|
void test('globalannual2.5minclusive,exceedingnottruncated;missingnotzero;scopeexclusionsspecific', () => {
|
|
assert.equal(
|
|
evaluate({ priorAnnualPurchases: '2490000' }).r.result.status,
|
|
'calculated',
|
|
);
|
|
assert.equal(
|
|
evaluate({ priorAnnualPurchases: '2490000.000001' }).r.result.status,
|
|
'indeterminate',
|
|
);
|
|
assert.equal(
|
|
evaluate({ priorAnnualPurchases: '' }).r.result.status,
|
|
'indeterminate',
|
|
);
|
|
for (const p of [
|
|
{ naturalOccasional: 'no' },
|
|
{ unregistered: 'no' },
|
|
{ related: 'no' },
|
|
{ activity: 'other' },
|
|
{ applicable: 'no' },
|
|
])
|
|
assert.equal(evaluate(p).r.result.status, 'not_applicable');
|
|
assert.equal(
|
|
evaluate({ naturalOccasional: '' }).r.result.status,
|
|
'indeterminate',
|
|
);
|
|
});
|
|
void test('withholdingrecoverhistoryandotherbookspreserved;reportneveroffsetsowntax', () => {
|
|
let { d, r } = evaluate();
|
|
const prior = JSON.parse(d.modelo_a_snapshot);
|
|
d.modelo_a_snapshot = saveIspcWithholdingBook(d, r);
|
|
assert.deepEqual(
|
|
JSON.parse(d.modelo_a_snapshot).ispcQuarters,
|
|
prior.ispcQuarters,
|
|
);
|
|
const b = ispcWithholdingBook(d);
|
|
assert.equal(b.result.status, 'calculated');
|
|
b.input.base = '20000';
|
|
r = recordIspcWithholding(d, b);
|
|
assert.equal(r.history.length, 1);
|
|
assert.equal(r.history[0].withheld.numerator, '500');
|
|
d.modelo_a_snapshot = saveIspcWithholdingBook(d, r);
|
|
assert.match(JSON.stringify(ispcWithholdingReportRows(d)), /1000.00/);
|
|
});
|