mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { ChannelType } from "@buape/carbon";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { maybeCreateDiscordAutoThread } from "./threading.js";
|
|
|
|
describe("maybeCreateDiscordAutoThread", () => {
|
|
const postMock = vi.fn();
|
|
const getMock = vi.fn();
|
|
const mockClient = {
|
|
rest: { post: postMock, get: getMock },
|
|
} as unknown as Parameters<typeof maybeCreateDiscordAutoThread>[0]["client"];
|
|
const mockMessage = {
|
|
id: "msg1",
|
|
timestamp: "123",
|
|
} as unknown as Parameters<typeof maybeCreateDiscordAutoThread>[0]["message"];
|
|
|
|
it("skips auto-thread if channelType is GuildForum", async () => {
|
|
const result = await maybeCreateDiscordAutoThread({
|
|
client: mockClient,
|
|
message: mockMessage,
|
|
messageChannelId: "forum1",
|
|
isGuildMessage: true,
|
|
channelConfig: { autoThread: true },
|
|
channelType: ChannelType.GuildForum,
|
|
baseText: "test",
|
|
combinedBody: "test",
|
|
});
|
|
expect(result).toBeUndefined();
|
|
expect(postMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("skips auto-thread if channelType is GuildMedia", async () => {
|
|
const result = await maybeCreateDiscordAutoThread({
|
|
client: mockClient,
|
|
message: mockMessage,
|
|
messageChannelId: "media1",
|
|
isGuildMessage: true,
|
|
channelConfig: { autoThread: true },
|
|
channelType: ChannelType.GuildMedia,
|
|
baseText: "test",
|
|
combinedBody: "test",
|
|
});
|
|
expect(result).toBeUndefined();
|
|
expect(postMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("creates auto-thread if channelType is GuildText", async () => {
|
|
postMock.mockResolvedValueOnce({ id: "thread1" });
|
|
const result = await maybeCreateDiscordAutoThread({
|
|
client: mockClient,
|
|
message: mockMessage,
|
|
messageChannelId: "text1",
|
|
isGuildMessage: true,
|
|
channelConfig: { autoThread: true },
|
|
channelType: ChannelType.GuildText,
|
|
baseText: "test",
|
|
combinedBody: "test",
|
|
});
|
|
expect(result).toBe("thread1");
|
|
expect(postMock).toHaveBeenCalled();
|
|
});
|
|
});
|