test: stabilize infra tests

This commit is contained in:
Sebastian
2026-02-16 22:37:34 -05:00
parent 759c7fc18e
commit f7d2e15a2e
5 changed files with 37 additions and 18 deletions

View File

@@ -1,20 +1,23 @@
import { describe, expect, it, vi } from "vitest";
import { startTelegramWebhook } from "./webhook.js";
const handlerSpy = vi.fn(
(_req: unknown, res: { writeHead: (status: number) => void; end: (body?: string) => void }) => {
res.writeHead(200);
res.end("ok");
},
const handlerSpy = vi.hoisted(() =>
vi.fn(
(_req: unknown, res: { writeHead: (status: number) => void; end: (body?: string) => void }) => {
res.writeHead(200);
res.end("ok");
},
),
);
const setWebhookSpy = vi.hoisted(() => vi.fn());
const stopSpy = vi.hoisted(() => vi.fn());
const webhookCallbackSpy = vi.hoisted(() => vi.fn(() => handlerSpy));
const createTelegramBotSpy = vi.hoisted(() =>
vi.fn(() => ({
api: { setWebhook: setWebhookSpy },
stop: stopSpy,
})),
);
const setWebhookSpy = vi.fn();
const stopSpy = vi.fn();
const webhookCallbackSpy = vi.fn(() => handlerSpy);
const createTelegramBotSpy = vi.fn(() => ({
api: { setWebhook: setWebhookSpy },
stop: stopSpy,
}));
vi.mock("grammy", async (importOriginal) => {
const actual = await importOriginal<typeof import("grammy")>();