Files
ihaleist/tests/telegram-brief-transport.test.mjs
T

23 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
});