Prepare PEC obligation total and calendar with private recovery and reports
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-11 09:59:54 +02:00
parent e549003e5d
commit bcbbe51c2f
14 changed files with 797 additions and 8 deletions
+109
View File
@@ -0,0 +1,109 @@
import fs from 'node:fs';
import assert from 'node:assert/strict';
import { combinedCase } from '../tests/frontend/helpers/irpc-investment-combination-case.mjs';
import { plan } from '../tests/frontend/helpers/irpc-pec-obligation-case.mjs';
import { calculatePecObligation } from '../resources/js/lib/irpc-pec-obligation.ts';
import {
recordAnnual,
saveAnnualBook,
annualBook,
annualCurrent,
annualHtml,
} from '../resources/js/lib/irpc-annual-settlement.ts';
import { createProjectDossierReport } from '../resources/js/lib/project-dossier-report.ts';
const out = new URL(
'../outputs/irpc-pec-obligation-20261111/',
import.meta.url,
);
fs.mkdirSync(out, { recursive: true });
const scenarios = {
ordinary: {},
minimum: { previousTurnover: '1000000' },
maximum: { previousTurnover: '50000000' },
start: {
activityStartYear: '2026',
activityReference: 'SYNTHETIC effective activity2026',
previousTurnover: '',
previousPpcPaid: '',
turnoverReference: '',
ppcReference: '',
},
zero_turnover: { previousTurnover: '0' },
unknown: { previousTurnover: '' },
};
for (const [name, changes] of Object.entries(scenarios)) {
if (process.argv[2] === 'generate') {
const { d, b } = combinedCase();
const prior = recordAnnual(d, b, '2026-11-11T10:00:00Z');
prior.pecObligation = {
...plan(),
subjectNuit: b.subjectNuit,
year: b.year,
...changes,
};
const next = recordAnnual(d, prior, '2026-11-11T10:01:00Z');
d.modelo_a_snapshot = saveAnnualBook(d, next);
fs.writeFileSync(new URL(name + '.json', out), JSON.stringify(d));
} else {
const d = JSON.parse(
fs.readFileSync(
new URL('recovered-' + name + '.json', out),
'utf8',
),
),
b = annualBook(d),
m = calculatePecObligation(
b.pecObligation,
b.subjectNuit,
b.year,
b.assessment,
);
assert.equal(annualCurrent(d, b), true);
assert.equal(b.history.length, 1);
assert.deepEqual(b.result.model.arithmeticBalance, {
numerator: '138',
denominator: '1',
});
const html = annualHtml(d),
report = createProjectDossierReport(d, {
selectedSections: new Set(['finance']),
generatedAt: '2026-11-11T10:02:00Z',
});
assert.match(html, /PEC — obrigação preparada/);
assert.match(JSON.stringify(report), /PEC — obrigação preparada/);
assert.equal(m.paymentExecuted, false);
assert.equal(m.annualDeductionCreated, false);
const expected = {
ordinary: '40000',
minimum: '20000',
maximum: '90000',
start: '0',
zero_turnover: null,
unknown: null,
}[name];
assert.equal(m.total?.numerator ?? null, expected);
fs.writeFileSync(new URL(name + '-report.html', out), html);
fs.writeFileSync(
new URL(name + '-verification.json', out),
JSON.stringify(
{
synthetic: true,
apiRecovered: true,
current: true,
historyPreserved: true,
annualBalanceUnchanged: true,
report: true,
visualReview: false,
model: m,
},
null,
2,
),
);
}
}
console.log(
process.argv[2] === 'generate'
? 'Six synthetic PEC scenarios prepared.'
: 'Six native recovered PEC scenarios recalculated and reported without creating deductions.',
);
+26
View File
@@ -0,0 +1,26 @@
<?php
$root = dirname(__DIR__);
if (($argv[1] ?? '') !== 'test' || basename($root) !== 'portal-investidor') {
throw new RuntimeException('Explicit local test operation required.');
}
foreach (['APP_ENV' => 'testing', 'APP_KEY' => 'base64:'.base64_encode(str_repeat('Q', 32)),
'APP_CONFIG_CACHE' => $root.'/outputs/irpc-pec-obligation-20261111/no-config.php',
'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441',
'DB_DATABASE' => 'proactive_investment_20261027_test', 'DB_USERNAME' => 'investmoz_test', 'DB_PASSWORD' => '',
'DB_URL' => '', 'DATABASE_URL' => '', 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array',
'QUEUE_CONNECTION' => 'sync', 'MAIL_MAILER' => 'array', 'SUITECRM_ENABLED' => 'false'] as $key => $value) {
putenv($key.'='.$value);
$_ENV[$key] = $_SERVER[$key] = $value;
}
$pdo = new PDO('pgsql:host=127.0.0.1;port=55441;dbname=proactive_investment_20261027_test', 'investmoz_test', '');
$identity = $pdo->query('select current_database() as name,inet_server_port() as port')->fetch(PDO::FETCH_ASSOC);
if ($identity['name'] !== 'proactive_investment_20261027_test' || (int) $identity['port'] !== 55441) {
throw new RuntimeException('Isolated QA identity required.');
}
$argv = ['phpunit', '-c', 'phpunit.investmoz.xml', '--do-not-cache-result', 'tests/Feature/IrpcPecObligationDraftTest.php'];
$argc = count($argv);
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = $argc;
require $root.'/vendor/autoload.php';
require $root.'/vendor/phpunit/phpunit/phpunit';