chore: Fix types in tests 17/N.

This commit is contained in:
cpojer
2026-02-17 11:59:41 +09:00
parent 7bc783cb03
commit 43c97d18aa
6 changed files with 66 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
import type { Bot } from "grammy";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { RuntimeEnv } from "../../runtime.js";
import { deliverReplies } from "./delivery.js";
const loadWebMedia = vi.fn();
@@ -10,7 +11,12 @@ const baseDeliveryParams = {
textLimit: 4000,
} as const;
type DeliverRepliesParams = Parameters<typeof deliverReplies>[0];
type RuntimeStub = { error: ReturnType<typeof vi.fn>; log?: ReturnType<typeof vi.fn> };
type DeliverWithParams = Omit<
DeliverRepliesParams,
"chatId" | "token" | "replyToMode" | "textLimit"
> &
Partial<Pick<DeliverRepliesParams, "replyToMode" | "textLimit">>;
type RuntimeStub = Pick<RuntimeEnv, "error" | "log" | "exit">;
vi.mock("../../web/media.js", () => ({
loadWebMedia: (...args: unknown[]) => loadWebMedia(...args),
@@ -29,14 +35,18 @@ vi.mock("grammy", () => ({
}));
function createRuntime(withLog = true): RuntimeStub {
return withLog ? { error: vi.fn(), log: vi.fn() } : { error: vi.fn() };
return {
error: vi.fn(),
log: withLog ? vi.fn() : vi.fn(),
exit: vi.fn(),
};
}
function createBot(api: Record<string, unknown> = {}): Bot {
return { api } as unknown as Bot;
}
async function deliverWith(params: Omit<DeliverRepliesParams, "chatId" | "token">) {
async function deliverWith(params: DeliverWithParams) {
await deliverReplies({
...baseDeliveryParams,
...params,