fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+80 -8
View File
@@ -1,8 +1,80 @@
import test from 'node:test';import assert from 'node:assert/strict';import fs from 'node:fs';import JSZip from 'jszip';
import {buildOfferPackage} from '../../resources/js/lib/iva-offer-package.ts';
import {recordOfferWorkflow} from '../../resources/js/lib/iva-offer-workflow.ts';
const seed=JSON.parse(fs.readFileSync('tests/frontend/fixtures/iva-offer-workflow.json','utf8')),rows=JSON.parse(seed.modelo_a_snapshot).offerPreparations['opportunity:364'].rows,bytes=Buffer.from('SYNTHETIC QA despacho privado para teste de continuidade.');
const hash=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',bytes))).map(b=>b.toString(16).padStart(2,'0')).join('');for(const row of rows)row.workflow.decisionAttachment.sha256=hash;
const buffer=()=>Uint8Array.from(bytes).buffer;
for(const row of rows)test(row.branch+' conjunto inclui original,pedido,formulário e manifesto com âmbito',async()=>{const ready=recordOfferWorkflow(row,'decision'),result=await buildOfferPackage(ready,async()=>buffer()),zip=await JSZip.loadAsync(result.bytes);assert.deepEqual(Buffer.from(await zip.file('despacho/SYNTHETIC-QA-despacho.txt').async('uint8array')),bytes);assert.match(await zip.file('pedido.txt').async('string'),/apresentação ocorre fora/);const manifest=JSON.parse(await zip.file('manifesto.json').async('string'));assert.equal(manifest.workflow.formDecisionHash,row.workflow.decisionAttachment.sha256);assert.match(await zip.file('preparacao-formulario.txt').async('string'),/Apresentação fora/);assert.equal(manifest.request.goods,'SYNTHETIC QA apenas bensA');if(process.env.IVA_OFFER_PACKAGE_PROOF)fs.writeFileSync(`outputs/iva-l1-returnees-20261025/${row.branch}-pedido-decisao-formulario.zip`,result.bytes);});
test('anexo alterado e indeferimento nunca geram conjunto de isenção',async()=>{await assert.rejects(buildOfferPackage(recordOfferWorkflow(rows[0],'decision'),async()=>new ArrayBuffer(1)),/hash/);await assert.rejects(buildOfferPackage({...rows[0],request:{...rows[0].request,state:'denied'}},async()=>buffer()),/indeferimento/);});
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import JSZip from 'jszip';
import { buildOfferPackage } from '../../resources/js/lib/iva-offer-package.ts';
import { recordOfferWorkflow } from '../../resources/js/lib/iva-offer-workflow.ts';
const seed = JSON.parse(
fs.readFileSync(
'tests/frontend/fixtures/iva-offer-workflow.json',
'utf8',
),
),
rows = JSON.parse(seed.modelo_a_snapshot).offerPreparations[
'opportunity:364'
].rows,
bytes = Buffer.from(
'SYNTHETIC QA despacho privado para teste de continuidade.',
);
const hash = Array.from(
new Uint8Array(await crypto.subtle.digest('SHA-256', bytes)),
)
.map((b) => b.toString(16).padStart(2, '0'))
.join('');
for (const row of rows) row.workflow.decisionAttachment.sha256 = hash;
const buffer = () => Uint8Array.from(bytes).buffer;
for (const row of rows)
void test(
row.branch +
' conjunto inclui original,pedido,formulário e manifesto com âmbito',
async () => {
const ready = recordOfferWorkflow(row, 'decision'),
result = await buildOfferPackage(ready, async () => buffer()),
zip = await JSZip.loadAsync(result.bytes);
assert.deepEqual(
Buffer.from(
await zip
.file('despacho/SYNTHETIC-QA-despacho.txt')
.async('uint8array'),
),
bytes,
);
assert.match(
await zip.file('pedido.txt').async('string'),
/apresentação ocorre fora/,
);
const manifest = JSON.parse(
await zip.file('manifesto.json').async('string'),
);
assert.equal(
manifest.workflow.formDecisionHash,
row.workflow.decisionAttachment.sha256,
);
assert.match(
await zip.file('preparacao-formulario.txt').async('string'),
/Apresentação fora/,
);
assert.equal(manifest.request.goods, 'SYNTHETIC QA apenas bensA');
if (process.env.IVA_OFFER_PACKAGE_PROOF)
fs.writeFileSync(
`outputs/iva-l1-returnees-20261025/${row.branch}-pedido-decisao-formulario.zip`,
result.bytes,
);
},
);
void test('anexo alterado e indeferimento nunca geram conjunto de isenção', async () => {
await assert.rejects(
buildOfferPackage(
recordOfferWorkflow(rows[0], 'decision'),
async () => new ArrayBuffer(1),
),
/hash/,
);
await assert.rejects(
buildOfferPackage(
{ ...rows[0], request: { ...rows[0].request, state: 'denied' } },
async () => buffer(),
),
/indeferimento/,
);
});