Completar combinação CBF15 com saldos anteriores e conferir PEC residual
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-11 07:35:04 +02:00
parent 67cd583b94
commit 9c067d6ae8
10 changed files with 357 additions and 18 deletions
+114
View File
@@ -0,0 +1,114 @@
import fs from "node:fs";
import assert from "node:assert/strict";
import { combinedCase } from "../tests/frontend/helpers/irpc-investment-combination-case.mjs";
import {
calculateAnnual,
recordAnnual,
annualBook,
annualCurrent,
saveAnnualBook,
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-cbf15-combination-20261111/",
import.meta.url,
);
fs.mkdirSync(out, { recursive: true });
const expected = {
combined: 138,
quota: 438,
overallocated: null,
reconciled: -500,
expired: 538,
};
for (const [name, balance] of Object.entries(expected)) {
if (process.argv[2] === "recovered") {
const d = JSON.parse(
fs.readFileSync(
new URL("recovered-" + name + ".json", out),
"utf8",
),
),
b = annualBook(d),
m = calculateAnnual(d, b);
assert.equal(annualCurrent(d, b), true);
assert.deepEqual(m, b.result.model);
assert.deepEqual(
m.arithmeticBalance,
balance === null
? null
: { numerator: String(balance), denominator: "1" },
);
const html = annualHtml(d),
report = createProjectDossierReport(d, {
selectedSections: new Set(["finance"]),
generatedAt: "2026-11-11T09:00:00+02:00",
});
assert.match(html, /CBF15/);
assert.match(JSON.stringify(report), /CBF15/);
fs.writeFileSync(new URL(name + "-report.html", out), html);
fs.writeFileSync(
new URL(name + "-verification.json", out),
JSON.stringify(
{
synthetic: true,
apiRecovered: true,
exactRecalculation: true,
html: true,
dossierReport: true,
balance: m.arithmeticBalance,
pending: m.pending,
investment: m.investmentCredit,
carry: m.creditCarry,
officialBalancesConsumed: false,
activeChanged: false,
},
null,
2,
),
);
} else {
const c = combinedCase();
c.b.history = [
recordAnnual(c.d, structuredClone(c.b), "2026-11-11T08:00:00+02:00")
.result,
];
if (name === "quota") {
c.b.investmentCredit.soleProject = "no";
c.b.investmentCredit.projectQuota = {
amount: "100",
reference: "SYNTHETIC documented residual project quota100",
};
}
if (["overallocated", "reconciled"].includes(name))
Object.assign(c.b.investmentCredit.assets[0], {
amount: "40000",
proofAmount: "40000",
});
if (name === "reconciled") {
c.b.creditCarry.currentPec = "0";
c.b.creditCarry.lots[1].selected = "0";
}
if (name === "expired") c.b.investmentCredit.startDate = "2021-01-01";
const book = recordAnnual(c.d, c.b, "2026-11-11T09:00:00+02:00");
assert.deepEqual(
book.result.model.arithmeticBalance,
balance === null
? null
: { numerator: String(balance), denominator: "1" },
);
fs.writeFileSync(
new URL(name + ".json", out),
JSON.stringify({
...c.d,
modelo_a_snapshot: saveAnnualBook(c.d, book),
}),
);
}
}
console.log(
process.argv[2] === "recovered"
? "Five API-recovered combinations recalculated and reported."
: "Five synthetic combinations prepared.",
);
+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-cbf15-combination-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/IrpcInvestmentCombinationDraftTest.php'];
$argc = count($argv);
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = $argc;
require $root.'/vendor/autoload.php';
require $root.'/vendor/phpunit/phpunit/phpunit';