|
1 | 1 | // Discord tests cover message handler.hydration plugin behavior. |
2 | 2 | import { MessageReferenceType, MessageType } from "discord-api-types/v10"; |
3 | | -import { describe, expect, it } from "vitest"; |
| 3 | +import { describe, expect, it, vi } from "vitest"; |
4 | 4 | import { Message } from "../internal/discord.js"; |
5 | 5 | import { |
6 | 6 | createFakeRestClient, |
@@ -168,6 +168,50 @@ describe("hydrateDiscordMessageIfNeeded", () => {
|
168 | 168 | expect(hydrated.referencedMessage?.content).toBe("the replied-to message"); |
169 | 169 | }); |
170 | 170 | |
| 171 | +it("keeps the original reply message when hydration fetch fails", async () => { |
| 172 | +const client = createInternalTestClient(); |
| 173 | +const rest = createFakeRestClient(); |
| 174 | +rest.get = vi.fn(async () => { |
| 175 | +throw Object.assign(new Error("Missing Access"), { status: 403 }); |
| 176 | +}); |
| 177 | +const message = new Message(client, { |
| 178 | +id: "m1", |
| 179 | +channel_id: "c1", |
| 180 | +content: "what did this mean?", |
| 181 | +attachments: [], |
| 182 | +embeds: [], |
| 183 | +mentions: [], |
| 184 | +mention_roles: [], |
| 185 | +mention_everyone: false, |
| 186 | +timestamp: new Date().toISOString(), |
| 187 | +author: { |
| 188 | +id: "u1", |
| 189 | +username: "alice", |
| 190 | +global_name: null, |
| 191 | +discriminator: "0", |
| 192 | +avatar: null, |
| 193 | +}, |
| 194 | +message_reference: { |
| 195 | +type: MessageReferenceType.Default, |
| 196 | +message_id: "m0", |
| 197 | +channel_id: "c1", |
| 198 | +}, |
| 199 | +type: MessageType.Reply, |
| 200 | +tts: false, |
| 201 | +pinned: false, |
| 202 | +}); |
| 203 | + |
| 204 | +const hydrated = await hydrateDiscordMessageIfNeeded({ |
| 205 | +client: { rest }, |
| 206 | + message, |
| 207 | +messageChannelId: "c1", |
| 208 | +}); |
| 209 | + |
| 210 | +expect(rest.get).toHaveBeenCalledOnce(); |
| 211 | +expect(hydrated).toBe(message); |
| 212 | +expect(hydrated.referencedMessage).toBeNull(); |
| 213 | +}); |
| 214 | + |
171 | 215 | it("does not hydrate known-deleted or forwarded references", async () => { |
172 | 216 | const client = createInternalTestClient(); |
173 | 217 | const rest = createFakeRestClient(); |
|