Implement server-owned read-only sample checks, category publication, explicit order-version identity and durable PDF/archive/notification steps. Freeze category-bound templates and recipients for isolated scheduled delivery, and require human verification for unknown SMTP outcomes. Add order/batch views and local HTTP/browser/PDF/archive regression coverage. Fix Unicode Windows startup links found by full regression using IShellLinkW. Automatic processing and sending stay disabled; no service deployment. Validation: npm ci; npm test -- --test-concurrency=1 (242 pass, 1 optional ZCode skip, 0 fail); 31 syntax checks; scoped independent code review. Live BPM V13/SMB/163 acceptance remains pending.
18 lines
2.6 KiB
JavaScript
18 lines
2.6 KiB
JavaScript
'use strict';
|
|
const test=require('node:test');const assert=require('node:assert/strict');const fs=require('node:fs');const os=require('node:os');const path=require('node:path');
|
|
const {OrderWorkflowStore}=require('../src/order-workflow-store.cjs');
|
|
const testVault=()=>({encode:(id,value)=>Buffer.from(JSON.stringify(value)),decode:(id,value)=>JSON.parse(Buffer.from(value).toString('utf8')),destroy(){}});
|
|
test('workflow store persists order versions, step evidence and batches across restart',t=>{
|
|
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'order-workflow-store-')),vault=testVault();let store=new OrderWorkflowStore(dir,{vault});t.after(()=>{store.close();fs.rmSync(dir,{recursive:true,force:true});});
|
|
store.putOrder({versionKey:'v1',orderNo:'ORD-1',status:'archive_error',steps:{detail:{status:'success'},pdf:{status:'success'},archive:{status:'error',error:'SMB unavailable'}}});
|
|
store.putBatch({id:'b1',status:'unknown',orderVersionKeys:['v1'],to:['test@example.test'],cc:[]});
|
|
store.close();store=new OrderWorkflowStore(dir,{vault});assert.equal(store.getOrder('v1').status,'unknown');assert.equal(store.getOrder('v1').steps.archive.error,'SMB unavailable');assert.equal(store.getBatch('b1').status,'unknown');assert.deepEqual(store.getBatch('b1').orderVersionKeys,['v1']);
|
|
});
|
|
test('workflow store restart converts sending batch to unknown without replaying it',t=>{
|
|
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'order-workflow-restart-')),vault=testVault();let store=new OrderWorkflowStore(dir,{vault});t.after(()=>{store.close();fs.rmSync(dir,{recursive:true,force:true});});
|
|
store.putBatch({id:'b1',status:'sending',orderVersionKeys:['v1'],to:['test@example.test'],cc:[]});store.close();store=new OrderWorkflowStore(dir,{vault});assert.equal(store.getBatch('b1').status,'unknown');assert.equal(store.getBatch('b1').error,'服务重启,发送结果需要核实。');
|
|
});
|
|
test('restart reconciles both sending batch and linked order atomically',t=>{
|
|
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'workflow-recovery-')),vault=testVault();let store=new OrderWorkflowStore(dir,{vault});t.after(()=>{store.close();fs.rmSync(dir,{recursive:true,force:true});});store.putOrder({versionKey:'v',orderNo:'000123',status:'sending',notification:{status:'sending',batchId:'b'},steps:{notification:{status:'sending'}}});store.putBatch({id:'b',status:'sending',orderVersionKeys:['v']});store.close();store=new OrderWorkflowStore(dir,{vault});assert.equal(store.getBatch('b').status,'unknown');assert.equal(store.getOrder('v').status,'unknown');assert.equal(store.getOrder('v').steps.notification.status,'unknown');
|
|
});
|