@@ -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+ } ) ;
0 commit comments