fix: preserve rule coverage and verify isolated sample delivery
This commit is contained in:
1 parent
5c34851347
commit
f936940ec0
9 files changed
+65
-5
No files matched your search
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict');
|
||||
const {MailService}=require('../../src/modules/mail/service.cjs');
|
||||
function fixture(unknown=false){
|
||||
const rows=[],messages=[],store={channelSecret:()=>({id:'channel',version:1,email:'sender@example.test',name:'fixture',smtp:{}}),guard(){},findSampleSend:(id,key)=>rows.find(r=>r.channel_id===id&&r.template_id===key),beginSend:(id,key)=>{rows.push({id:'send-1',channel_id:id,template_id:key,status:'sending'});return 'send-1';},finishSend:(id,status)=>{rows.find(r=>r.id===id).status=status;}};
|
||||
const service=new MailService({store,smtpFactory:()=>({verify:async()=>{},sendMail:async message=>{messages.push(message);if(unknown)throw Error('fixture disconnected');return {accepted:['2639266652@qq.com'],rejected:[]};},close(){}})});
|
||||
return {service,rows,messages,input:{idempotencyKey:'sample-once',subject:'分类汇总样例',text:'大家好:\n订单号:TEST-A\n订单号:TEST-B'}};
|
||||
}
|
||||
test('sample mail uses fixed isolated envelope, no attachments and a persistent no-repeat receipt',async()=>{
|
||||
const f=fixture(),result=await f.service.sendSample('channel',f.input);assert.equal(result.status,'sent');assert.equal(f.messages.length,1);assert.deepEqual(f.messages[0].to,['2639266652@qq.com']);assert.deepEqual(f.messages[0].cc,[]);assert.deepEqual(f.messages[0].attachments,[]);assert.match(f.messages[0].subject,/样例测试/);assert.match(f.messages[0].text,/不表示.*PDF.*归档/);assert.match(f.messages[0].text,/订单号:TEST-A\n订单号:TEST-B/);
|
||||
assert.equal((await f.service.sendSample('channel',f.input)).reused,true);assert.equal(f.messages.length,1);
|
||||
});
|
||||
test('unknown sample delivery is retained and never retried automatically',async()=>{
|
||||
const f=fixture(true);await assert.rejects(()=>f.service.sendSample('channel',f.input),e=>e.status===502);assert.equal(f.rows[0].status,'unknown');await assert.rejects(()=>f.service.sendSample('channel',f.input),e=>e.status===409);assert.equal(f.messages.length,1);
|
||||
});
|
||||
test('sample requests cannot select other recipients, attachments or injected headers',async()=>{
|
||||
const f=fixture();for(const patch of [{to:['other@example.test']},{attachments:[]},{subject:'bad\r\nBcc: other@example.test'},{idempotencyKey:''}])await assert.rejects(()=>f.service.sendSample('channel',{...f.input,...patch}),e=>e.status===400);assert.equal(f.messages.length,0);
|
||||
});
|
||||
@@ -49,3 +49,9 @@ test('unusable imports roll back atomically and uncovered flows remain explicitl
|
||||
assert(f.store.restrictedTest().uncovered.some(row=>row.processName==='未配置字段的流程'));
|
||||
const blocked=f.store.ingest({...f.event('uncovered'),processName:'未配置字段的流程'},'fixture');assert.equal(blocked.status,'blocked');assert.equal(blocked.archive,null);
|
||||
});
|
||||
test('applying one category retains missing-flow warnings for other categories',t=>{
|
||||
const f=fixture(t);activateReferenceMapping(f.store,'overseas-change');const other=f.store.get('rules','overseas-change').draft;
|
||||
f.store.saveRule({...other,to:['2639266652@qq.com'],cc:[],bodyTemplateId:'',archiveDirectory:f.root+'\\other',filenameDate:'receivedAt'},'admin');
|
||||
f.store.put('restricted-test',{id:'main',value:null});const run=f.store.saveRestrictedTest({version:0,enabled:true,recipient:'2639266652@qq.com',archiveRoot:f.root,channelId:'fixture-mail',ruleIds:['bs-change','overseas-change']},admin);assert(run.uncovered.length>0);
|
||||
const rule=f.store.get('rules','bs-change').draft;f.store.applyRestrictedDrafts({version:run.version,rules:[{id:rule.id,version:rule.version}]},admin);assert.deepEqual(f.store.restrictedTest().uncovered,run.uncovered);
|
||||
});
|
||||
@@ -32,6 +32,10 @@ test('unmatched arrivals never enter order lists, counts or details while classi
|
||||
for(const id of ['candidate:candidate-a','candidate:candidate-b','unmatched-order','task:unmatched-task'])assert.throws(()=>orderDetail(c,id,user),e=>e.status===404);
|
||||
assert.equal(c.orderRules.all('execution-candidates').length,2);assert.equal(c.orderRules.get('orders','unmatched-order').status,'blocked');
|
||||
});
|
||||
test('removed orders disappear from the center without erasing archive or dedup evidence',()=>{
|
||||
const c=fixture(),order=c.orderRules.get('orders','o0');order.archive={files:[{name:'retained.pdf',sha256:'a'.repeat(64)}]};order.removedAt='2026-10-23T08:00:00Z';order.status='ignored';
|
||||
assert.equal(queryOrders(c,{},user).total,82);assert.equal(summary(c,user).counts.orders,82);assert.throws(()=>orderDetail(c,'o0',user),e=>e.status===404);assert.equal(c.orderRules.get('orders','o0').archive.files[0].name,'retained.pdf');
|
||||
});
|
||||
test('file endpoint reauthorizes and validates bytes against durable evidence',async()=>{
|
||||
const c=fixture(),bytes=Buffer.from('%PDF-x');c.orderRules.get('orders','o0').archive={files:[{name:'a.pdf',path:'server-only',size:bytes.length,sha256:require('node:crypto').createHash('sha256').update(bytes).digest('hex')}]};
|
||||
assert.deepEqual((await readOrderFile(c,'o0',0,user)).bytes,bytes);c.execution.archive.read=async()=>Buffer.from('tampered');await assert.rejects(()=>readOrderFile(c,'o0',0,user));await assert.rejects(()=>readOrderFile(c,'foreign',0,user));
|
||||
|
||||
Reference in new issue
Block a user