fix(discord): surface failed bulk reaction removals instead of false success (#90038)

This commit is contained in:
Masato Hoshino
2026-07-06 16:21:53 +01:00
committed by GitHub
parent 919811cf85
commit a327cec143
2 changed files with 25 additions and 11 deletions
+7 -11
View File
@@ -87,17 +87,13 @@ export async function removeOwnReactionsDiscord(
if (identifiers.size === 0) {
return { ok: true, removed: [] };
}
const removed: string[] = [];
await Promise.allSettled(
Array.from(identifiers, (identifier) => {
removed.push(identifier);
return deleteOwnMessageReaction(
rest,
channelId,
messageId,
normalizeReactionEmoji(identifier),
);
}),
const removed = Array.from(identifiers);
// Promise.all so a rejected delete propagates: allSettled would swallow the
// failure and falsely report every identifier as removed.
await Promise.all(
removed.map((identifier) =>
deleteOwnMessageReaction(rest, channelId, messageId, normalizeReactionEmoji(identifier)),
),
);
return { ok: true, removed };
}
@@ -861,6 +861,24 @@ describe("removeOwnReactionsDiscord", () => {
Routes.channelMessageOwnReaction("chan1", "msg1", "party_blob%3A123"),
);
});
it("surfaces a failed deletion instead of reporting false success", async () => {
const { rest, getMock, deleteMock } = makeDiscordRest();
getMock.mockResolvedValue({
reactions: [
{ emoji: { name: "✅", id: null } },
{ emoji: { name: "party_blob", id: "123" } },
],
});
const apiError = new Error("Discord API 500");
deleteMock.mockResolvedValueOnce(undefined);
deleteMock.mockRejectedValueOnce(apiError);
await expect(
removeOwnReactionsDiscord("chan1", "msg1", { rest, token: "t", cfg: DISCORD_TEST_CFG }),
).rejects.toThrow("Discord API 500");
// Both deletions are still attempted; the rejection just propagates.
expect(deleteMock).toHaveBeenCalledTimes(2);
});
});
describe("fetchReactionsDiscord", () => {