Files
openclaw/src/channels/plugins/configured-state.test.ts
T
2026-05-02 01:06:38 +01:00

66 lines
1.8 KiB
TypeScript

import { createRequire } from "node:module";
import { describe, expect, it } from "vitest";
import {
hasBundledChannelConfiguredState,
listBundledChannelIdsWithConfiguredState,
} from "./configured-state.js";
const nodeRequire = createRequire(import.meta.url);
describe("bundled channel configured-state metadata", () => {
it("lists the shipped metadata-first configured-state channels", () => {
expect(listBundledChannelIdsWithConfiguredState()).toEqual(
expect.arrayContaining(["discord", "irc", "slack", "telegram"]),
);
});
it("resolves Discord, Slack, Telegram, and IRC env probes without full plugin loads", () => {
expect(
hasBundledChannelConfiguredState({
channelId: "discord",
cfg: {},
env: { DISCORD_BOT_TOKEN: "token" },
}),
).toBe(true);
expect(
hasBundledChannelConfiguredState({
channelId: "slack",
cfg: {},
env: { SLACK_BOT_TOKEN: "xoxb-test" },
}),
).toBe(true);
expect(
hasBundledChannelConfiguredState({
channelId: "telegram",
cfg: {},
env: { TELEGRAM_BOT_TOKEN: "token" },
}),
).toBe(true);
expect(
hasBundledChannelConfiguredState({
channelId: "irc",
cfg: {},
env: { IRC_HOST: "irc.example.com", IRC_NICK: "openclaw" },
}),
).toBe(true);
});
it("uses declarative env metadata without a TypeScript source require hook", () => {
const previousTsHook = nodeRequire.extensions[".ts"];
delete nodeRequire.extensions[".ts"];
try {
expect(
hasBundledChannelConfiguredState({
channelId: "discord",
cfg: {},
env: { DISCORD_BOT_TOKEN: "token" },
}),
).toBe(true);
} finally {
if (previousTsHook) {
nodeRequire.extensions[".ts"] = previousTsHook;
}
}
});
});