mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: mock channel configured state seams
This commit is contained in:
@@ -1,9 +1,44 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { withTempDirSync } from "../test-helpers/temp-dir.js";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { isChannelConfigured } from "./channel-configured.js";
|
||||
|
||||
vi.mock("../channels/plugins/configured-state.js", () => ({
|
||||
hasBundledChannelConfiguredState: ({
|
||||
channelId,
|
||||
env,
|
||||
}: {
|
||||
channelId: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}) => {
|
||||
if (channelId === "telegram") {
|
||||
return Boolean(env?.TELEGRAM_BOT_TOKEN);
|
||||
}
|
||||
if (channelId === "discord") {
|
||||
return Boolean(env?.DISCORD_BOT_TOKEN);
|
||||
}
|
||||
if (channelId === "slack") {
|
||||
return Boolean(env?.SLACK_BOT_TOKEN);
|
||||
}
|
||||
if (channelId === "irc") {
|
||||
return Boolean(env?.IRC_HOST && env?.IRC_NICK);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../channels/plugins/persisted-auth-state.js", () => ({
|
||||
hasBundledChannelPersistedAuthState: ({
|
||||
channelId,
|
||||
env,
|
||||
}: {
|
||||
channelId: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}) => channelId === "matrix" && env?.OPENCLAW_STATE_DIR === "state-with-matrix-creds",
|
||||
}));
|
||||
|
||||
vi.mock("../channels/plugins/bootstrap-registry.js", () => ({
|
||||
getBootstrapChannelPlugin: () => undefined,
|
||||
}));
|
||||
|
||||
describe("isChannelConfigured", () => {
|
||||
it("detects Telegram env configuration through the package metadata seam", () => {
|
||||
expect(isChannelConfigured({}, "telegram", { TELEGRAM_BOT_TOKEN: "token" })).toBe(true);
|
||||
@@ -44,19 +79,8 @@ describe("isChannelConfigured", () => {
|
||||
});
|
||||
|
||||
it("detects persisted Matrix credentials through package metadata", () => {
|
||||
withTempDirSync({ prefix: "openclaw-channel-configured-" }, (stateDir) => {
|
||||
fs.mkdirSync(path.join(stateDir, "credentials", "matrix"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(stateDir, "credentials", "matrix", "credentials-ops.json"),
|
||||
JSON.stringify({
|
||||
homeserver: "https://matrix.example.org",
|
||||
userId: "@ops:example.org",
|
||||
accessToken: "token",
|
||||
}),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
expect(isChannelConfigured({}, "matrix", { OPENCLAW_STATE_DIR: stateDir })).toBe(true);
|
||||
});
|
||||
expect(
|
||||
isChannelConfigured({}, "matrix", { OPENCLAW_STATE_DIR: "state-with-matrix-creds" }),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user