fix: retain verified Telegram message receipts for weekly briefs

This commit is contained in:
2026-09-06 14:39:12 +03:00
parent 7a01e4bed7
commit df0626a71f
7 changed files with 63 additions and 9 deletions
+4 -4
View File
@@ -9,7 +9,7 @@ function fixture(overrides={}) {
store:{ listUsers:()=>[{email:'one@example.test'}], getData:(email,key)=>key==='brief'?prefs.get(email):{chatId:'test-chat'} },
buildBrief:()=>({bos:false,hafta:'Test'}),text:()=> 'Test metni',html:()=> '<p>Test metni</p>',
telegramConfigured:()=>true,emailConfigured:()=>true,
sendTelegram:async()=>{calls.push('telegram');return true;},
sendTelegram:async()=>{calls.push('telegram');return {id:'test-chat:1'};},
sendEmail:async()=>{calls.push('email');return {id:'test-receipt'};},
warn:()=>{}, ...overrides,
};
@@ -45,7 +45,7 @@ test('false and missing receipts do not become successful sends',async()=>{
});
test('opt-out during Telegram delivery prevents the following email',async()=>{
const f=fixture({sendTelegram:async()=>{f.prefs.set('one@example.test',{kapali:true});return true;}});
const f=fixture({sendTelegram:async()=>{f.prefs.set('one@example.test',{kapali:true});return {id:'test-chat:1'};}});
const result=await f.send(async()=>[]);
assert.equal(result.gonderilen,1);
assert.equal(result.kapali,1);
@@ -79,7 +79,7 @@ test('one recipient failure does not skip subsequent recipients; feed failure is
test('long brief is sent completely as plain text with each part accounted for',async()=>{
const content=('Ürün <test> & 🧪\n').repeat(700),sent=[];
const f=fixture({text:()=>content,emailConfigured:()=>false,
sendTelegram:async(chatId,text,options)=>{sent.push(text);assert.deepEqual(options,{parseMode:null});return true;}});
sendTelegram:async(chatId,text,options)=>{sent.push(text);assert.deepEqual(options,{parseMode:null,returnReceipt:true});return {id:'test-chat:1'};}});
const result=await f.send(async()=>[]);
assert.equal(sent.join(''),content);
assert.ok(sent.length>1);
@@ -89,7 +89,7 @@ test('long brief is sent completely as plain text with each part accounted for',
test('a failed Telegram part stops subsequent parts but still attempts email',async()=>{
let attempts=0;
const f=fixture({text:()=> 'x'.repeat(12000),sendTelegram:async()=>{attempts++;if(attempts===2)throw new Error('Unavailable');return true;}});
const f=fixture({text:()=> 'x'.repeat(12000),sendTelegram:async()=>{attempts++;if(attempts===2)throw new Error('Unavailable');return {id:'test-chat:1'};}});
const result=await f.send(async()=>[]);
assert.equal(attempts,2);
assert.deepEqual(result.kanallar.telegram,{denenen:2,kabul:1,hata:1});