9 lines
4.3 KiB
JavaScript
9 lines
4.3 KiB
JavaScript
// Actual client over actual HTTP; previews roll back, no confirmation POSTs permitted.
|
|
import fs from 'node:fs';import assert from 'node:assert/strict';import {parsePage,installDom} from './purchasing-workspace-dom.mjs';import {session} from './sgf-single-http.mjs';
|
|
const nativeFetch=globalThis.fetch,s=await session('sgf:finance_prepare','accounting');const r=await s.get('/fiscal/iva',{headers:{Accept:'text/html'}});assert.equal(r.status,200);const document=parsePage(await r.text());installDom(document);document.getElementById=id=>document.querySelector('#'+id);globalThis.window={addEventListener(){}};const $=id=>document.getElementById(id);$('size').value='25';let previewPosts=0,confirmationPosts=0;const calls=[],checks=[];const ok=(v,n)=>{assert(v,n);checks.push(n);};
|
|
globalThis.fetch=async(url,options={})=>{if(url.startsWith('http:'))return nativeFetch(url,options);calls.push(url);if(options.method==='POST'){if(url.endsWith('/confirm')){confirmationPosts++;throw Error('No fiscal confirmations permitted in UI proof');}assert(url.endsWith('/preview'));previewPosts++;const a=await s.command(url,JSON.parse(options.body),options.headers['Idempotency-Key']);return{status:a.status,json:async()=>a.value};}const a=await s.get(url);return{status:a.status,json:()=>a.json()};};
|
|
await import('../public/sgf-iva.mjs?dom-http');const wait=async f=>{const end=Date.now()+15000;while(!f()&&Date.now()<end)await new Promise(r=>setTimeout(r,25));assert(f(),$('message').textContent);};await wait(()=>$('events').children.length===4);ok($('summary').textContent.includes('862.07')&&$('summary').textContent.includes('137.93'),'frozen source amounts visible');ok($('summary').textContent.includes('Imposto a pagar: indeterminado'),'no invented payable');ok($('download').querySelector('a').href.includes('/export'),'only reviewed map download offered');
|
|
$('kind').value='assessment';$('kind').onchange();$('action').value='prepare';$('action').onchange();ok($('source').value==='','source not selected automatically');const p=await s.get('/api/fiscal-assessments');const state=await p.json();$('source').value=String(state.source.output_id);$('evidence').value='Evidência QA escolhida individualmente e mantida ao paginar.';$('reason').value='Fundamento QA individual conservado durante consulta do histórico.';$('operation').oninput();$('size').value='100';$('apply').onclick();await wait(()=>$('filters').disabled===false&&calls.some(v=>v.includes('per_page=100')));ok($('evidence').value.includes('mantida ao paginar')&&$('reason').value.includes('conservado'),'history pagination preserves unsubmitted evidence/reason');
|
|
await $('operation').onsubmit({preventDefault(){}});ok(previewPosts===1&&confirmationPosts===0,'only actual rollback preview reached server');ok($('fields').disabled&&$('filters').disabled,'preview protects form and history controls');ok($('impact').textContent.includes('137.93')&&$('impact').textContent.includes('Indeterminado'),'impact visible before confirmation');ok(!$('confirm').hidden,'explicit confirmation button offered');$('cancel').onclick();ok(!$('fields').disabled&&$('impact').children.length===0,'cancel restores form without executing');ok($('evidence').value.includes('mantida ao paginar'),'cancel preserves evidence');
|
|
const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'));const root=run.root+'/private/receipt-composition-cc50a276c10c',progress=JSON.parse(fs.readFileSync(root+'/iva-http-20261110.json'));$('referenceKey').value=progress.operations['prepare-book'].key;await $('recovery').onsubmit({preventDefault(){}});ok($('receipt').textContent.includes('Nenhuma operação repetida'),'historical command receipt recovered by GET');$('events').children[0].querySelector('button').onclick();ok($('detail').textContent.includes('fundamento')&&$('detail').textContent.includes('137.93'),'history exposes selected version evidence');const after=await s.get('/api/fiscal-assessments');ok((await after.json()).events.total===4&&confirmationPosts===0,'four retained versions unchanged by UI proof');const file=root+'/iva-dom-http-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,preview_posts:previewPosts,confirmation_posts:confirmationPosts,transport_mocked:false,real_http_forwarded:true,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));
|