Files
Investidor-V2/tools/irpc-economic-recovered-qa.mjs

23 lines
2.1 KiB
JavaScript

import fs from 'node:fs';
import assert from 'node:assert/strict';
import {annualBook, annualCurrent, calculateAnnual, annualHtml} from '../resources/js/lib/irpc-annual-settlement.ts';
import {createProjectDossierReport} from '../resources/js/lib/project-dossier-report.ts';
const output = new URL('../outputs/irpc-l8-economic-20261028/', import.meta.url);
const receipts = [];
for (const name of ['payable', 'combined', 'quota', 'prior-use', 'duplicate', 'missing-gross-up', 'article40', 'shared-paper', 'partial-parcel', 'fractional', 'recoverable']) {
const d = JSON.parse(fs.readFileSync(new URL('recovered-' + name + '.json', output), 'utf8'));
const b = annualBook(d), m = b.result.model;
assert.equal(annualCurrent(d, b), true); assert.deepEqual(calculateAnnual(d, b), m);
assert.equal(b.history.length, 1); assert.equal(b.history[0].model.payable.numerator, name === 'combined' ? '550' : '700');
const html = annualHtml(d), dossier = createProjectDossierReport(d, {selectedSections: new Set(['finance']), generatedAt: '2026-10-28T14:00:00+02:00'});
assert.match(html, /Crédito económico — antes do internacional/); assert.match(JSON.stringify(dossier), /Crédito económico/);
if (name === 'combined') {assert.match(html, /538.00/); assert.match(html, /Saldo anterior — PEC — 2023/);}
if (name === 'payable') {assert.match(html, /688.00/); assert.match(html, /1396.00/);}
if (name === 'fractional') assert.deepEqual(m.arithmeticBalance, {numerator: '349997', denominator: '500'});
fs.writeFileSync(new URL('report-' + name + '.html', output), html);
fs.writeFileSync(new URL('dossier-' + name + '.json', output), JSON.stringify(dossier));
receipts.push({name, status: m.status, balance: m.arithmeticBalance, economicDeduction: m.economicCredit.deducted, apiRecovered: true, recalculationEqual: true, html: true, dossier: true, frozenHistoryPreserved: true});
}
fs.writeFileSync(new URL('recovered-report-receipt.json', output), JSON.stringify({synthetic: true, activeChanged: false, receipts}, null, 2));
console.log(JSON.stringify(receipts.map(({name, status, balance}) => ({name, status, balance})), null, 2));