Files
openclaw/extensions/discord/src/client.test.ts
scoootscooob 5682ec37fa refactor: move Discord channel implementation to extensions/ (#45660)
* refactor: move Discord channel implementation to extensions/discord/src/

Move all Discord source files from src/discord/ to extensions/discord/src/,
following the extension migration pattern. Source files in src/discord/ are
replaced with re-export shims. Channel-plugin files from
src/channels/plugins/*/discord* are similarly moved and shimmed.

- Copy all .ts source files preserving subdirectory structure (monitor/, voice/)
- Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues)
- Fix all relative imports to use correct paths from new location
- Create re-export shims at original locations for backward compatibility
- Delete test files from shim locations (tests live in extension now)
- Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate
  extension files outside src/
- Update write-plugin-sdk-entry-dts.ts to match new declaration output paths

* fix: add importOriginal to thread-bindings session-meta mock for extensions test

* style: fix formatting in thread-bindings lifecycle test
2026-03-14 02:53:57 -07:00

92 lines
2.2 KiB
TypeScript

import type { RequestClient } from "@buape/carbon";
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../../src/config/config.js";
import { createDiscordRestClient } from "./client.js";
describe("createDiscordRestClient", () => {
const fakeRest = {} as RequestClient;
it("uses explicit token without resolving config token SecretRefs", () => {
const cfg = {
channels: {
discord: {
token: {
source: "exec",
provider: "vault",
id: "discord/bot-token",
},
},
},
} as OpenClawConfig;
const result = createDiscordRestClient(
{
token: "Bot explicit-token",
rest: fakeRest,
},
cfg,
);
expect(result.token).toBe("explicit-token");
expect(result.rest).toBe(fakeRest);
expect(result.account.accountId).toBe("default");
});
it("keeps account retry config when explicit token is provided", () => {
const cfg = {
channels: {
discord: {
accounts: {
ops: {
token: {
source: "exec",
provider: "vault",
id: "discord/ops-token",
},
retry: {
attempts: 7,
},
},
},
},
},
} as OpenClawConfig;
const result = createDiscordRestClient(
{
accountId: "ops",
token: "Bot explicit-account-token",
rest: fakeRest,
},
cfg,
);
expect(result.token).toBe("explicit-account-token");
expect(result.account.accountId).toBe("ops");
expect(result.account.config.retry).toMatchObject({ attempts: 7 });
});
it("still throws when no explicit token is provided and config token is unresolved", () => {
const cfg = {
channels: {
discord: {
token: {
source: "file",
provider: "default",
id: "/discord/token",
},
},
},
} as OpenClawConfig;
expect(() =>
createDiscordRestClient(
{
rest: fakeRest,
},
cfg,
),
).toThrow(/unresolved SecretRef/i);
});
});