10 lines
2.7 KiB
JavaScript
10 lines
2.7 KiB
JavaScript
import assert from 'node:assert/strict';import fs from 'node:fs';import {WorkshopStockOperation} from '../resources/js/workshop-stock-operation.js';
|
|
const checks=[],ok=(v,n)=>{assert(v,n);checks.push(n);};const calls=[];let lost=true;const operation=new WorkshopStockOperation(async(path,method,body,token,key)=>{calls.push({path,method,body:JSON.stringify(body),key});if(lost){lost=false;throw Error('Response lost after commit');}return {id:7,replayed:true};});
|
|
const input={entry_id:4,version:1,warehouse_id:3,movement_id:8,reason:'Origem física individual.'};try{await operation.send('/api/workshop-stock/prepare-return',input,'same-key');}catch{}
|
|
ok(operation.uncertain&&!operation.pending,'lost response retains recoverable operation');input.reason='Changed outside the frozen request';let refused=false;try{await operation.send('/api/workshop-stock/prepare',input,'another-key');}catch{refused=true;}ok(refused&&calls.length===1,'uncertain operation refuses a different decision');
|
|
const result=await operation.retry();ok(result.id===7&&result.replayed&&!operation.uncertain,'recovery returns original receipt');ok(calls[0].body===calls[1].body&&calls[0].key===calls[1].key&&calls[0].path===calls[1].path,'retry preserves exact original body, path and key despite caller mutation');
|
|
let empty=true;const incomplete=new WorkshopStockOperation(async()=>empty?(empty=false,{}):{movement_id:22,replayed:true});try{await incomplete.send('/confirm',{received_in_warehouse:true},'confirmation');}catch{}ok(incomplete.uncertain,'successful HTTP with incomplete receipt remains uncertain');ok((await incomplete.retry()).movement_id===22,'incomplete receipt recovers same physical confirmation');
|
|
const invalid=new WorkshopStockOperation(async()=>{const e=Error('Version changed');e.status=409;throw e;});try{await invalid.send('/prepare',{},'stale');}catch{}ok(!invalid.uncertain&&!invalid.pending,'explicit stale-version refusal requires new conference rather than frozen recovery');
|
|
let release;let count=0;const concurrent=new WorkshopStockOperation(()=>{count++;return new Promise(resolve=>release=resolve);});const first=concurrent.send('/confirm',{},'one');refused=false;try{await concurrent.send('/confirm',{},'two');}catch{refused=true;}ok(refused&&count===1,'pending confirmation rejects overlapping UI command');release({movement_id:9});await first;ok(!concurrent.pending,'completed command releases UI busy state');
|
|
const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'));const proof=run.root+'/private/receipt-composition-b4093c6f6707/single-workshop-stock-client-20261110.json';fs.writeFileSync(proof,JSON.stringify({passed:true,checks,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:checks.length,proof}));
|