import test from 'node:test'; import assert from 'node:assert/strict'; import {operationPayload,validateOperation,runOperations} from '../src/core/stock-operations.ts'; const form={date:'2026-11-25',remark:'',project:null}; const row=()=>({source:{id:7,receiptRoot:true,inNum:5,stockNum:5,projectId:4,productId:3,areaId:1},area:{id:2},quantity:'2',key:'operation-1',status:'editing',error:''}); test('receipt and move accept no photos; each batch row carries only its own selected photo IDs',()=>{ for(const kind of ['move','receive']){ assert.equal(validateOperation(kind,[row()],form),'');assert.equal(operationPayload(kind,row(),form)[0].body.photoIds,undefined); assert.deepEqual(operationPayload(kind,{...row(),photos:[{id:'photo-a'}]},form)[0].body.photoIds,['photo-a']); assert.deepEqual(operationPayload(kind,{...row(),photos:[{id:'photo-b'}]},form)[0].body.photoIds,['photo-b']); assert.ok(validateOperation(kind,[{...row(),photosPending:true}],form));assert.ok(validateOperation(kind,[{...row(),photos:[{error:'failed'}]}],form));assert.ok(validateOperation(kind,[{...row(),photos:Array.from({length:10},(_,i)=>({id:String(i)}))}],form)); } const legacy={...row(),source:{...row().source,receiptRoot:false}};assert.deepEqual(operationPayload('receive',{...legacy,photos:[{id:'photo-a'}]},form)[1].body.photoIds,['photo-a']); }); test('uncertain retries retain original photos and do not change the stock request',async()=>{ const calls=[];let rows=await runOperations('move',[{...row(),photos:[{id:'original'}]}],form,async(path,options)=>{calls.push(options.body);throw Error('timeout');},async()=>{}); rows[0].photos=[{id:'replacement'}];await runOperations('move',rows,form,async(path,options)=>calls.push(options.body),async()=>{}); assert.deepEqual(calls[0],calls[1]);assert.deepEqual(calls[1].photoIds,['original']); });