mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:31:36 +00:00
refactor: eliminate jscpd clones and boost tests
This commit is contained in:
50
src/test-utils/channel-plugins.test.ts
Normal file
50
src/test-utils/channel-plugins.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createChannelTestPluginBase, createOutboundTestPlugin } from "./channel-plugins.js";
|
||||
|
||||
describe("createChannelTestPluginBase", () => {
|
||||
it("builds a plugin base with defaults", () => {
|
||||
const cfg = {} as never;
|
||||
const base = createChannelTestPluginBase({ id: "telegram", label: "Telegram" });
|
||||
expect(base.id).toBe("telegram");
|
||||
expect(base.meta.label).toBe("Telegram");
|
||||
expect(base.meta.selectionLabel).toBe("Telegram");
|
||||
expect(base.meta.docsPath).toBe("/channels/telegram");
|
||||
expect(base.capabilities.chatTypes).toEqual(["direct"]);
|
||||
expect(base.config.listAccountIds(cfg)).toEqual(["default"]);
|
||||
expect(base.config.resolveAccount(cfg)).toEqual({});
|
||||
});
|
||||
|
||||
it("honors config and metadata overrides", async () => {
|
||||
const cfg = {} as never;
|
||||
const base = createChannelTestPluginBase({
|
||||
id: "discord",
|
||||
label: "Discord Bot",
|
||||
docsPath: "/custom/discord",
|
||||
capabilities: { chatTypes: ["group"] },
|
||||
config: {
|
||||
listAccountIds: () => ["acct-1"],
|
||||
isConfigured: async () => true,
|
||||
},
|
||||
});
|
||||
expect(base.meta.docsPath).toBe("/custom/discord");
|
||||
expect(base.capabilities.chatTypes).toEqual(["group"]);
|
||||
expect(base.config.listAccountIds(cfg)).toEqual(["acct-1"]);
|
||||
const account = base.config.resolveAccount(cfg);
|
||||
await expect(base.config.isConfigured?.(account, cfg)).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("createOutboundTestPlugin", () => {
|
||||
it("keeps outbound test plugin account list behavior", () => {
|
||||
const cfg = {} as never;
|
||||
const plugin = createOutboundTestPlugin({
|
||||
id: "signal",
|
||||
outbound: {
|
||||
deliveryMode: "direct",
|
||||
resolveTarget: () => ({ ok: true, to: "target" }),
|
||||
sendText: async () => ({ channel: "signal", messageId: "m1" }),
|
||||
},
|
||||
});
|
||||
expect(plugin.config.listAccountIds(cfg)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -28,13 +28,13 @@ export const createTestRegistry = (channels: TestChannelRegistration[] = []): Pl
|
||||
diagnostics: [],
|
||||
});
|
||||
|
||||
export const createOutboundTestPlugin = (params: {
|
||||
export const createChannelTestPluginBase = (params: {
|
||||
id: ChannelId;
|
||||
outbound: ChannelOutboundAdapter;
|
||||
label?: string;
|
||||
docsPath?: string;
|
||||
capabilities?: ChannelCapabilities;
|
||||
}): ChannelPlugin => ({
|
||||
config?: Partial<ChannelPlugin["config"]>;
|
||||
}): Pick<ChannelPlugin, "id" | "meta" | "capabilities" | "config"> => ({
|
||||
id: params.id,
|
||||
meta: {
|
||||
id: params.id,
|
||||
@@ -45,8 +45,25 @@ export const createOutboundTestPlugin = (params: {
|
||||
},
|
||||
capabilities: params.capabilities ?? { chatTypes: ["direct"] },
|
||||
config: {
|
||||
listAccountIds: () => [],
|
||||
listAccountIds: () => ["default"],
|
||||
resolveAccount: () => ({}),
|
||||
...params.config,
|
||||
},
|
||||
});
|
||||
|
||||
export const createOutboundTestPlugin = (params: {
|
||||
id: ChannelId;
|
||||
outbound: ChannelOutboundAdapter;
|
||||
label?: string;
|
||||
docsPath?: string;
|
||||
capabilities?: ChannelCapabilities;
|
||||
}): ChannelPlugin => ({
|
||||
...createChannelTestPluginBase({
|
||||
id: params.id,
|
||||
label: params.label,
|
||||
docsPath: params.docsPath,
|
||||
capabilities: params.capabilities,
|
||||
config: { listAccountIds: () => [] },
|
||||
}),
|
||||
outbound: params.outbound,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user