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.
21 lines
2.5 KiB
JavaScript
21 lines
2.5 KiB
JavaScript
'use strict';
|
|
const test=require('node:test');const assert=require('node:assert/strict');const {orderWorkflowApi}=require('../src/order-workflow-api.cjs');
|
|
const user={username:'admin',role:'admin'};
|
|
async function request(route,body,{role='admin',pipeline,workflow}={}){let result;await orderWorkflowApi({user:{...user,role},sessionId:'s',route,method:body===undefined?'GET':'POST',body,pipeline,workflow:workflow||{},reply:(status,value)=>result={status,value}});return result;}
|
|
test('HTTP cannot forge BPM provenance, PDF success, SMB success, or caller-owned batches',async()=>{
|
|
for(const [route,body] of [['/api/order-workflow/identify',{provenance:'bpm-readonly',detail:{}}],['/api/order-workflow/orders/o/pdf-success',{jobId:'forged'}],['/api/order-workflow/orders/o/archive-success',{archiveId:'forged'}],['/api/order-workflow/batches/b/freeze',{groups:{},templates:{}}]])await assert.rejects(()=>request(route,body),error=>[403,404,409].includes(error.status));
|
|
});
|
|
test('sample check only accepts a persisted arrival reference and verifies configuration admin role',async()=>{
|
|
const pipeline={checkRule:async(id,input,principal)=>({valid:true,checkId:'c',id,input,actor:principal.user.username})};
|
|
const ok=await request('/api/order-workflow/rules/r/check',{connectionId:'c',source:'v4',taskId:'t'},{pipeline});assert.equal(ok.value.checkId,'c');
|
|
await assert.rejects(()=>request('/api/order-workflow/rules/r/check',{connectionId:'c',source:'v4',taskId:'t',detail:{forged:true}},{pipeline}),error=>error.status===400);
|
|
await assert.rejects(()=>request('/api/order-workflow/rules/r/check',{connectionId:'c',source:'v4',taskId:'t'},{role:'operator',pipeline}),error=>error.status===403);
|
|
});
|
|
test('viewer can inspect workflow and cannot retry or resolve and unknown requires admin evidence',async()=>{
|
|
const workflow={listOrders:()=>[],listBatches:()=>[],resolveBatch:()=>({status:'sent'})},pipeline={arrivals:()=>[],config:()=>({enabled:false}),retry:async()=>({status:'archived'})};
|
|
assert.equal((await request('/api/order-workflow',undefined,{role:'viewer',workflow,pipeline})).status,200);
|
|
await assert.rejects(()=>request('/api/order-workflow/orders/o/retry',{},{role:'viewer',workflow,pipeline}),error=>error.status===403);
|
|
await assert.rejects(()=>request('/api/order-workflow/batches/b/resolve',{resolution:'retry',note:'已核验邮件记录'},{role:'operator',workflow,pipeline}),error=>error.status===403);
|
|
assert.equal((await request('/api/order-workflow/batches/b/resolve',{resolution:'sent',note:'已核验邮件记录'},{workflow,pipeline})).value.status,'sent');
|
|
});
|