Personal Telegram developer console for GitHub
test: require Telegram API failures to propagate
davoodmehraban89 committed
Oct 2, 2026 at 22:17 UTC
7ff11d881fad21db14f00a815863a25faa6054e1
1 file changed
+31
test/telegram.test.js
new
+31
@@ -0,0 +1,31 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { TelegramClient } from '../src/telegram.js';
4
+
5
+test('TelegramClient rejects HTTP-level Telegram API failures', async () => {
6
+ const client = new TelegramClient('token', {
7
+ fetch: async () => new Response(JSON.stringify({ ok: false, description: 'Bad Request' }), {
8
+ status: 400,
9
+ headers: { 'content-type': 'application/json' }
10
+ })
11
+ });
12
+
13
+ await assert.rejects(
14
+ () => client.sendMessage(1, 'hello'),
15
+ /Telegram API sendMessage failed: 400.*Bad Request/i
16
+ );
17
+});
18
+
19
+test('TelegramClient rejects Telegram ok:false responses even with HTTP 200', async () => {
20
+ const client = new TelegramClient('token', {
21
+ fetch: async () => new Response(JSON.stringify({ ok: false, description: 'message is not modified' }), {
22
+ status: 200,
23
+ headers: { 'content-type': 'application/json' }
24
+ })
25
+ });
26
+
27
+ await assert.rejects(
28
+ () => client.editMessageText(1, 2, 'same'),
29
+ /message is not modified/i
30
+ );
31
+});