Files
openclaw/extensions/discord/src/send.webhook-activity.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

70 lines
1.9 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { sendWebhookMessageDiscord } from "./send.js";
const recordChannelActivityMock = vi.hoisted(() => vi.fn());
const loadConfigMock = vi.hoisted(() => vi.fn(() => ({ channels: { discord: {} } })));
vi.mock("../../../src/config/config.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../../src/config/config.js")>();
return {
...actual,
loadConfig: () => loadConfigMock(),
};
});
vi.mock("../../../src/infra/channel-activity.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../../src/infra/channel-activity.js")>();
return {
...actual,
recordChannelActivity: (...args: unknown[]) => recordChannelActivityMock(...args),
};
});
describe("sendWebhookMessageDiscord activity", () => {
beforeEach(() => {
recordChannelActivityMock.mockClear();
loadConfigMock.mockClear();
vi.stubGlobal(
"fetch",
vi.fn(async () => {
return new Response(JSON.stringify({ id: "msg-1", channel_id: "thread-1" }), {
status: 200,
headers: { "content-type": "application/json" },
});
}),
);
});
afterEach(() => {
vi.unstubAllGlobals();
});
it("records outbound channel activity for webhook sends", async () => {
const cfg = {
channels: {
discord: {
token: "resolved-token",
},
},
};
const result = await sendWebhookMessageDiscord("hello world", {
cfg,
webhookId: "wh-1",
webhookToken: "tok-1",
accountId: "runtime",
threadId: "thread-1",
});
expect(result).toEqual({
messageId: "msg-1",
channelId: "thread-1",
});
expect(recordChannelActivityMock).toHaveBeenCalledWith({
channel: "discord",
accountId: "runtime",
direction: "outbound",
});
expect(loadConfigMock).not.toHaveBeenCalled();
});
});