Persist notification email batches with leased idempotent delivery

This commit is contained in:
2026-09-06 13:03:47 +03:00
parent cbfdd072d1
commit d956de3014
7 changed files with 122 additions and 17 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ test('delivery failure retains pending items and batches acknowledge only includ
const rows=Array.from({length:28},(_,i)=>({...future,id:'t-'+i,ikn:'2026/'+i,baslik:'Laboratuvar '+i}));
const subscription={id:1,email:'qa@example.test',initialized:true,sonGorulenler:[]};
const sent=[],messages=[];let fail=true;
const dependencies={now,configured:()=>true,telegramReady:()=>false,readSubscriptions:()=>[subscription],saveSent:(id,ids)=>{sent.push(ids);subscription.sonGorulenler.push(...ids);},deliverEmail:async message=>{if(fail)throw new Error('provider unavailable');messages.push(message);}};
const dependencies={now,configured:()=>true,telegramReady:()=>false,readSubscriptions:()=>[subscription],reserve:(id,payload,ids)=>({id:'test-delivery',payload,tenderIds:ids}),accepted:delivery=>{sent.push(delivery.tenderIds);subscription.sonGorulenler.push(...delivery.tenderIds);},failed:()=>{},deliverEmail:async message=>{if(fail)throw new Error('provider unavailable');messages.push(message);return {id:'provider-test'};}};
assert.equal((await bildirimleriIsle(async()=>({tenders:rows}),{},dependencies)).hata,1);assert.equal(sent.length,0);
fail=false;assert.equal((await bildirimleriIsle(async()=>({tenders:rows}),{},dependencies)).gonderilen,1);assert.equal(sent[0].length,25);assert.match(messages[0].html,/>Laboratuvar 24</);assert.doesNotMatch(messages[0].html,/>Laboratuvar 25</);
await bildirimleriIsle(async()=>({tenders:rows}),{},dependencies);assert.equal(sent[1].length,3);assert.match(messages[1].html,/>Laboratuvar 27</);