Files
SGF/scripts/sgf-payable-aging-http.mjs
T
2026-11-11 09:00:17 +02:00

4 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from 'node:fs';import assert from 'node:assert/strict';import crypto from 'node:crypto';import {session} from './sgf-single-http.mjs';import {checkedPayablePage,payableAgeSummary,payablePageCsv} from '../resources/js/payable-position-view.js';
const s=await session('sgf:read_only','finance'),query={page:1,per_page:25,reference_on:'2026-12-15'},checks=[],ok=(v,n)=>{assert(v,n);checks.push(n);},path='/api/finance/payable-positions?',load=async q=>{const r=await s.get(path+new URLSearchParams(q));assert.equal(r.status,200);return checkedPayablePage(await r.json(),q);};const data=await load(query),plain=await load({page:1,per_page:25}),row=data.positions.find(r=>r.obligation_id);ok(row.balance_minor==='10000'&&row.reviewed_age_days===15&&row.reviewed_age_bucket==='days_1_30','actual100 classified15 days from reviewed deadline');ok(row.due_on===null&&row.days_overdue===null,'original unknown due remains separate');ok(plain.positions.find(r=>r.document_id===row.document_id).balance_minor===row.balance_minor&&plain.positions.every(r=>r.reviewed_age_bucket===null),'no reference no implicit classification or balance change');ok(payableAgeSummary(data).some(g=>g.currency==='MZN'&&g.bucket==='days_1_30'&&g.value==='100,00'),'actual page bucket exact100');const large=await load({...query,per_page:100});ok(JSON.stringify(large.positions)===JSON.stringify(data.positions),'known pages25/100 identical');const sameDay=await load({...query,reference_on:'2026-11-30'});ok(sameDay.positions.find(r=>r.document_id===row.document_id).reviewed_age_bucket==='not_due','actual same day not overdue');const search=await load({...query,search:row.reference});ok(search.positions.some(r=>r.document_id===row.document_id),'search preserved with reference');ok((await load({...query,page:100000})).positions.length===0,'empty page no fallback');let r=await s.get(path+new URLSearchParams({...query,reference_on:'2026-02-30'}));ok(r.status===422,'impossible reference refused');r=await s.get(path+new URLSearchParams({...query,tenant_id:2}));ok(r.status===422,'tenant override refused');const other=await session('sgf:read_only','commercial');r=await other.get(path+new URLSearchParams(query));ok([403,409].includes(r.status),'other module refused');ok(payablePageCsv(data,query).includes('2026-12-15')&&payablePageCsv(data,query).includes('1–30 dias'),'CSV actual period and category');
const root=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')).root+'/private/receipt-composition-cc50a276c10c',manifest=JSON.parse(fs.readFileSync(root+'/app/public/build/manifest.json'));for(const e of Object.values(manifest).filter(v=>v.isEntry||v.file.includes('PayablePositionsWorkspace'))){r=await fetch('http://127.0.0.1:8085/build/'+e.file);const bytes=Buffer.from(await r.arrayBuffer());ok(r.status===200&&/javascript/.test(r.headers.get('content-type'))&&crypto.createHash('sha256').update(bytes).digest('hex')===crypto.createHash('sha256').update(fs.readFileSync(root+'/app/public/build/'+e.file)).digest('hex'),'actual JS delivery '+e.file);}const file=root+'/payable-aging-http-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks,business_commands:0,new_grants:0,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof:file}));