|
1 | 1 | // Discord tests cover threading.starter plugin behavior. |
2 | 2 | import { StickerFormatType } from "discord-api-types/v10"; |
3 | | -import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | +import { describe, expect, it, vi } from "vitest"; |
4 | 4 | import { ChannelType, type Client } from "../internal/discord.js"; |
5 | | -import { resetDiscordThreadStarterCacheForTest, resolveDiscordThreadStarter } from "./threading.js"; |
| 5 | +import { resolveDiscordThreadStarter } from "./threading.js"; |
6 | 6 |
|
7 | 7 | type ResolvedThreadStarter = NonNullable<Awaited<ReturnType<typeof resolveDiscordThreadStarter>>>; |
| 8 | +let threadIdIndex = 0; |
8 | 9 |
|
9 | 10 | type ThreadStarterRestMessage = { |
10 | 11 | content?: string | null; |
@@ -92,23 +93,20 @@ async function resolveStarter(params: { |
92 | 93 | }) { |
93 | 94 | const get = vi.fn().mockResolvedValue(params.message); |
94 | 95 | const client = { rest: { get } } as unknown as Client; |
| 96 | + const threadId = `thread-${++threadIdIndex}`; |
95 | 97 |
|
96 | 98 | const result = await resolveDiscordThreadStarter({ |
97 | | - channel: { id: "thread-1" }, |
| 99 | + channel: { id: threadId }, |
98 | 100 | client, |
99 | 101 | parentId: params.parentId ?? "parent-1", |
100 | 102 | parentType: params.parentType ?? ChannelType.GuildText, |
101 | 103 | resolveTimestampMs: params.resolveTimestampMs ?? (() => undefined), |
102 | 104 | }); |
103 | 105 |
|
104 | | - return { get, result }; |
| 106 | + return { get, result, threadId }; |
105 | 107 | } |
106 | 108 |
|
107 | 109 | describe("resolveDiscordThreadStarter", () => { |
108 | | - beforeEach(() => { |
109 | | - resetDiscordThreadStarterCacheForTest(); |
110 | | - }); |
111 | | - |
112 | 110 | it("falls back to joined embed title and description when content is empty", async () => { |
113 | 111 | const { result } = await resolveStarter({ |
114 | 112 | message: createStarterMessage({ |
@@ -277,15 +275,15 @@ describe("resolveDiscordThreadStarter", () => { |
277 | 275 | }); |
278 | 276 |
|
279 | 277 | it("uses the thread id as the message channel id for forum parents", async () => { |
280 | | - const { get, result } = await resolveStarter({ |
| 278 | + const { get, result, threadId } = await resolveStarter({ |
281 | 279 | message: createStarterMessage({ content: "starter content" }), |
282 | 280 | parentId: undefined, |
283 | 281 | parentType: ChannelType.GuildForum, |
284 | 282 | }); |
285 | 283 |
|
286 | 284 | expect(requireThreadStarter(result).text).toBe("starter content"); |
287 | 285 | expect(get).toHaveBeenCalledTimes(1); |
288 | | - expect(firstRestGetPath(get)).toBe("/channels/thread-1/messages/thread-1"); |
| 286 | + expect(firstRestGetPath(get)).toBe(`/channels/${threadId}/messages/${threadId}`); |
289 | 287 | }); |
290 | 288 |
|
291 | 289 | it("returns null when content, embeds, and snapshots are all empty", async () => { |
|
0 commit comments