Keep unsent notification batches pending and retain seen history

This commit is contained in:
2026-09-06 13:00:12 +03:00
parent d2d66c8e9d
commit 4c4ba0c4c8
5 changed files with 82 additions and 23 deletions
+26
View File
@@ -0,0 +1,26 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {bildirimleriIsle,bildirilebilir} from '../server/notifier.mjs';
const future={tarih:'10.09.2026',saat:'10:00',durum:'Açık',baslik:'Laboratuvar'};
const now=()=>new Date('2026-09-06T10:00:00Z');
test('notification eligibility excludes expired cancelled and unknown deadlines',()=>{
assert.equal(bildirilebilir(future,now()),true);
for(const patch of [{durum:'İptal'},{durum:'Sonuçlandı'},{id:'hist-1'},{tarih:'01.09.2026'},{saat:''},{tarih:''}])assert.equal(bildirilebilir({...future,...patch},now()),false);
});
test('delivery failure retains pending items and batches acknowledge only included tenders',async()=>{
const rows=Array.from({length:28},(_,i)=>({...future,id:'t-'+i,ikn:'2026/'+i}));
const subscription={id:1,email:'qa@example.test',initialized:true,sonGorulenler:[]};
const sent=[];let fail=true;
const dependencies={now,configured:()=>true,telegramReady:()=>false,readSubscriptions:()=>[subscription],saveSent:(id,ids)=>{sent.push(ids);subscription.sonGorulenler.push(...ids);},deliverEmail:async()=>{if(fail)throw new Error('provider unavailable');}};
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);
await bildirimleriIsle(async()=>({tenders:rows}),{},dependencies);assert.equal(sent[1].length,3);
await bildirimleriIsle(async()=>({tenders:rows}),{},dependencies);assert.equal(sent.length,2);
});
test('baseline is distinct from delivery and overlapping turns do not send twice',async()=>{
let release;const pending=new Promise(resolve=>release=resolve);let baseline=0;
const dependencies={now,configured:()=>true,telegramReady:()=>false,readSubscriptions:()=>[{id:1,initialized:false}],saveBaseline:()=>baseline++,deliverEmail:()=>assert.fail('baseline must not send')};
const first=bildirimleriIsle(async()=>{await pending;return {tenders:[future]};},{},dependencies);
assert.equal((await bildirimleriIsle(()=>assert.fail(),{},dependencies)).atlandi,'önceki tur sürüyor');
release();await first;assert.equal(baseline,1);
});
+8
View File
@@ -26,3 +26,11 @@ test('distinct topic and institution sets coexist while equivalent subscriptions
subscriptions.subscribe('sets',{konular:['Laboratuvar','TEST'],kurumlar:['Hastane B']});
rows=subscriptions.list('sets');assert.equal(rows.length,3);assert.equal(rows.find(row=>row.id===one.id).sonGorulenler[0],'tender-1');
});
test('baseline does not claim delivery and seen history is not truncated at 400',()=>{
const row=subscriptions.subscribe('history',{konular:['Laboratuvar']})[0];
subscriptions.markBaseline(row.id,Array.from({length:450},(_,i)=>'old-'+i));
let saved=subscriptions.list('history')[0];assert.equal(saved.initialized,true);assert.equal(saved.sonGonderim,null);assert.equal(saved.sonGorulenler.length,450);
subscriptions.markSent(row.id,['new-1','old-1']);saved=subscriptions.list('history')[0];
assert.equal(saved.sonGorulenler.length,451);assert.ok(saved.sonGonderim);assert.ok(saved.sonGorulenler.includes('old-0'));
});