This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { fiscalQaRows } from "../../resources/js/lib/fiscal-qa-preview.ts";
|
||||
import { exportCompletedArithmeticCsv } from "../../resources/js/lib/simulation-form.ts";
|
||||
import { exportCompletedArithmeticCsv, readArithmeticSnapshot } from "../../resources/js/lib/simulation-form.ts";
|
||||
import { createProjectDossierReport } from "../../resources/js/lib/project-dossier-report.ts";
|
||||
|
||||
function fixture() {
|
||||
@@ -131,3 +131,46 @@ test("dossier report uses the same exact snapshot and preserves genuine indeterm
|
||||
"Indeterminado",
|
||||
);
|
||||
});
|
||||
|
||||
test("published consumer routes the frozen snapshot through screen CSV and dossier without QA labels", () => {
|
||||
const simulation = fixture();
|
||||
const snapshot = simulation.result_snapshot;
|
||||
snapshot.scenario_kind = "fiscal_rule_published";
|
||||
snapshot.context.engine_version = "fiscal-published-v1";
|
||||
snapshot.presentation = { value: snapshot.result.value, rounding_applied: false };
|
||||
snapshot.result.explanation = "IVA pela versão publicada; enquadramento declarado.";
|
||||
snapshot.fiscal_provenance.rule.status = "published";
|
||||
snapshot.fiscal_provenance.scope_status = "user_declared";
|
||||
snapshot.fiscal_provenance.mode = "published_version";
|
||||
simulation.reports[0].report_snapshot = structuredClone(snapshot);
|
||||
const before = JSON.stringify(simulation);
|
||||
const rows = fiscalQaRows(snapshot);
|
||||
assert.equal(readArithmeticSnapshot(snapshot).integrity, "versioned");
|
||||
assert.match(rows[0][1], /publicada/);
|
||||
assert.doesNotMatch(JSON.stringify(rows), /rascunho|não publicada|QA/);
|
||||
const csv = exportCompletedArithmeticCsv(simulation, "2026-10-21T12:00:00Z");
|
||||
for (const [label, value] of rows) {
|
||||
assert.ok(csv.includes(label));
|
||||
assert.ok(csv.includes(value.replaceAll('"', '""')));
|
||||
}
|
||||
const report = createProjectDossierReport({ project_title: "Published IVA QA", currency: "MZN" }, {
|
||||
selectedSections: new Set(["finance"]), currentCalculation: { status: "completed", version: 2, snapshot },
|
||||
});
|
||||
const finance = report.sections.find((section) => section.id === "finance");
|
||||
for (const [field, value] of rows) assert.ok(finance.rows.some((row) => row.field === field && row.value === value));
|
||||
assert.doesNotMatch(JSON.stringify(finance), /rascunho|proveniência QA/);
|
||||
assert.equal(JSON.stringify(simulation), before);
|
||||
});
|
||||
|
||||
test("published consumer indeterminate snapshot is valid and a mismatched presentation is refused", () => {
|
||||
const snapshot = fixture().result_snapshot;
|
||||
snapshot.scenario_kind = "fiscal_rule_published";
|
||||
snapshot.result.status = "indeterminate";
|
||||
snapshot.result.value = null;
|
||||
snapshot.result.missing_inputs = ["operation_scope"];
|
||||
snapshot.indicative_total = null;
|
||||
snapshot.presentation = { value: null, rounding_applied: false };
|
||||
assert.equal(readArithmeticSnapshot(snapshot).integrity, "versioned");
|
||||
snapshot.presentation.value = "0";
|
||||
assert.equal(readArithmeticSnapshot(snapshot).integrity, "invalid");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user