





























@@ -1,15 +1,29 @@
11import type { WebClient } from "@slack/web-api";
22import { describe, expect, it, vi } from "vitest";
3-import { reactSlackMessage } from "./actions.js";
3+import { reactSlackMessage, removeOwnSlackReactions, removeSlackReaction } from "./actions.js";
4455function createClient() {
66return {
7+auth: {
8+test: vi.fn(async () => ({ user_id: "UBOT" })),
9+},
710reactions: {
811add: vi.fn(async () => ({})),
12+get: vi.fn(async () => ({
13+message: {
14+reactions: [],
15+},
16+})),
17+remove: vi.fn(async () => ({})),
918},
1019} as unknown as WebClient & {
20+auth: {
21+test: ReturnType<typeof vi.fn>;
22+};
1123reactions: {
1224add: ReturnType<typeof vi.fn>;
25+get: ReturnType<typeof vi.fn>;
26+remove: ReturnType<typeof vi.fn>;
1327};
1428};
1529}
@@ -58,3 +72,76 @@ describe("reactSlackMessage", () => {
5872});
5973});
6074});
75+76+describe("removeSlackReaction", () => {
77+it("treats no_reaction as idempotent success", async () => {
78+const client = createClient();
79+client.reactions.remove.mockRejectedValueOnce(slackPlatformError("no_reaction"));
80+81+await expect(
82+removeSlackReaction("C1", "123.456", ":white_check_mark:", {
83+ client,
84+token: "xoxb-test",
85+}),
86+).resolves.toBeUndefined();
87+88+expect(client.reactions.remove).toHaveBeenCalledWith({
89+channel: "C1",
90+timestamp: "123.456",
91+name: "white_check_mark",
92+});
93+});
94+95+it("propagates unrelated reaction remove errors", async () => {
96+const client = createClient();
97+client.reactions.remove.mockRejectedValueOnce(slackPlatformError("invalid_name"));
98+99+await expect(
100+removeSlackReaction("C1", "123.456", "not-an-emoji", {
101+ client,
102+token: "xoxb-test",
103+}),
104+).rejects.toMatchObject({
105+data: {
106+error: "invalid_name",
107+},
108+});
109+});
110+});
111+112+describe("removeOwnSlackReactions", () => {
113+it("removes own reactions through the idempotent remove helper", async () => {
114+const client = createClient();
115+client.reactions.get.mockResolvedValueOnce({
116+message: {
117+reactions: [
118+{ name: "thumbsup", users: ["UBOT", "U1"] },
119+{ name: "eyes", users: ["U2", "UBOT"] },
120+{ name: "wave", users: ["U2"] },
121+],
122+},
123+});
124+client.reactions.remove
125+.mockRejectedValueOnce(slackPlatformError("no_reaction"))
126+.mockResolvedValueOnce({});
127+128+await expect(
129+removeOwnSlackReactions("C1", "123.456", {
130+ client,
131+token: "xoxb-test",
132+}),
133+).resolves.toEqual(["thumbsup", "eyes"]);
134+135+expect(client.reactions.remove).toHaveBeenCalledTimes(2);
136+expect(client.reactions.remove).toHaveBeenNthCalledWith(1, {
137+channel: "C1",
138+timestamp: "123.456",
139+name: "thumbsup",
140+});
141+expect(client.reactions.remove).toHaveBeenNthCalledWith(2, {
142+channel: "C1",
143+timestamp: "123.456",
144+name: "eyes",
145+});
146+});
147+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。