test(telegram): pass explicit deps in command tests

This commit is contained in:
Ayaan Zaidi 2026-03-18 10:09:08 +05:30
parent b9dfb6cc23
commit 1ef7e544e9
No known key found for this signature in database
3 changed files with 39 additions and 1 deletions

View File

@ -56,6 +56,7 @@ export function createNativeCommandTestParams(
params.resolveTelegramGroupConfig ??
((_chatId, _messageThreadId) => ({ groupConfig: undefined, topicConfig: undefined })),
shouldSkipUpdate: params.shouldSkipUpdate ?? (() => false),
telegramDeps: params.telegramDeps,
opts: params.opts ?? { token: "token" },
};
}

View File

@ -1,6 +1,7 @@
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
import type { OpenClawConfig } from "openclaw/plugin-sdk/telegram";
import { expect, vi } from "vitest";
import type { TelegramBotDeps } from "./bot-deps.js";
import {
createNativeCommandTestParams as createBaseNativeCommandTestParams,
createTelegramPrivateCommandContext,
@ -78,10 +79,23 @@ export function createNativeCommandTestParams(
cfg: OpenClawConfig,
params: Partial<RegisterTelegramNativeCommandsParams> = {},
): RegisterTelegramNativeCommandsParams {
const telegramDeps: TelegramBotDeps = {
loadConfig: vi.fn(() => ({})),
resolveStorePath: vi.fn((storePath?: string) => storePath ?? "/tmp/sessions.json"),
readChannelAllowFromStore: vi.fn(async () => []),
enqueueSystemEvent: vi.fn(),
dispatchReplyWithBufferedBlockDispatcher: vi.fn(async () => ({
queuedFinal: false,
counts: {},
})),
listSkillCommandsForAgents,
wasSentByBot: vi.fn(() => false),
};
return createBaseNativeCommandTestParams({
cfg,
runtime: params.runtime ?? ({} as RuntimeEnv),
nativeSkillsEnabled: true,
telegramDeps,
...params,
});
}

View File

@ -9,6 +9,7 @@ import {
pluginCommandMocks,
resetPluginCommandMocks,
} from "../../../test/helpers/extensions/telegram-plugin-command.js";
import type { TelegramBotDeps } from "./bot-deps.js";
const skillCommandMocks = vi.hoisted(() => ({
listSkillCommandsForAgents: vi.fn(() => []),
}));
@ -31,11 +32,33 @@ vi.mock("./bot/delivery.js", () => ({
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
import {
createCommandBot,
createNativeCommandTestParams,
createNativeCommandTestParams as createNativeCommandTestParamsBase,
createPrivateCommandContext,
waitForRegisteredCommands,
} from "./bot-native-commands.menu-test-support.js";
function createNativeCommandTestParams(
cfg: OpenClawConfig,
params: Partial<Parameters<typeof registerTelegramNativeCommands>[0]> = {},
) {
const telegramDeps: TelegramBotDeps = {
loadConfig: vi.fn(() => ({})),
resolveStorePath: vi.fn((storePath?: string) => storePath ?? "/tmp/sessions.json"),
readChannelAllowFromStore: vi.fn(async () => []),
enqueueSystemEvent: vi.fn(),
dispatchReplyWithBufferedBlockDispatcher: vi.fn(async () => ({
queuedFinal: false,
counts: {},
})),
listSkillCommandsForAgents: skillCommandMocks.listSkillCommandsForAgents,
wasSentByBot: vi.fn(() => false),
};
return createNativeCommandTestParamsBase(cfg, {
telegramDeps,
...params,
});
}
describe("registerTelegramNativeCommands", () => {
beforeEach(() => {
skillCommandMocks.listSkillCommandsForAgents.mockClear();