@@ -294,9 +294,11 @@ describe("Loaderboard Controller", () => {
294294
295295 describe ( "get rank" , ( ) => {
296296 const getLeaderboardRankMock = vi . spyOn ( LeaderboardDal , "getRank" ) ;
297+ const getFriendsUidsMock = vi . spyOn ( FriendDal , "getFriendsUids" ) ;
297298
298299 afterEach ( ( ) => {
299300 getLeaderboardRankMock . mockClear ( ) ;
301+ getFriendsUidsMock . mockClear ( ) ;
300302 } ) ;
301303
302304 it ( "fails withouth authentication" , async ( ) => {
@@ -308,7 +310,6 @@ describe("Loaderboard Controller", () => {
308310
309311 it ( "should get for english time 60" , async ( ) => {
310312 //GIVEN
311-
312313 const entryId = new ObjectId ( ) ;
313314 const resultEntry = {
314315 _id : entryId ,
@@ -323,7 +324,6 @@ describe("Loaderboard Controller", () => {
323324 getLeaderboardRankMock . mockResolvedValue ( resultEntry ) ;
324325
325326 //WHEN
326-
327327 const { body } = await mockApp
328328 . get ( "/leaderboards/rank" )
329329 . query ( { language : "english" , mode : "time" , mode2 : "60" } )
@@ -344,6 +344,37 @@ describe("Loaderboard Controller", () => {
344344 undefined
345345 ) ;
346346 } ) ;
347+
348+ it ( "should get for english time 60 friends only" , async ( ) => {
349+ //GIVEN
350+ await enableFriendsFeature ( true ) ;
351+ const friends = [ "friendOne" , "friendTwo" ] ;
352+ getFriendsUidsMock . mockResolvedValue ( friends ) ;
353+ getLeaderboardRankMock . mockResolvedValue ( { } as any ) ;
354+
355+ //WHEN
356+ await mockApp
357+ . get ( "/leaderboards/rank" )
358+ . query ( {
359+ language : "english" ,
360+ mode : "time" ,
361+ mode2 : "60" ,
362+ friendsOnly : true ,
363+ } )
364+ . set ( "Authorization" , `Bearer ${ uid } ` )
365+ . expect ( 200 ) ;
366+
367+ //THEN
368+ expect ( getLeaderboardRankMock ) . toHaveBeenCalledWith (
369+ "time" ,
370+ "60" ,
371+ "english" ,
372+ uid ,
373+ friends
374+ ) ;
375+ expect ( getFriendsUidsMock ) . toHaveBeenCalledWith ( uid ) ;
376+ } ) ;
377+
347378 it ( "should get with ape key" , async ( ) => {
348379 await acceptApeKeys ( true ) ;
349380 const apeKey = await mockAuthenticateWithApeKey ( uid , await configuration ) ;
@@ -795,10 +826,12 @@ describe("Loaderboard Controller", () => {
795826 ) ;
796827
797828 const getRankMock = vi . fn ( ) ;
829+ const getFriendsUidsMock = vi . spyOn ( FriendDal , "getFriendsUids" ) ;
798830
799831 beforeEach ( async ( ) => {
800832 getDailyLeaderboardMock . mockClear ( ) ;
801833 getRankMock . mockClear ( ) ;
834+ getFriendsUidsMock . mockClear ( ) ;
802835
803836 getDailyLeaderboardMock . mockReturnValue ( {
804837 getRank : getRankMock ,
@@ -820,6 +853,7 @@ describe("Loaderboard Controller", () => {
820853 . query ( { language : "english" , mode : "time" , mode2 : "60" } )
821854 . expect ( 401 ) ;
822855 } ) ;
856+
823857 it ( "should get for english time 60" , async ( ) => {
824858 //GIVEN
825859 const lbConf = ( await configuration ) . dailyLeaderboards ;
@@ -862,8 +896,42 @@ describe("Loaderboard Controller", () => {
862896 - 1
863897 ) ;
864898
865- expect ( getRankMock ) . toHaveBeenCalledWith ( uid , lbConf ) ;
899+ expect ( getRankMock ) . toHaveBeenCalledWith ( uid , lbConf , undefined ) ;
866900 } ) ;
901+
902+ it ( "should get for english time 60 friends only" , async ( ) => {
903+ //GIVEN
904+ const lbConf = ( await configuration ) . dailyLeaderboards ;
905+ getRankMock . mockResolvedValue ( { } ) ;
906+ const friends = [ "friendOne" , "friendTwo" ] ;
907+ getFriendsUidsMock . mockResolvedValue ( friends ) ;
908+
909+ //WHEN
910+ await mockApp
911+ . get ( "/leaderboards/daily/rank" )
912+ . set ( "Authorization" , `Bearer ${ uid } ` )
913+ . query ( {
914+ language : "english" ,
915+ mode : "time" ,
916+ mode2 : "60" ,
917+ friendsOnly : true ,
918+ } )
919+ . expect ( 200 ) ;
920+
921+ //THEN
922+
923+ expect ( getDailyLeaderboardMock ) . toHaveBeenCalledWith (
924+ "english" ,
925+ "time" ,
926+ "60" ,
927+ lbConf ,
928+ - 1
929+ ) ;
930+
931+ expect ( getRankMock ) . toHaveBeenCalledWith ( uid , lbConf , friends ) ;
932+ expect ( getFriendsUidsMock ) . toHaveBeenCalledWith ( uid ) ;
933+ } ) ;
934+
867935 it ( "fails if daily leaderboards are disabled" , async ( ) => {
868936 await dailyLeaderboardEnabled ( false ) ;
869937
@@ -876,6 +944,7 @@ describe("Loaderboard Controller", () => {
876944 "Daily leaderboards are not available at this time."
877945 ) ;
878946 } ) ;
947+
879948 it ( "should get for mode" , async ( ) => {
880949 for ( const mode of [ "time" , "words" , "quote" , "zen" , "custom" ] ) {
881950 const response = await mockApp
@@ -885,6 +954,7 @@ describe("Loaderboard Controller", () => {
885954 expect ( response . status , "for mode " + mode ) . toEqual ( 200 ) ;
886955 }
887956 } ) ;
957+
888958 it ( "should get for mode2" , async ( ) => {
889959 for ( const mode2 of allModes ) {
890960 const response = await mockApp
0 commit comments