Personal Telegram developer console for GitHub
test: cover temporary Telegram webhook setup endpoint
davoodmehraban89 committed
Oct 2, 2026 at 18:34 UTC
dd2da6d9e56c5de7197f639873fccfcaa36c479b
1 file changed
+31
test/security.test.js
+31
@@ -80,3 +80,34 @@ test("unauthorized Telegram users receive no bot response", async () => {
80
assert.equal(res.status, 200);
81
assert.equal(calls, 0);
82
});
83
+
84
+test("temporary setup endpoint registers Telegram webhook to this worker", async () => {
85
+ const req = new Request("https://nexa-dev-bot.example.workers.dev/telegram/setup", {
86
+ method: "GET",
87
+ });
88
+
89
+ let captured;
90
+ globalThis.fetch = async (url, init) => {
91
+ captured = {
92
+ url: String(url),
93
+ body: JSON.parse(init.body),
94
+ };
95
+ return new Response(JSON.stringify({ ok: true, result: true }), {
96
+ status: 200,
97
+ headers: { "content-type": "application/json" },
98
+ });
99
+ };
100
+
101
+ const res = await worker.fetch(req, {
102
+ TELEGRAM_WEBHOOK_SECRET: "secret",
103
+ TELEGRAM_BOT_TOKEN: "token",
104
+ });
105
+
106
+ assert.equal(res.status, 200);
107
+ assert.equal(captured.url, "https://api.telegram.org/bottoken/setWebhook");
108
+ assert.deepEqual(captured.body, {
109
+ url: "https://nexa-dev-bot.example.workers.dev/telegram/webhook",
110
+ secret_token: "secret",
111
+ allowed_updates: ["message"],
112
+ });
113
+});