@@ -2948,6 +2948,9 @@ describe("user controller test", () => {
29482948 streak : { length : 2 , lastResultTimestamp : 2000 , maxLength : 5 } ,
29492949 lbOptOut : false ,
29502950 bananas : 47 , //should get removed
2951+ testActivity : {
2952+ "2024" : fillYearWithDay ( 94 ) ,
2953+ } ,
29512954 } ;
29522955
29532956 beforeEach ( async ( ) => {
@@ -2961,6 +2964,7 @@ describe("user controller test", () => {
29612964
29622965 it ( "should get by name without authentication" , async ( ) => {
29632966 //GIVEN
2967+
29642968 getUserByNameMock . mockResolvedValue ( foundUser as any ) ;
29652969
29662970 const rank = { rank : 24 } as LeaderboardEntry ;
@@ -3018,6 +3022,46 @@ describe("user controller test", () => {
30183022 expect ( getUserByNameMock ) . toHaveBeenCalledWith ( "bob" , "get user profile" ) ;
30193023 expect ( getUserMock ) . not . toHaveBeenCalled ( ) ;
30203024 } ) ;
3025+ it ( "should get testActivity if enabled" , async ( ) => {
3026+ //GIVEN
3027+ vi . useFakeTimers ( ) . setSystemTime ( 1712102400000 ) ;
3028+ getUserByNameMock . mockResolvedValue ( {
3029+ ...foundUser ,
3030+ profileDetails : { showActivityOnPublicProfile : true } ,
3031+ } as any ) ;
3032+ const rank = { rank : 24 } as LeaderboardEntry ;
3033+ leaderboardGetRankMock . mockResolvedValue ( rank ) ;
3034+ leaderboardGetCountMock . mockResolvedValue ( 100 ) ;
3035+
3036+ //WHEN
3037+ const { body } = await mockApp . get ( "/users/bob/profile" ) . expect ( 200 ) ;
3038+
3039+ //THEN
3040+ expect ( body . data . testActivity ) . toEqual (
3041+ expect . objectContaining ( {
3042+ lastDay : 1712102400000 ,
3043+ testsByDays : expect . arrayContaining ( [ ] ) ,
3044+ } )
3045+ ) ;
3046+ } ) ;
3047+ it ( "should not get testActivity if disabled" , async ( ) => {
3048+ //GIVEN
3049+ vi . useFakeTimers ( ) . setSystemTime ( 1712102400000 ) ;
3050+ getUserByNameMock . mockResolvedValue ( {
3051+ ...foundUser ,
3052+ profileDetails : { showActivityOnPublicProfile : false } ,
3053+ } as any ) ;
3054+ const rank = { rank : 24 } as LeaderboardEntry ;
3055+ leaderboardGetRankMock . mockResolvedValue ( rank ) ;
3056+ leaderboardGetCountMock . mockResolvedValue ( 100 ) ;
3057+
3058+ //WHEN
3059+ const { body } = await mockApp . get ( "/users/bob/profile" ) . expect ( 200 ) ;
3060+
3061+ //THEN
3062+ expect ( body . data . testActivity ) . toBeUndefined ( ) ;
3063+ } ) ;
3064+
30213065 it ( "should get base profile for banned user" , async ( ) => {
30223066 //GIVEN
30233067 getUserByNameMock . mockResolvedValue ( {
@@ -3132,6 +3176,7 @@ describe("user controller test", () => {
31323176 twitter : "twitter" ,
31333177 website : "https://monkeytype.com" ,
31343178 } ,
3179+ showActivityOnPublicProfile : false ,
31353180 } ;
31363181
31373182 //WHEN
@@ -3159,6 +3204,7 @@ describe("user controller test", () => {
31593204 twitter : "twitter" ,
31603205 website : "https://monkeytype.com" ,
31613206 } ,
3207+ showActivityOnPublicProfile : false ,
31623208 } ,
31633209 {
31643210 badges : [ { id : 4 } , { id : 2 , selected : true } , { id : 3 } ] ,
0 commit comments