Files
Investidor-V2/tests/frontend/iva-offer-package.test.mjs
T

9 lines
2.0 KiB
JavaScript

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/);});