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
+24
View File
@@ -20,3 +20,27 @@ test('brief plain-text mode reaches Telegram request without HTML parsing or con
else process.env.TELEGRAM_BOT_TOKEN=oldToken;
}
});
test('Telegram receipts preserve chat and message ids and reject incomplete or mismatched acceptance',async()=>{
const oldFetch=globalThis.fetch,oldToken=process.env.TELEGRAM_BOT_TOKEN;
process.env.TELEGRAM_BOT_TOKEN='synthetic-test-token';
let body={ok:true,result:{message_id:42,chat:{id:-100123}}},httpOk=true;
globalThis.fetch=async()=>({ok:httpOk,status:httpOk?200:502,json:async()=>body});
try {
const options={parseMode:null,returnReceipt:true};
assert.deepEqual(await sendTelegram('-100123','Test',options),{id:'-100123:42',chatId:'-100123',messageId:42});
for(const result of [undefined,{}, {message_id:0,chat:{id:-100123}}, {message_id:42,chat:{id:999}},
{message_id:'42',chat:{id:-100123}}, {message_id:42,chat:{id:0}}, {message_id:Number.MAX_SAFE_INTEGER+1,chat:{id:-100123}}]) {
body={ok:true,result};
await assert.rejects(sendTelegram('-100123','Test',options),/belirsiz/);
}
body={ok:true,result:{message_id:42,chat:{id:-100123}}};httpOk=false;
await assert.rejects(sendTelegram('-100123','Test',options),/HTTP 502/);
httpOk=true;body={ok:'true',result:{message_id:42,chat:{id:-100123}}};
await assert.rejects(sendTelegram('-100123','Test',options),/HTTP 200/);
} finally {
globalThis.fetch=oldFetch;
if(oldToken===undefined)delete process.env.TELEGRAM_BOT_TOKEN;
else process.env.TELEGRAM_BOT_TOKEN=oldToken;
}
});