import assert from 'node:assert/strict'; import test from 'node:test'; import { serializeBusinessPlanSnapshot } from '../../resources/js/lib/business-financial-plan.ts'; import { ivaTreatmentForCae } from '../../resources/js/lib/iva-activity.ts'; import { monthlyIvaInput, monthlyIvaKey, monthlyIvaTreatment, } from '../../resources/js/lib/monthly-iva.ts'; const settings = { start: '2026-01', basis: 'net', declared: true, auto: true }; function draftWith(cae) { const zero = Object.fromEntries( [ 'openingCash', 'monthlyCollections', 'monthlyVariableCostPayments', 'monthlyInventoryPurchases', 'monthlyOperatingExpenses', 'monthlyOperatingPayments', 'monthlyPayrollExpense', 'monthlyPayrollPayments', 'assetInvestment', 'inventory', 'receivables', 'payables', 'equity', 'shareholderLoans', 'bankLoanProceeds', 'grants', 'assetDepreciation', 'monthlyInterestExpense', 'monthlyInterestPayment', 'monthlyPrincipalRepayment', ].map((key) => [key, '0']), ); return { currency: 'MZN', business_plan_snapshot: serializeBusinessPlanSnapshot({ ...zero, currency: 'MZN', periods: 2, depreciationLifeMonths: 60, products: [ { label: 'Serviço', monthlyUnits: '10', unitPrice: '1000', unitVariableCost: '0', }, ], ...(cae ? { economicClassification: { code: cae, revision: 'CAE-Rev.2', sourceSha256: 'cb3dee56db5b2c3f12e3071615725051828a9e1eba17662aa5e78d5f3356b0fc', }, } : {}), }), }; } test('IVA follows the activity: health and education at 5% (artigo 17-A), everything else at 16%', () => { assert.equal(ivaTreatmentForCae('86201').rate, 5); assert.match(ivaTreatmentForCae('86201').article, /17-A\(a\)/); assert.equal(ivaTreatmentForCae('85300').rate, 5); assert.match(ivaTreatmentForCae('85300').article, /17-A\(b\)/); assert.match(ivaTreatmentForCae('85492').article, /17-A\(c\)/); assert.ok( ivaTreatmentForCae('85300').conditions.some((c) => /reconhecido/.test(c), ), ); for (const code of ['55111', '01111', '85410']) assert.equal(ivaTreatmentForCae(code).rate, 16, code); assert.equal(ivaTreatmentForCae(undefined).fromActivity, false); assert.equal(ivaTreatmentForCae('55111').fromActivity, true); }); test('the monthly IVA asks the server for the reduced version only for a 17-A activity, and earlier hotel results stay current', () => { const clinic = monthlyIvaInput(draftWith('86201'), settings); assert.equal(clinic.operation, 'internal_reduced_17a_net'); assert.equal(monthlyIvaTreatment(draftWith('86201')).rate, 5); const hotel = monthlyIvaInput(draftWith('55111'), settings); assert.equal('operation' in hotel, false); const unclassified = monthlyIvaInput(draftWith(null), settings); assert.equal(monthlyIvaKey(hotel), monthlyIvaKey(unclassified)); assert.notEqual( monthlyIvaKey(clinic), monthlyIvaKey(hotel), 'a change of activity makes the earlier result stale', ); });