Personal Telegram developer console for GitHub

test: require redacted webhook failure diagnostics

davoodmehraban89 committed Oct 3, 2026 at 00:28 UTC 079f9b7977e1120d1bcdbbcd75d91e6a322e5a49
1 file changed +32
test/index.test.js
+32
@@ -91,4 +91,36 @@ describe('Nexa Dev Bot - Cloudflare Worker Entrypoint', () => {
91 }), runtime);
92 assert.equal(res.status, 404);
93 });
94 +
95 + it('logs Telegram webhook processing failures without exposing the bot token', async () => {
96 + const originalFetch = globalThis.fetch;
97 + const originalError = console.error;
98 + const logs = [];
99 + const secretToken = 'telegram-secret-token-for-test';
100 +
101 + globalThis.fetch = async (url) => {
102 + if (String(url).startsWith('https://api.telegram.org/')) {
103 + return new Response(JSON.stringify({ ok: false, description: 'Unauthorized' }), {
104 + status: 401,
105 + headers: { 'content-type': 'application/json' }
106 + });
107 + }
108 + return originalFetch(url);
109 + };
110 + console.error = (...args) => logs.push(args.map(String).join(' '));
111 +
112 + try {
113 + const res = await worker.fetch(webhookRequest(), {
114 + ...runtime,
115 + TELEGRAM_BOT_TOKEN: secretToken
116 + });
117 + assert.equal(res.status, 400);
118 + assert.ok(logs.some(line => /telegram_webhook_error/i.test(line)));
119 + assert.ok(logs.some(line => /401|Unauthorized/i.test(line)));
120 + assert.ok(logs.every(line => !line.includes(secretToken)));
121 + } finally {
122 + globalThis.fetch = originalFetch;
123 + console.error = originalError;
124 + }
125 + });
126 });