Web 与 App 支持选传最多 9 张、单张 50MB 照片,并与本次入库和移库事务绑定。库存图库按项目、物品、库区归集到货、入库和移库照片,支持来源筛选、缩略图及原图预览,校验只读权限和照片归属。附开发数据库结构脚本、更新说明和相关测试,同时纳入采购明细垂直居中修正。
20 lines
1.8 KiB
JavaScript
20 lines
1.8 KiB
JavaScript
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']);
|
|
});
|