Files
SGF/scripts/sgf-bank-dom-http.mjs
2026-11-11 09:00:17 +02:00

6 lines
3.9 KiB
JavaScript

// Actual client over actual HTTP in its retained finalized state; zero POSTs.
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','finance');let r=await s.get('/finance/bank',{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);let posts=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'){posts++;throw Error('No bank POST allowed in retained final state proof');}const a=await s.get(url);return{status:a.status,json:()=>a.json()};};await import('../public/sgf-bank.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===7);ok($('summary').textContent.includes('Finalizada')&&$('summary').textContent.includes('versão 7'),'finalized conference visible');ok($('summary').textContent.includes('linhas efectivas do diário QA'),'actual native source identified');ok($('summary').textContent.includes('abertura 0.00')&&$('summary').textContent.includes('fecho 0.00'),'explicit statement opening/closing');ok($('fields').disabled,'finalized workflow has no writer controls');ok(!$('filters').disabled,'historical read controls remain available');ok($('rows').children.length===2&&$('rows').textContent.includes('diário 2')&&$('rows').textContent.includes('diário 3'),'two explicit historical correspondences visible');ok($('download').querySelector('a').href.endsWith('/report'),'reviewed report link available');$('status').value='unmatched';$('apply').onclick();await wait(()=>$('rows').children.length===0&&!$('filters').disabled);ok($('rows').children.length===0,'unmatched status filter applied');$('status').value='matched';$('size').value='100';$('apply').onclick();await wait(()=>$('rows').children.length===2&&!$('filters').disabled&&calls.some(c=>c.includes('per_page=100')));ok($('events').children.length===7,'history100 preserves7 existing events');$('events').children[0].querySelector('button').onclick();ok($('detail').textContent.includes('fundamento')&&$('detail').textContent.includes('difference_minor'),'selected historical version details');
const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=run.root+'/private/receipt-composition-cc50a276c10c',p=JSON.parse(fs.readFileSync(root+'/bank-http-20261110.json'));$('referenceKey').value=p.operations.import.key;await $('recovery').onsubmit({preventDefault(){}});ok($('receipt').textContent.includes('Nenhuma operação repetida'),'historical receipt recovered without execution');ok(posts===0,'zero business POSTs');r=await s.get('/api/cash');const cash=await r.json();ok(r.status===200&&cash.basis.closed&&cash.basis.balance_minor===95000,'cash remains closed950');const acct=await session('sgf:finance_prepare','accounting');r=await acct.get('/api/fiscal-assessments');const iva=await r.json();ok(r.status===200&&iva.form_current_review&&iva.events.total===4,'IVA book/map remains reviewed with4versions');r=await acct.get('/api/fiscal-rules?view=calculations');ok(r.status===200&&(await r.json()).records.total===2,'two fiscal calculations retained');const file=root+'/bank-dom-http-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,business_posts:posts,real_http_forwarded:true,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));