mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 06:20:55 +00:00
* 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
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { ChannelType } from "discord-api-types/v10";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { registerDiscordComponentEntries } from "./components-registry.js";
|
|
import { sendDiscordComponentMessage } from "./send.components.js";
|
|
import { makeDiscordRest } from "./send.test-harness.js";
|
|
|
|
const loadConfigMock = vi.hoisted(() => vi.fn(() => ({ session: { dmScope: "main" } })));
|
|
|
|
vi.mock("../../../src/config/config.js", async () => {
|
|
const actual = await vi.importActual<typeof import("../../../src/config/config.js")>(
|
|
"../../../src/config/config.js",
|
|
);
|
|
return {
|
|
...actual,
|
|
loadConfig: (..._args: unknown[]) => loadConfigMock(),
|
|
};
|
|
});
|
|
|
|
vi.mock("./components-registry.js", () => ({
|
|
registerDiscordComponentEntries: vi.fn(),
|
|
}));
|
|
|
|
describe("sendDiscordComponentMessage", () => {
|
|
const registerMock = vi.mocked(registerDiscordComponentEntries);
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("keeps direct-channel DM session keys on component entries", async () => {
|
|
const { rest, postMock, getMock } = makeDiscordRest();
|
|
getMock.mockResolvedValueOnce({
|
|
type: ChannelType.DM,
|
|
recipients: [{ id: "user-1" }],
|
|
});
|
|
postMock.mockResolvedValueOnce({ id: "msg1", channel_id: "dm-1" });
|
|
|
|
await sendDiscordComponentMessage(
|
|
"channel:dm-1",
|
|
{
|
|
blocks: [{ type: "actions", buttons: [{ label: "Tap" }] }],
|
|
},
|
|
{
|
|
rest,
|
|
token: "t",
|
|
sessionKey: "agent:main:discord:channel:dm-1",
|
|
agentId: "main",
|
|
},
|
|
);
|
|
|
|
expect(registerMock).toHaveBeenCalledTimes(1);
|
|
const args = registerMock.mock.calls[0]?.[0];
|
|
expect(args?.entries[0]?.sessionKey).toBe("agent:main:discord:channel:dm-1");
|
|
});
|
|
});
|