Files
Investidor-V2/tools/portal-segmentation-library-qa.cjs
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

31 lines
2.6 KiB
JavaScript

// New document consumer proof only; no A/B or C37 repetition.
const {start,assert,fs,path,DIR,sanitized}=require('./portal-functional-qa-lib.cjs');
const crypto=require('node:crypto');
void(async()=>{
const q=await start('segmentation-library-chromium-20261011'),sessions=[];
const source=JSON.parse(fs.readFileSync(path.join(DIR,'segmentation-reconciliation-20261011/library-replay-qa.json'),'utf8'));
const item=source.retrieval[0],route=`/management/documents/${item.document_id}/download`;
async function manager(){const s=await q.context('manager');sessions.push(s);await q.login(s.page,'manager');await q.open(s.page,'/management/portal-services');return s;}
try{
let s=await manager();
assert(await s.page.getByText(/Portal do Investidor — InvesteMoz: segmentar processos v1/).first().isVisible());
assert(await s.page.getByText(/Exemplar observado:.*segmentar processos v1/).first().count()>0);
const download=s.page.waitForEvent('download');await s.page.locator(`a[href="${route}"]`).click();
const file=await download,p=await file.path();assert(p);
assert.equal(crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex'),source.source_sha256);
q.proof.checks.authorized_ui_download_matches_original=true;
await q.shot(s.page,'private-source-library',false);
s.ctx.qaClosing=true;await s.ctx.close();s=await manager();
assert(await s.page.locator(`a[href="${route}"]`).isVisible());q.proof.checks.new_session_recovers_private_exemplar=true;
const denied=await q.context('promoter');sessions.push(denied);await q.login(denied.page,'promoter');assert.equal((await q.open(denied.page,route)).status(),403);
q.proof.checks.promoter_cannot_download_private_specification=true;
const anonymous=await q.context('anonymous');sessions.push(anonymous);
assert.equal((await q.open(anonymous.page,`/documentos/${item.resource_id}/download`)).status(),404);
q.proof.checks.not_published=true;q.proof.checks.no_rules_activated=true;
q.proof.checks.exact_requested_filename_still_pending=true;
q.proof.document={resource_id:item.resource_id,document_id:item.document_id,sha256:source.source_sha256,observed_filename:item.file_name};
q.proof.AB_C37_not_repeated=true;q.proof.result='passed';q.save();console.log(JSON.stringify({result:'passed',checks:q.proof.checks,active_writes:0}));
}catch(e){q.proof.result='failed';q.proof.failure=sanitized(e);q.save();console.log(JSON.stringify({result:'failed',failure:q.proof.failure,active_writes:0}));process.exitCode=1;}
finally{for(const s of sessions){s.ctx.qaClosing=true;await s.ctx.close();}await q.browser.close();}
})();