Identify IRPC income category and retention nature in Portuguese
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import {irpcBook,irpcReportRows,irpcPreparationHtml} from '../../resources/js/lib/irpc-withholdings.ts';
|
||||
test('each saved calculation identifies income category rate and Portuguese nature without recalculation',()=>{
|
||||
const d=JSON.parse(fs.readFileSync(new URL('./fixtures/irpc-grouped-preserved.json',import.meta.url),'utf8')),before=JSON.stringify(irpcBook(d)),rows=irpcReportRows(d);
|
||||
assert.equal(rows.length,6);for(const r of rows){assert.match(r[2],/enquadramento:/);assert.match(r[2],/taxa:(10|20)%/);assert.match(r[3],/Retenção definitiva|Imposto por conta/);}
|
||||
assert.match(rows[2][2],/Propriedade intelectual\/industrial/);assert.match(rows[3][2],/Serviços de telecomunicações/);assert.match(rows[4][3],/Imposto por conta/);assert.match(rows[0][3],/Retenção definitiva/);assert.equal(JSON.stringify(irpcBook(d)),before);const html=irpcPreparationHtml(d);assert.match(html,/Retenção definitiva/);assert.match(html,/Imposto por conta/);assert.ok(!html.includes(';definitive;'));
|
||||
});
|
||||
@@ -22,7 +22,7 @@ test('duplicate document, duplicate proof ID or duplicate reference do not doubl
|
||||
test('reuse is idempotent, inherits supplier/document/amount, preserves deliberate edits and detects source delta',()=>{const d=draft(),ab=acquisitionBook(d),a={...newAcquisition('L5-supplier','2026-10','MZN'),supplier:'SYNTHETIC saved supplier',documentRef:'SYNTHETIC invoice',documentLine:'1',net:'100000',description:'SaaS'};d.modelo_a_snapshot=saveAcquisitionBook(d,{...ab,rows:[...ab.rows,a]});let b=reuseIrpcSources(d,irpcBook(d));assert.equal(reuseIrpcSources(d,b).rows.length,b.rows.length);let r=b.rows.find(r=>r.source?.id==='acquisition:L5-supplier');assert.equal(r.counterparty,a.supplier);assert.equal(r.documentRef,'SYNTHETIC invoice / linha 1');r.base='90000';assert.equal(reuseIrpcSources(d,b).rows.find(v=>v.id===r.id).base,'90000');b={version:1,rows:[{...row(),id:r.id,source:r.source}],payments:[]};const current=acquisitionBook(d);d.modelo_a_snapshot=saveAcquisitionBook(d,{...current,rows:current.rows.map(v=>v.id===a.id?{...v,net:'120000'}:v)});assert.match(recordIrpc(d,b).result.rows[0].reason,/origem alterado/);});
|
||||
test('save/recover preserves all preexisting maps, history, context separation and frozen report',()=>{const d=draft(),prior=JSON.parse(d.modelo_a_snapshot),b=recordIrpc(d,book());d.modelo_a_snapshot=saveIrpcBook(d,b);const now=JSON.parse(d.modelo_a_snapshot);for(const[k,v]of Object.entries(prior))assert.deepEqual(now[k],v);assert.deepEqual(irpcBook(d).result,b.result);assert.equal(irpcCurrent(d,b),true);b.rows[0].base='200000';assert.equal(irpcCurrent(d,b),false);assert.match(irpcReportRows({...d,modelo_a_snapshot:saveIrpcBook(d,b)})[0][2],/10000.00/);assert.equal(recordIrpc(d,b).history.length,1);d.context_opportunity='other';assert.equal(irpcBook(d).rows.length,0);});
|
||||
test('malformed store remains recoverable as explicit error, never overwritten blank',()=>{assert.throws(()=>irpcBook({modelo_a_snapshot:'{"version":1,"books":{},"irpcWithholdings":[]}'}));const d=draft(),b=book();b.rows[0].events=[{kind:'madeup',date:'2026-10-01',reference:'x'}];assert.throws(()=>saveIrpcBook(d,b));});
|
||||
test('export escapes private inputs, retains period/nature/gaps and excludes submission claims',()=>{const d=draft(),r={...row(),counterparty:'<script>alert(1)</script>'};d.modelo_a_snapshot=saveIrpcBook(d,recordIrpc(d,book(r)));const html=irpcPreparationHtml(d);assert.ok(!html.includes('<script>'));assert.match(html,/<script>/);assert.match(html,/sem submissão/);assert.match(html,/CER/);assert.match(html,/2026-10/);assert.match(html,/definitive/);});
|
||||
test('export escapes private inputs, retains period/nature/gaps and excludes submission claims',()=>{const d=draft(),r={...row(),counterparty:'<script>alert(1)</script>'};d.modelo_a_snapshot=saveIrpcBook(d,recordIrpc(d,book(r)));const html=irpcPreparationHtml(d);assert.ok(!html.includes('<script>'));assert.match(html,/<script>/);assert.match(html,/sem submissão/);assert.match(html,/CER/);assert.match(html,/2026-10/);assert.match(html,/Retenção definitiva/);});
|
||||
if(process.env.IRPC_FIXTURE_OUTPUT){const d=draft(),b=recordIrpc(d,{version:1,rows:[{...row(),settlement:'complete',allocations:[{paymentId:'p1',amount:'6000'}]},{...row('commission'),base:'20000',kind:'emoney_commission',direction:'received',settlement:'complete',allocations:[{paymentId:'p2',amount:'1500'}]}],payments:[{id:'p1',kind:'remittance',reference:'SYNTHETIC-AT1',date:'2026-10-20',amount:'6000',currency:'MZN'},{id:'p2',kind:'withholding_proof',reference:'SYNTHETIC-PROOF1',date:'2026-10-20',amount:'1500',currency:'MZN'}]});d.modelo_a_snapshot=saveIrpcBook(d,b);fs.writeFileSync(process.env.IRPC_FIXTURE_OUTPUT,JSON.stringify(d,null,2)+'\n');}
|
||||
|
||||
test("allocation changes in another opportunity mark previous result stale only for shared payments",()=>{const d=draft(),p={id:'p',kind:'remittance',reference:'SYNTHETIC-SHARED',date:'2026-10-20',amount:'10000',currency:'MZN'},r={...row(),settlement:'complete',allocations:[{paymentId:'p',amount:'6000'}]},b=recordIrpc(d,{...book(r),payments:[p]});d.modelo_a_snapshot=saveIrpcBook(d,b);assert.equal(irpcCurrent(d,b),true);const ctx=d.context_opportunity;d.context_opportunity='other';d.modelo_a_snapshot=saveIrpcBook(d,book(row('unrelated')));d.context_opportunity=ctx;assert.equal(irpcCurrent(d,b),true);d.context_opportunity='other';d.modelo_a_snapshot=saveIrpcBook(d,{...book({...row('shared'),settlement:'complete',allocations:[{paymentId:'p',amount:'1000'}]}),payments:[p]});d.context_opportunity=ctx;assert.equal(irpcCurrent(d,b),false);assert.match(irpcReportRows(d)[0][3],/Histórico/);});
|
||||
|
||||
Reference in New Issue
Block a user