Telegram: enable grammY throttler and webhook tests

This commit is contained in:
Peter Steinberger
2025-12-07 22:52:57 +01:00
parent 4d3d9cca2a
commit 5f5846a08b
7 changed files with 120 additions and 6 deletions

33
src/telegram/bot.test.ts Normal file
View File

@@ -0,0 +1,33 @@
import { describe, expect, it, vi } from "vitest";
const useSpy = vi.fn();
const onSpy = vi.fn();
const stopSpy = vi.fn();
const apiStub = { config: { use: useSpy } };
vi.mock("grammy", () => ({
Bot: class {
api = apiStub as any;
on = onSpy;
stop = stopSpy;
constructor(public token: string) {}
},
InputFile: class {},
webhookCallback: vi.fn(),
}));
const throttlerSpy = vi.fn(() => "throttler");
vi.mock("@grammyjs/transformer-throttler", () => ({
apiThrottler: () => throttlerSpy(),
}));
import { createTelegramBot } from "./bot.js";
describe("createTelegramBot", () => {
it("installs grammY throttler", () => {
createTelegramBot({ token: "tok" });
expect(throttlerSpy).toHaveBeenCalledTimes(1);
expect(useSpy).toHaveBeenCalledWith("throttler");
});
});