Type send.test.ts mocks against SendBotApi

This commit is contained in:
EugeneTes
2026-09-08 12:05:09 +00:00
parent c30fccb6d5
commit a6612edc1d

View File

@@ -1,18 +1,21 @@
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from "vitest";
import { InputFile } from "grammy";
import { createSendTool, handleSend, type SendBotApi } from "./send.js";
describe("send tool", () => {
let dir: string;
let bot: { sendPhoto: ReturnType<typeof vi.fn>; sendDocument: ReturnType<typeof vi.fn> };
let bot: { sendPhoto: Mock<SendBotApi["sendPhoto"]>; sendDocument: Mock<SendBotApi["sendDocument"]> };
let opts: { bot: SendBotApi; chatId: number; workspaceDir: string };
beforeEach(async () => {
dir = await mkdtemp(path.join(os.tmpdir(), "secretary-send-"));
bot = { sendPhoto: vi.fn().mockResolvedValue({}), sendDocument: vi.fn().mockResolvedValue({}) };
bot = {
sendPhoto: vi.fn<SendBotApi["sendPhoto"]>().mockResolvedValue({}),
sendDocument: vi.fn<SendBotApi["sendDocument"]>().mockResolvedValue({}),
};
opts = { bot, chatId: 42, workspaceDir: dir };
});
afterEach(async () => {