mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-23 07:01:40 +00:00
fix: extend discord thread parent fallback coverage (#24897) (thanks @z-x-yang)
This commit is contained in:
@@ -44,4 +44,63 @@ describe("resolveDiscordThreadParentInfo", () => {
|
||||
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({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user