fix: preserve complete weekly brief content and date bounds
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createBriefBuilder, splitBriefText } from '../server/brief-content.mjs';
|
||||
|
||||
const parseDate = value => /^\d{4}-\d{2}-\d{2}$/.test(value || '') ? new Date(value+'T00:00:00+03:00') : null;
|
||||
|
||||
test('brief includes more than 200 tracked tenders and 15 results without silent caps',()=>{
|
||||
const keys=Array.from({length:205},(_,i)=>`2026/${i}`), seen=[];
|
||||
const now=new Date('2026-09-06T21:05:00Z');
|
||||
const build=createBriefBuilder({trackedKeys:()=>[...keys,keys[0]],
|
||||
upcoming:(email,tenders,days,clock)=>{assert.equal(clock,now);assert.equal(days,7);return [];},
|
||||
results:key=>{seen.push(key);return [{baslik:key,sozlesmeTarihi:'2026-09-06'}];},parseDate});
|
||||
const result=build('test@example.test',[],now);
|
||||
assert.equal(result.sonuclar.length,205);
|
||||
assert.equal(new Set(result.sonuclar.map(t=>t.ikn)).size,205);
|
||||
assert.equal(seen.length,205);
|
||||
assert.equal(result.bos,false);
|
||||
assert.equal(result.hafta,'07 Eylül 2026');
|
||||
});
|
||||
|
||||
test('previous seven full Istanbul dates include the first day and exclude current/future dates',()=>{
|
||||
const build=createBriefBuilder({trackedKeys:()=>['2026/1'],upcoming:()=>[],parseDate,
|
||||
results:()=>['2026-08-30','2026-08-31','2026-09-06','2026-09-07','2026-09-08','invalid']
|
||||
.map(date=>({baslik:date,sozlesmeTarihi:date}))});
|
||||
const result=build('test@example.test',[],new Date('2026-09-06T21:05:00Z'));
|
||||
assert.deepEqual(result.sonuclar.map(t=>t.baslik),['2026-09-06','2026-08-31']);
|
||||
});
|
||||
|
||||
test('long Turkish/emoji text is preserved exactly without splitting surrogate pairs',()=>{
|
||||
const text=('Laboratuvar <kit> & test 🧪\n').repeat(600);
|
||||
const parts=splitBriefText(text);
|
||||
assert.ok(parts.length>3);
|
||||
assert.equal(parts.join(''),text);
|
||||
for(const part of parts){assert.ok(part.length<=3900);assert.ok(part.isWellFormed());}
|
||||
assert.deepEqual(splitBriefText(''),[]);
|
||||
assert.throws(()=>splitBriefText('text',1));
|
||||
});
|
||||
@@ -75,3 +75,24 @@ test('one recipient failure does not skip subsequent recipients; feed failure is
|
||||
assert.deepEqual(f.calls,['email']);
|
||||
await assert.rejects(f.send(async()=>{throw new Error('Feed unavailable');}),/Feed unavailable/);
|
||||
});
|
||||
|
||||
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;}});
|
||||
const result=await f.send(async()=>[]);
|
||||
assert.equal(sent.join(''),content);
|
||||
assert.ok(sent.length>1);
|
||||
assert.equal(result.kanallar.telegram.kabul,sent.length);
|
||||
assert.equal(result.hata,0);
|
||||
});
|
||||
|
||||
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 result=await f.send(async()=>[]);
|
||||
assert.equal(attempts,2);
|
||||
assert.deepEqual(result.kanallar.telegram,{denenen:2,kabul:1,hata:1});
|
||||
assert.equal(result.kanallar.email.kabul,1);
|
||||
assert.equal(result.hata,1);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { sendTelegram } from '../server/telegram.mjs';
|
||||
|
||||
test('brief plain-text mode reaches Telegram request without HTML parsing or content changes',async()=>{
|
||||
const oldFetch=globalThis.fetch,oldToken=process.env.TELEGRAM_BOT_TOKEN;
|
||||
process.env.TELEGRAM_BOT_TOKEN='synthetic-test-token';
|
||||
const payloads=[];
|
||||
globalThis.fetch=async(url,options)=>{payloads.push(JSON.parse(options.body));return {ok:true,json:async()=>({ok:true})};};
|
||||
try {
|
||||
const text='Laboratuvar <test> & ürün 🧪';
|
||||
assert.equal(await sendTelegram('test-chat',text,{parseMode:null}),true);
|
||||
assert.equal(payloads[0].text,text);
|
||||
assert.equal(Object.hasOwn(payloads[0],'parse_mode'),false);
|
||||
await sendTelegram('test-chat','<b>Başlık</b>');
|
||||
assert.equal(payloads[1].parse_mode,'HTML');
|
||||
} finally {
|
||||
globalThis.fetch=oldFetch;
|
||||
if(oldToken===undefined)delete process.env.TELEGRAM_BOT_TOKEN;
|
||||
else process.env.TELEGRAM_BOT_TOKEN=oldToken;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user