mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:08:26 +00:00
fix: prefer config tokens over env for discord/telegram
This commit is contained in:
47
src/discord/token.test.ts
Normal file
47
src/discord/token.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { resolveDiscordToken } from "./token.js";
|
||||
|
||||
describe("resolveDiscordToken", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it("prefers config token over env", () => {
|
||||
vi.stubEnv("DISCORD_BOT_TOKEN", "env-token");
|
||||
const cfg = {
|
||||
channels: { discord: { token: "cfg-token" } },
|
||||
} as ClawdbotConfig;
|
||||
const res = resolveDiscordToken(cfg);
|
||||
expect(res.token).toBe("cfg-token");
|
||||
expect(res.source).toBe("config");
|
||||
});
|
||||
|
||||
it("uses env token when config is missing", () => {
|
||||
vi.stubEnv("DISCORD_BOT_TOKEN", "env-token");
|
||||
const cfg = {
|
||||
channels: { discord: {} },
|
||||
} as ClawdbotConfig;
|
||||
const res = resolveDiscordToken(cfg);
|
||||
expect(res.token).toBe("env-token");
|
||||
expect(res.source).toBe("env");
|
||||
});
|
||||
|
||||
it("prefers account token for non-default accounts", () => {
|
||||
vi.stubEnv("DISCORD_BOT_TOKEN", "env-token");
|
||||
const cfg = {
|
||||
channels: {
|
||||
discord: {
|
||||
token: "base-token",
|
||||
accounts: {
|
||||
work: { token: "acct-token" },
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
const res = resolveDiscordToken(cfg, { accountId: "work" });
|
||||
expect(res.token).toBe("acct-token");
|
||||
expect(res.source).toBe("config");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user