Skip to content

Commit cf8deca

Browse files
committed
add more tests and debugging for bump streak ending
1 parent 6598def commit cf8deca

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

src/modules/core/bump.listener.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,77 @@ test("End other user's streak", async () => {
196196
expect.stringContaining("ended"),
197197
);
198198
});
199+
test("End other user's streak with real data", async () => {
200+
const { fakeUser, mockReact, mockChannel } = await setupMocks();
201+
202+
await getOrCreateUserById(266973575225933824n);
203+
await getOrCreateUserById(1118501031488274517n);
204+
const fake266 = createFakeUser(266973575225933824n);
205+
const bumps = [
206+
{
207+
messageId: 1409196765260943511n,
208+
userId: 1118501031488274517n,
209+
timestamp: "2025-08-24 15:24:53.372000 +00:00",
210+
},
211+
{
212+
messageId: 1409229323868700832n,
213+
userId: 266973575225933824n,
214+
timestamp: "2025-08-24 17:34:13.906000 +00:00",
215+
},
216+
{
217+
messageId: 1409260216125489343n,
218+
userId: 266973575225933824n,
219+
timestamp: "2025-08-24 19:36:59.894000 +00:00",
220+
},
221+
{
222+
messageId: 1409290444470354060n,
223+
userId: 266973575225933824n,
224+
timestamp: "2025-08-24 21:37:07.134000 +00:00",
225+
},
226+
];
227+
228+
await Bump.destroy({
229+
where: { userId: 1n },
230+
}); // remove user 1
231+
for (const bump of bumps) {
232+
await Bump.create({
233+
userId: BigInt(bump.userId),
234+
timestamp: new Date(bump.timestamp),
235+
messageId: BigInt(bump.messageId),
236+
});
237+
}
238+
239+
// until evil user 2 comes along
240+
const otherUserId = 2n;
241+
const otherUser = await getOrCreateUserById(otherUserId);
242+
await Bump.create({
243+
userId: BigInt(otherUserId),
244+
timestamp: new Date(),
245+
messageId: BigInt(20),
246+
});
247+
248+
await handleBumpStreak(
249+
otherUser,
250+
{ user: createFakeUser(otherUserId) } as unknown as MessageInteraction,
251+
{ channel: mockChannel, react: mockReact } as unknown as Message & {
252+
channel: PartialTextBasedChannelFields;
253+
},
254+
{
255+
users: {
256+
fetch: mock(async (id: string) => {
257+
if (id === otherUserId.toString())
258+
return { id: otherUserId.toString() };
259+
if (id === fakeUser.id) return fakeUser;
260+
if (id === fake266.id) return fake266;
261+
throw new Error("Unknown user");
262+
}),
263+
},
264+
} as unknown as Client,
265+
);
266+
267+
expect(mockReact).toHaveBeenCalledTimes(1);
268+
expect(mockChannel.send).toHaveBeenCalledTimes(1);
269+
expect(mockChannel.send).toHaveBeenCalledWith(
270+
expect.stringContaining("ended"),
271+
);
272+
});

src/modules/core/bump.listener.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { EventListener } from "../module.js";
22
import {
33
ChannelType,
4+
Client,
5+
EmojiIdentifierResolvable,
46
InteractionType,
57
Message,
68
MessageInteraction,
@@ -9,7 +11,6 @@ import {
911
import { DDUser, getOrCreateUserById } from "../../store/models/DDUser.js";
1012
import { logger } from "../../logging.js";
1113
import { config } from "../../Config.js";
12-
import { Client, EmojiIdentifierResolvable } from "discord.js";
1314
import { Bump } from "../../store/models/Bump.js";
1415
import {
1516
extractStreaks,
@@ -65,6 +66,10 @@ export async function handleBumpStreak(
6566
if (allStreaks.length > 1) {
6667
const mostRecent = allStreaks[allStreaks.length - 2]!;
6768
logger.debug(`Most recent streak:`, mostRecent);
69+
logger.debug(
70+
"Most recent streaks:",
71+
allStreaks.slice(allStreaks.length - 5),
72+
);
6873
if (mostRecent.userId != bumper.id && mostRecent.current >= 2) {
6974
const user = await client.users.fetch(mostRecent.userId.toString());
7075
message.channel.send(

0 commit comments

Comments
 (0)