openclaw/extensions/discord/src/monitor/threading.parent-info.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

112 lines
3.1 KiB
TypeScript

import { ChannelType } from "@buape/carbon";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { __resetDiscordChannelInfoCacheForTest } from "./message-utils.js";
import { resolveDiscordThreadParentInfo } from "./threading.js";
describe("resolveDiscordThreadParentInfo", () => {
beforeEach(() => {
__resetDiscordChannelInfoCacheForTest();
});
it("falls back to fetched thread parentId when parentId is missing in payload", async () => {
const fetchChannel = vi.fn(async (channelId: string) => {
if (channelId === "thread-1") {
return {
id: "thread-1",
type: ChannelType.PublicThread,
name: "thread-name",
parentId: "parent-1",
};
}
if (channelId === "parent-1") {
return {
id: "parent-1",
type: ChannelType.GuildText,
name: "parent-name",
};
}
return null;
});
const client = {
fetchChannel,
} as unknown as import("@buape/carbon").Client;
const result = await resolveDiscordThreadParentInfo({
client,
threadChannel: {
id: "thread-1",
parentId: undefined,
},
channelInfo: null,
});
expect(fetchChannel).toHaveBeenCalledWith("thread-1");
expect(fetchChannel).toHaveBeenCalledWith("parent-1");
expect(result).toEqual({
id: "parent-1",
name: "parent-name",
type: ChannelType.GuildText,
});
});
it("does not fetch thread info when parentId is already present", async () => {
const fetchChannel = vi.fn(async (channelId: string) => {
if (channelId === "parent-1") {
return {
id: "parent-1",
type: ChannelType.GuildText,
name: "parent-name",
};
}
return null;
});
const client = { fetchChannel } as unknown as import("@buape/carbon").Client;
const result = await resolveDiscordThreadParentInfo({
client,
threadChannel: {
id: "thread-1",
parentId: "parent-1",
},
channelInfo: null,
});
expect(fetchChannel).toHaveBeenCalledTimes(1);
expect(fetchChannel).toHaveBeenCalledWith("parent-1");
expect(result).toEqual({
id: "parent-1",
name: "parent-name",
type: ChannelType.GuildText,
});
});
it("returns empty parent info when fallback thread lookup has no parentId", async () => {
const fetchChannel = vi.fn(async (channelId: string) => {
if (channelId === "thread-1") {
return {
id: "thread-1",
type: ChannelType.PublicThread,
name: "thread-name",
parentId: undefined,
};
}
return null;
});
const client = { fetchChannel } as unknown as import("@buape/carbon").Client;
const result = await resolveDiscordThreadParentInfo({
client,
threadChannel: {
id: "thread-1",
parentId: undefined,
},
channelInfo: null,
});
expect(fetchChannel).toHaveBeenCalledTimes(1);
expect(fetchChannel).toHaveBeenCalledWith("thread-1");
expect(result).toEqual({});
});
});