mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:27:39 +00:00
Telegram: enable grammY throttler and webhook tests
This commit is contained in:
33
src/telegram/bot.test.ts
Normal file
33
src/telegram/bot.test.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user