@@ -194,6 +194,95 @@ describe("AdminController", () => {
194194 ) . toBeRateLimited ( { max : 1 , windowMs : 5000 } ) ;
195195 } ) ;
196196 } ) ;
197+
198+ describe ( "clear streak hour offset" , ( ) => {
199+ const clearStreakHourOffset = vi . spyOn ( UserDal , "clearStreakHourOffset" ) ;
200+
201+ beforeEach ( ( ) => {
202+ [ clearStreakHourOffset ] . forEach ( ( it ) => it . mockReset ( ) ) ;
203+ } ) ;
204+
205+ it ( "should clear streak hour offset for user" , async ( ) => {
206+ //GIVEN
207+ const victimUid = new ObjectId ( ) . toHexString ( ) ;
208+
209+ //WHEN
210+ const { body } = await mockApp
211+ . post ( "/admin/clearStreakHourOffset" )
212+ . send ( { uid : victimUid } )
213+ . set ( "Authorization" , `Bearer ${ uid } ` )
214+ . expect ( 200 ) ;
215+
216+ //THEN
217+ expect ( body ) . toEqual ( {
218+ message : "Streak hour offset cleared" ,
219+ data : null ,
220+ } ) ;
221+ expect ( clearStreakHourOffset ) . toHaveBeenCalledWith ( victimUid ) ;
222+ } ) ;
223+ it ( "should fail without mandatory properties" , async ( ) => {
224+ //GIVEN
225+
226+ //WHEN
227+ const { body } = await mockApp
228+ . post ( "/admin/clearStreakHourOffset" )
229+ . send ( { } )
230+ . set ( "Authorization" , `Bearer ${ uid } ` )
231+ . expect ( 422 ) ;
232+
233+ //THEN
234+ expect ( body ) . toEqual ( {
235+ message : "Invalid request data schema" ,
236+ validationErrors : [ '"uid" Required' ] ,
237+ } ) ;
238+ } ) ;
239+ it ( "should fail with unknown properties" , async ( ) => {
240+ //GIVEN
241+
242+ //WHEN
243+ const { body } = await mockApp
244+ . post ( "/admin/clearStreakHourOffset" )
245+ . send ( { uid : new ObjectId ( ) . toHexString ( ) , extra : "value" } )
246+ . set ( "Authorization" , `Bearer ${ uid } ` )
247+ . expect ( 422 ) ;
248+
249+ //THEN
250+ expect ( body ) . toEqual ( {
251+ message : "Invalid request data schema" ,
252+ validationErrors : [ "Unrecognized key(s) in object: 'extra'" ] ,
253+ } ) ;
254+ } ) ;
255+ it ( "should fail if user is no admin" , async ( ) => {
256+ await expectFailForNonAdmin (
257+ mockApp
258+ . post ( "/admin/clearStreakHourOffset" )
259+ . send ( { uid : new ObjectId ( ) . toHexString ( ) } )
260+ . set ( "Authorization" , `Bearer ${ uid } ` )
261+ ) ;
262+ } ) ;
263+ it ( "should fail if admin endpoints are disabled" , async ( ) => {
264+ //GIVEN
265+ await expectFailForDisabledEndpoint (
266+ mockApp
267+ . post ( "/admin/clearStreakHourOffset" )
268+ . send ( { uid : new ObjectId ( ) . toHexString ( ) } )
269+ . set ( "Authorization" , `Bearer ${ uid } ` )
270+ ) ;
271+ } ) ;
272+ it ( "should be rate limited" , async ( ) => {
273+ //GIVEN
274+ const victimUid = new ObjectId ( ) . toHexString ( ) ;
275+
276+ //WHEN
277+ await expect (
278+ mockApp
279+ . post ( "/admin/clearStreakHourOffset" )
280+ . send ( { uid : victimUid } )
281+ . set ( "Authorization" , `Bearer ${ uid } ` )
282+ ) . toBeRateLimited ( { max : 1 , windowMs : 5000 } ) ;
283+ } ) ;
284+ } ) ;
285+
197286 describe ( "accept reports" , ( ) => {
198287 const getReportsMock = vi . spyOn ( ReportDal , "getReports" ) ;
199288 const deleteReportsMock = vi . spyOn ( ReportDal , "deleteReports" ) ;
0 commit comments