feat: expose guided manual IVA and IRPC form preparation
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-28 21:54:25 +02:00
parent 17444aaaa5
commit 332c16ebb5
10 changed files with 293 additions and 2 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
final class FiscalFormEntryTest extends TestCase
{
use DatabaseTransactions;
protected function setUp(): void
{
parent::setUp();
\Tests\Support\ProactiveInvestmentFixture::guard();
$this->withoutVite();
}
public function test_both_fiscal_forms_are_public_and_do_not_redirect_to_legal_documents(): void
{
config(['portal.homologation_only' => false]);
foreach (['iva', 'irpc'] as $tax) {
$this->get('/formularios/fiscais?imposto='.$tax)
->assertOk()
->assertInertia(fn (Assert $page) => $page->component('portal/fiscal-forms')->where('initialTax', $tax));
}
}
}
+34
View File
@@ -0,0 +1,34 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import {createRequire} from 'node:module';
import React from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import ts from 'typescript';
import * as forms from '../../resources/js/lib/fiscal-form-preparation.ts';
const require=createRequire(import.meta.url);
const source=fs.readFileSync(new URL('../../resources/js/pages/portal/fiscal-forms.tsx',import.meta.url),'utf8');
const compiled=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,jsx:ts.JsxEmit.ReactJSX}}).outputText;
const module={exports:{}};
new Function('require','module','exports',compiled)(name=>name==='@inertiajs/react'?{Head:()=>null,Link:({href,children,...props})=>React.createElement('a',{href,...props},children),router:{on:()=>()=>{}}}:name==='@/layouts/portal-navigation'?{PortalMenu:()=>null}:name==='@/lib/fiscal-form-preparation'?forms:require(name),module,module.exports);
test('fiscal entry renders labelled editable fields and a guided preparation rather than legislation',()=>{
const html=renderToStaticMarkup(React.createElement(module.exports.default));
for(const label of ['Identificação e período','Nome ou designação social','NUIT','Período — ano e mês','Conferir e guardar','Guardar ficheiro para continuar','Recuperar ficheiro guardado','Confirmar recuperação']) {
// Confirmation appears only after a compatible file is selected.
if(label !== 'Confirmar recuperação') assert.ok(html.includes(label),label);
}
assert.equal((html.match(/inputMode="decimal"/g)??[]).length,27);
assert.match(html,/sem submissão à Autoridade Tributária/);
assert.match(html,/Não há gravação automática/);
assert.doesNotMatch(html,/value="0"/);
});
test('IRPC entry opens the requested form directly and keeps its partial coverage explicit',()=>{
const html=renderToStaticMarkup(React.createElement(module.exports.default,{initialTax:'irpc'}));
assert.match(html,/IRPC — Modelo 22/);
assert.match(html,/L8 permanece parcial/);
assert.match(html,/303 — Dupla tributação económica/);
assert.match(html,/304 — Dupla tributação internacional/);
assert.match(html,/Não utilize a mesma parcela/);
assert.equal((html.match(/inputMode="decimal"/g)??[]).length,24);
assert.doesNotMatch(html,/01 — Base das operações/);
});
@@ -0,0 +1,34 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {newFiscalPreparation, readFiscalPreparation, fiscalPreparationIssues, fiscalFormFields} from '../../resources/js/lib/fiscal-form-preparation.ts';
test('IVA and IRPC preparations round trip deliberate entries and unknown amounts without zero defaults', () => {
for (const kind of ['iva', 'irpc']) {
const p = newFiscalPreparation(kind);
p.name = 'Investidor de teste'; p.nuit = '123456789'; p.period = kind === 'iva' ? '2026-10' : '2026';
const [first, second] = fiscalFormFields(kind);
p.values[first.code] = '123456789012345678901234,01';
p.values[second.code] = '';
const restored = readFiscalPreparation(JSON.stringify(p));
assert.deepEqual(restored, p);
assert.deepEqual(fiscalPreparationIssues(restored), []);
assert.equal(restored.values[second.code], '');
assert.equal(Object.values(restored.values).includes('0'), false);
}
});
test('foreign editions, unknown fields and malformed or oversized files cannot replace preparation', () => {
const p = newFiscalPreparation('iva');
for (const v of [{...p, sourceHash: 'different'}, {...p, values: {'999': '1'}}, {...p, values: []}, {...p, nuit: 123}, {...p, version: 'later'}]) assert.throws(() => readFiscalPreparation(JSON.stringify(v)));
assert.throws(() => readFiscalPreparation('{broken'));
assert.throws(() => readFiscalPreparation('x'.repeat(100001)));
assert.equal(p.kind, 'iva'); assert.deepEqual(p.values, {});
});
test('invalid format is identified without rounding or discarding an incomplete preparation', () => {
const p = newFiscalPreparation('irpc');
p.values['303'] = '1.234'; p.values['304'] = '25,00';
const restored = readFiscalPreparation(JSON.stringify(p));
assert.equal(restored.values['303'], '1.234');
assert.ok(fiscalPreparationIssues(restored).some(i => i.startsWith('Campo 303:')));
assert.equal(fiscalFormFields('irpc').find(f => f.code === '303').label, 'Dupla tributação económica');
assert.equal(fiscalFormFields('irpc').find(f => f.code === '304').label, 'Dupla tributação internacional');
});