refactor(test): share telegram send test setup

This commit is contained in:
Peter Steinberger
2026-02-14 21:08:29 +00:00
parent 96f80d6d82
commit 3c043f5d2d
4 changed files with 95 additions and 157 deletions

View File

@@ -1,59 +1,16 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { describe, expect, it, vi } from "vitest";
import {
getTelegramSendTestMocks,
importTelegramSendModule,
installTelegramSendTestHooks,
} from "./send.test-harness.js";
const { botApi, botCtorSpy } = vi.hoisted(() => ({
botApi: {
sendMessage: vi.fn(),
sendPhoto: vi.fn(),
},
botCtorSpy: vi.fn(),
}));
installTelegramSendTestHooks();
const { loadWebMedia } = vi.hoisted(() => ({
loadWebMedia: vi.fn(),
}));
vi.mock("../web/media.js", () => ({
loadWebMedia,
}));
vi.mock("grammy", () => ({
Bot: class {
api = botApi;
catch = vi.fn();
constructor(
public token: string,
public options?: {
client?: { fetch?: typeof fetch; timeoutSeconds?: number };
},
) {
botCtorSpy(token, options);
}
},
InputFile: class {},
}));
const { loadConfig } = vi.hoisted(() => ({
loadConfig: vi.fn(() => ({})),
}));
vi.mock("../config/config.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../config/config.js")>();
return {
...actual,
loadConfig,
};
});
import { sendMessageTelegram } from "./send.js";
const { loadWebMedia } = getTelegramSendTestMocks();
const { sendMessageTelegram } = await importTelegramSendModule();
describe("sendMessageTelegram caption splitting", () => {
beforeEach(() => {
loadConfig.mockReturnValue({});
loadWebMedia.mockReset();
botApi.sendMessage.mockReset();
botApi.sendPhoto.mockReset();
botCtorSpy.mockReset();
});
it("splits long captions into media + text messages when text exceeds 1024 chars", async () => {
const chatId = "123";
// Generate text longer than 1024 characters