Files
order-notification-automation/tests/order-workflow-api.test.cjs
T
abaishu0730 94fc985553 feat: add guarded BPM category and template workflow
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.
2026-10-22 16:52:59 +08:00

16 lines
1.7 KiB
JavaScript

'use strict';
const test=require('node:test');const assert=require('node:assert/strict');
const {orderWorkflowApi}=require('../src/order-workflow-api.cjs');const {OrderWorkflow}=require('../src/order-workflow.cjs');
const rule={id:'r',enabled:false,processName:'流程',nodeName:'节点',productLine:'L',templateId:'tpl',pdfTemplateId:'bpm-snapshot-v1',recipientGroupId:'L',notificationType:'order',batchMode:'category_template',adapters:{V13:{orderNo:'order'}}};
async function call(user,body,workflow=new OrderWorkflow()){let result;await orderWorkflowApi({workflow,user,route:'/api/order-workflow/rules',method:'POST',body,reply:(status,value)=>result={status,value}});return result;}
test('only admins save category bindings and edits preserve optimistic version checks',async()=>{
const workflow=new OrderWorkflow();await assert.rejects(()=>call({role:'operator'},rule,workflow),e=>e.status===403);await assert.rejects(()=>call({role:'viewer'},rule,workflow),e=>e.status===403);
const first=await call({role:'admin'},rule,workflow);assert.equal(first.value.status,'draft');assert.equal(first.value.pdfTemplateId,'bpm-snapshot-v1');assert.equal(first.value.recipientGroupId,'L');
await assert.rejects(()=>call({role:'admin'},rule,workflow),e=>e.code==='RULE_VERSION_CONFLICT');
const saved=await call({role:'admin'},{...rule,version:first.value.version,templateId:'tpl2'},workflow);assert.equal(saved.value.version,2);
});
test('category configuration cannot inject raw recipient addresses or a published status',async()=>{
await assert.rejects(()=>call({role:'admin'},{...rule,recipientGroup:{to:['other@example.test']}}),e=>e.status===400);
await assert.rejects(()=>call({role:'admin'},{...rule,status:'published'}),e=>e.status===400);
});