fix: carry confirmed unsent orders into the next scheduled batch
This commit is contained in:
1 parent
dfdcf0cc2d
commit
069a69af93
23 files changed
+338
-40
No files matched your search
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
const test=require('node:test');
|
||||
const assert=require('node:assert/strict');
|
||||
const {OrderRuleDispatcher}=require('../../src/modules/order-rules/dispatcher.cjs');
|
||||
const at='2026-10-27T03:30:00.000Z';
|
||||
function fixture({verifyError,sendError,result,channelId='mail',expired=false}={}){
|
||||
const batch={id:'batch',status:'prepared',cutoff:expired?'2026-10-27T02:00:00.000Z':at,channelId,to:['2639266652@qq.com'],cc:[],attachments:[],orderIds:['order'],ruleSnapshot:{}};
|
||||
const completions=[];let submissions=0,begun=0;
|
||||
const store={get:()=>null,now:()=>at,settings:()=>({enabled:true,channelId:'mail'}),snapshot:()=>({batches:[batch],capabilities:{liveTodo:true,pdfExport:true,automaticArchive:true}}),discoveryBlockers:()=>[],batchIncomplete:()=>false,beginSending:()=>{begun++;},finishSending:(...args)=>completions.push(args)};
|
||||
const mail={store:{channelSecret:()=>({id:'mail',version:1,email:'sender@example.com',smtp:{}}),guard:()=>{}},smtpFactory:()=>({verify:async()=>{if(verifyError)throw verifyError;},sendMail:async()=>{submissions++;if(sendError)throw sendError;return result||{accepted:['2639266652@qq.com'],rejected:[]};},close:()=>{}})};
|
||||
const dispatcher=new OrderRuleDispatcher({store,mail,settings:()=>({}),clock:()=>new Date(at),providersReady:()=>true});
|
||||
return {dispatcher,batch,store,completions,counts:()=>({submissions,begun})};
|
||||
}
|
||||
test('SMTP verify failure proves no submission and can safely be considered for carry-forward',async()=>{
|
||||
const f=fixture({verifyError:Error('offline')});await f.dispatcher.dispatch(f.batch,f.store.settings());
|
||||
assert.equal(f.completions[0][1],'failed');assert.deepEqual(f.completions[0][3],{outcome:'not_submitted',phase:'preflight',at});assert.deepEqual(f.counts(),{submissions:0,begun:0});
|
||||
});
|
||||
test('expired prepared queue records definite no submission',async()=>{
|
||||
const f=fixture({expired:true});await f.dispatcher.perform(new Date(at));
|
||||
assert.deepEqual(f.completions[0][3],{outcome:'not_submitted',phase:'queue_expired',at});assert.equal(f.counts().submissions,0);
|
||||
});
|
||||
test('channel mismatch is rejected before SMTP with no submission evidence',async()=>{
|
||||
const f=fixture({channelId:'previous'});await f.dispatcher.dispatch(f.batch,f.store.settings());
|
||||
assert.deepEqual(f.completions[0][3],{outcome:'not_submitted',phase:'preflight',at});assert.equal(f.counts().submissions,0);
|
||||
});
|
||||
test('strict complete RCPT rejection records an unsent envelope outcome',async()=>{
|
||||
const f=fixture({sendError:Object.assign(Error('rejected'),{code:'EENVELOPE',command:'RCPT TO',rejected:['2639266652@qq.com'],accepted:[]})});await f.dispatcher.dispatch(f.batch,f.store.settings());
|
||||
assert.equal(f.completions[0][1],'failed');assert.deepEqual(f.completions[0][3],{outcome:'all_recipients_rejected',phase:'smtp_envelope',at});assert.equal(f.counts().submissions,1);
|
||||
});
|
||||
for(const [name,options] of [
|
||||
['SMTP timeout',{sendError:Object.assign(Error('timeout'),{code:'ETIMEDOUT'})}],
|
||||
['partial SMTP acceptance',{result:{accepted:['2639266652@qq.com'],rejected:['other@example.com']}}],
|
||||
['RCPT error with accepted recipients',{sendError:Object.assign(Error('mixed'),{code:'EENVELOPE',command:'RCPT TO',rejected:['2639266652@qq.com'],accepted:['2639266652@qq.com']})}],
|
||||
['unproven recipient rejection',{sendError:Object.assign(Error('other'),{code:'EENVELOPE',command:'RCPT TO',rejected:['other@example.com'],accepted:[]})}],
|
||||
])test(name+' remains unknown without an unsent proof',async()=>{
|
||||
const f=fixture(options);await f.dispatcher.dispatch(f.batch,f.store.settings());assert.equal(f.completions[0][1],'unknown');assert.equal(f.completions[0][3],undefined);assert.equal(f.counts().submissions,1);
|
||||
});
|
||||
Reference in new issue
Block a user