Skip to content

Commit 24d18de

Browse files
committed
Clean up starboard: remove unused parameter and extract shared test helpers
1 parent 83a560d commit 24d18de

5 files changed

Lines changed: 61 additions & 75 deletions

File tree

src/modules/starboard/starboard.listener.test.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
11
import { describe, expect, test } from "bun:test";
2-
import type { Message } from "discord.js";
32
import {
43
getReactionCountForEmoji,
54
getThresholdReactionCount,
65
matchesConfiguredEmoji,
76
} from "./starboard.reaction-utils.js";
8-
9-
interface ReactionStub {
10-
emoji: {
11-
name: string | null;
12-
id: string | null;
13-
};
14-
count: number | null;
15-
}
16-
17-
const createMessageWithReactions = (reactions: ReactionStub[]): Message => {
18-
return {
19-
reactions: {
20-
cache: {
21-
find: (
22-
predicate: (reaction: ReactionStub) => boolean,
23-
): ReactionStub | undefined => reactions.find(predicate),
24-
},
25-
},
26-
} as unknown as Message;
27-
};
7+
import { createMessageWithReactions } from "./starboard.test-utils.js";
288

299
describe("matchesConfiguredEmoji", () => {
3010
test("matches unicode emoji with and without variation selector", () => {

src/modules/starboard/starboard.listener.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ export const StarboardListener: EventListener = {
305305
message,
306306
member,
307307
effectiveStarCount,
308-
undefined,
309308
board.config,
310309
contentStarCount,
311310
);
@@ -439,7 +438,6 @@ export const StarboardListener: EventListener = {
439438
refreshedMessage,
440439
member,
441440
displayCount,
442-
undefined,
443441
board.config,
444442
contentCount,
445443
);
@@ -641,7 +639,6 @@ async function updateBoardMessage(
641639
reactionMessage,
642640
member,
643641
starCount,
644-
undefined,
645642
board.config,
646643
contentStarCount,
647644
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { Message } from "discord.js";
2+
3+
export interface ReactionStub {
4+
emoji: {
5+
name: string | null;
6+
id: string | null;
7+
};
8+
count: number | null;
9+
}
10+
11+
const buildReactionsCache = (reactions: ReactionStub[]) => ({
12+
cache: {
13+
find: (
14+
predicate: (reaction: ReactionStub) => boolean,
15+
): ReactionStub | undefined => reactions.find(predicate),
16+
},
17+
});
18+
19+
export const createMessageWithReactions = (
20+
reactions: ReactionStub[],
21+
): Message => {
22+
return {
23+
reactions: buildReactionsCache(reactions),
24+
} as unknown as Message;
25+
};
26+
27+
export const createMessageWithUrlAndReactions = (
28+
url: string,
29+
reactions: ReactionStub[],
30+
): Pick<Message, "url" | "reactions"> => {
31+
return {
32+
url,
33+
reactions: buildReactionsCache(reactions),
34+
} as Pick<Message, "url" | "reactions">;
35+
};

src/modules/starboard/starboard.test.ts

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
11
import { describe, expect, test } from "bun:test";
2-
import type { Message } from "discord.js";
32
import { config } from "../../Config.js";
43
import {
54
buildStarboardMessageContent,
65
type StarboardContentRenderOptions,
76
} from "./starboard.content.js";
8-
9-
interface ReactionStub {
10-
emoji: {
11-
name: string | null;
12-
id: string | null;
13-
};
14-
count: number | null;
15-
}
16-
17-
const createMessageWithReactions = (
18-
url: string,
19-
reactions: ReactionStub[],
20-
): Pick<Message, "url" | "reactions"> => {
21-
return {
22-
url,
23-
reactions: {
24-
cache: {
25-
find: (
26-
predicate: (reaction: ReactionStub) => boolean,
27-
): ReactionStub | undefined => reactions.find(predicate),
28-
},
29-
},
30-
} as Pick<Message, "url" | "reactions">;
31-
};
7+
import { createMessageWithUrlAndReactions } from "./starboard.test-utils.js";
328

339
const starboardRenderOptions: StarboardContentRenderOptions = {
3410
emojiId: config.starboard.emojiId,
@@ -43,15 +19,18 @@ describe("buildStarboardMessageContent", () => {
4319
throw new Error("antiStarboard config is required for this test");
4420
}
4521

46-
const message = createMessageWithReactions("https://discord.test/message", [
47-
{
48-
emoji: {
49-
name: antiStarboard.emojiId,
50-
id: null,
22+
const message = createMessageWithUrlAndReactions(
23+
"https://discord.test/message",
24+
[
25+
{
26+
emoji: {
27+
name: antiStarboard.emojiId,
28+
id: null,
29+
},
30+
count: 2,
5131
},
52-
count: 2,
53-
},
54-
]);
32+
],
33+
);
5534

5635
expect(
5736
buildStarboardMessageContent(message, 5, starboardRenderOptions),
@@ -61,7 +40,7 @@ describe("buildStarboardMessageContent", () => {
6140
});
6241

6342
test("omits the anti-star hint when there are no anti-stars", () => {
64-
const message = createMessageWithReactions(
43+
const message = createMessageWithUrlAndReactions(
6544
"https://discord.test/message",
6645
[],
6746
);
@@ -77,15 +56,18 @@ describe("buildStarboardMessageContent", () => {
7756
throw new Error("antiStarboard config is required for this test");
7857
}
7958

80-
const message = createMessageWithReactions("https://discord.test/message", [
81-
{
82-
emoji: {
83-
name: antiStarboard.emojiId,
84-
id: null,
59+
const message = createMessageWithUrlAndReactions(
60+
"https://discord.test/message",
61+
[
62+
{
63+
emoji: {
64+
name: antiStarboard.emojiId,
65+
id: null,
66+
},
67+
count: 2,
8568
},
86-
count: 2,
87-
},
88-
]);
69+
],
70+
);
8971

9072
expect(
9173
buildStarboardMessageContent(message, 2, {

src/modules/starboard/starboard.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,13 @@ export const createStarboardMessageFromMessage: (
149149
message: Message,
150150
member: GuildMember,
151151
stars: number,
152-
starboardMessage?: Message,
153152
renderOptions?: StarboardRenderOptions,
154153
contentStars?: number,
155154
) => Promise<{
156155
embeds: EmbedBuilder[];
157156
content: string;
158157
files?: AttachmentBuilder[];
159-
}> = async (
160-
message,
161-
member,
162-
stars,
163-
_starboardMessage,
164-
renderOptions,
165-
contentStars,
166-
) => {
158+
}> = async (message, member, stars, renderOptions, contentStars) => {
167159
const settings = renderOptions ?? defaultRenderOptions;
168160
const embeds: EmbedBuilder[] = [];
169161
const files: AttachmentBuilder[] = [];

0 commit comments

Comments
 (0)