test(telegram): pass explicit deps in command tests
This commit is contained in:
parent
3bf540170a
commit
1dfeb21cb5
@ -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" },
|
||||
};
|
||||
}
|
||||
|
||||
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user