mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 01:11:37 +00:00
Tests: add Telegram channel contract suite
This commit is contained in:
49
extensions/telegram/src/channel.contract.test.ts
Normal file
49
extensions/telegram/src/channel.contract.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/telegram";
|
||||
import { afterEach, describe, vi } from "vitest";
|
||||
import { installChannelActionsContractSuite } from "../../../src/test-utils/channel-actions-contract.js";
|
||||
import { installChannelPluginContractSuite } from "../../../src/test-utils/channel-plugin-contract.js";
|
||||
|
||||
const telegramListActionsMock = vi.fn();
|
||||
const telegramGetCapabilitiesMock = vi.fn();
|
||||
|
||||
vi.mock("./runtime.js", () => ({
|
||||
getTelegramRuntime: () => ({
|
||||
channel: {
|
||||
telegram: {
|
||||
messageActions: {
|
||||
listActions: telegramListActionsMock,
|
||||
getCapabilities: telegramGetCapabilitiesMock,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
const { telegramPlugin } = await import("./channel.js");
|
||||
|
||||
describe("telegramPlugin contract", () => {
|
||||
afterEach(() => {
|
||||
telegramListActionsMock.mockReset();
|
||||
telegramGetCapabilitiesMock.mockReset();
|
||||
});
|
||||
|
||||
installChannelPluginContractSuite({
|
||||
plugin: telegramPlugin,
|
||||
});
|
||||
|
||||
installChannelActionsContractSuite({
|
||||
plugin: telegramPlugin,
|
||||
cases: [
|
||||
{
|
||||
name: "forwards runtime-backed Telegram actions and capabilities",
|
||||
cfg: {} as OpenClawConfig,
|
||||
expectedActions: ["send", "poll", "react"],
|
||||
expectedCapabilities: ["interactive", "buttons"],
|
||||
beforeTest: () => {
|
||||
telegramListActionsMock.mockReturnValue(["send", "poll", "react"]);
|
||||
telegramGetCapabilitiesMock.mockReturnValue(["interactive", "buttons"]);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user