fix: force telegram native fetch under bun

This commit is contained in:
Peter Steinberger
2026-01-08 04:40:29 +01:00
parent 3178a3014d
commit ab98ffe9fe
7 changed files with 101 additions and 11 deletions

View File

@@ -44,6 +44,7 @@ const middlewareUseSpy = vi.fn();
const onSpy = vi.fn();
const stopSpy = vi.fn();
const commandSpy = vi.fn();
const botCtorSpy = vi.fn();
const sendChatActionSpy = vi.fn();
const setMessageReactionSpy = vi.fn(async () => undefined);
const setMyCommandsSpy = vi.fn(async () => undefined);
@@ -76,7 +77,12 @@ vi.mock("grammy", () => ({
on = onSpy;
stop = stopSpy;
command = commandSpy;
constructor(public token: string) {}
constructor(
public token: string,
public options?: { client?: { fetch?: typeof fetch } },
) {
botCtorSpy(token, options);
}
},
InputFile: class {},
webhookCallback: vi.fn(),
@@ -118,6 +124,7 @@ describe("createTelegramBot", () => {
setMyCommandsSpy.mockReset();
middlewareUseSpy.mockReset();
sequentializeSpy.mockReset();
botCtorSpy.mockReset();
sequentializeKey = undefined;
});
@@ -127,6 +134,23 @@ describe("createTelegramBot", () => {
expect(useSpy).toHaveBeenCalledWith("throttler");
});
it("forces native fetch for BAN compatibility", () => {
const originalFetch = globalThis.fetch;
const fetchSpy = vi.fn() as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
try {
createTelegramBot({ token: "tok" });
expect(botCtorSpy).toHaveBeenCalledWith(
"tok",
expect.objectContaining({
client: expect.objectContaining({ fetch: fetchSpy }),
}),
);
} finally {
globalThis.fetch = originalFetch;
}
});
it("sequentializes updates by chat and thread", () => {
createTelegramBot({ token: "tok" });
expect(sequentializeSpy).toHaveBeenCalledTimes(1);