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

7 lines
2.6 KiB
JavaScript

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_review','finance');let r=await s.get('/finance/cash',{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=[];
globalThis.fetch=async(url,options={})=>{if(url.startsWith('http:'))return nativeFetch(url,options);calls.push(url);if(options.method==='POST'){posts++;throw Error('No Cash POST permitted in this read-only UI proof');}const q=await s.get(url);return{status:q.status,json:()=>q.json()};};
await import('../public/sgf-cash.mjs?dom-http');const wait=async f=>{const end=Date.now()+12000;while(!f()&&Date.now()<end)await new Promise(r=>setTimeout(r,25));assert(f(),$('message').textContent);};await wait(()=>$('events').children.length===9);assert.match($('summary').textContent,/Fechada/);assert.match($('summary').textContent,/950.00 MZN/);assert($('fields').disabled);assert.equal($('action').children.length,1);assert.equal($('filters').disabled,false);assert.match($('period').textContent,/1000.00 MZN/);assert.match($('period').textContent,/50.00 MZN/);
$('filterKind').value='expense';$('apply').onclick();await wait(()=>$('events').children.length===2);assert.match($('period').textContent,/fecho 950.00 MZN/);$('from').value='2026-11-11';$('apply').onclick();await wait(()=>$('events').children.length===0);assert.match($('period').textContent,/abertura 950.00 MZN/);
const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),root=run.root+'/private/receipt-composition-cc50a276c10c',progress=JSON.parse(fs.readFileSync(root+'/cash-http-20261110.json'));$('referenceKey').value=progress.operations['fechar-caixa'].key;await $('recovery').onsubmit({preventDefault(){}});assert.match($('receipt').textContent,/versão 9, Fechado/);assert.match($('receipt').textContent,/Nenhuma operação repetida/);assert(calls.some(url=>url.includes('/api/cash/receipts/')));assert.equal(posts,0);const file=root+'/cash-dom-http-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks:14,real_confirmation_posts:0,transport_mocked:false,read_transport_forwarded:true,closed_cash_preserved:true,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:14,proof:file}));