@@ -201,6 +201,67 @@ describe("/logs", function () {
201201 return done ( ) ;
202202 } ) ;
203203 } ) ;
204+
205+ it ( "should return logs filtered by username, startDate, and endDate when dev flag is enabled" , function ( done ) {
206+ const username = "joygupta" ;
207+ const startDate = 1729841400000 ;
208+ const endDate = 1729841500000 ;
209+ chai
210+ . request ( app )
211+ . get ( `/logs?username=${ username } &startDate=${ startDate } &endDate=${ endDate } &dev=true` )
212+ . set ( "cookie" , `${ cookieName } =${ superUserToken } ` )
213+ . end ( function ( err , res ) {
214+ if ( err ) {
215+ return done ( err ) ;
216+ }
217+ expect ( res ) . to . have . status ( 200 ) ;
218+ expect ( res . body . message ) . to . equal ( "All Logs fetched successfully" ) ;
219+
220+ expect ( res . body . data ) . to . be . an ( "array" ) ;
221+ res . body . data . forEach ( ( log ) => {
222+ expect ( log ) . to . have . property ( "meta" ) ;
223+ expect ( log ) . to . have . property ( "body" ) ;
224+ expect ( log . meta ) . to . have . property ( "userId" ) ;
225+ const timestamp = log . timestamp . _seconds * 1000 ;
226+ expect ( timestamp ) . to . be . at . least ( startDate ) ;
227+ expect ( timestamp ) . to . be . at . most ( endDate ) ;
228+ } ) ;
229+
230+ return done ( ) ;
231+ } ) ;
232+ } ) ;
233+
234+ it ( "should return an error if startDate is greater than endDate" , function ( done ) {
235+ const username = "joygupta" ;
236+ const startDate = 1729841500000 ;
237+ const endDate = 1729841400000 ;
238+
239+ chai
240+ . request ( app )
241+ . get ( `/logs?username=${ username } &startDate=${ startDate } &endDate=${ endDate } &dev=true` )
242+ . set ( "cookie" , `${ cookieName } =${ superUserToken } ` )
243+ . end ( function ( _err , res ) {
244+ expect ( res ) . to . have . status ( 500 ) ;
245+ expect ( res . body . error ) . to . equal ( "Start date cannot be greater than end date." ) ;
246+ return done ( ) ;
247+ } ) ;
248+ } ) ;
249+
250+ it ( "should return an empty array if no logs match username and date range" , function ( done ) {
251+ const username = "nonexistentUser" ;
252+ const startDate = 1729841400000 ;
253+ const endDate = 1729841500000 ;
254+
255+ chai
256+ . request ( app )
257+ . get ( `/logs?username=${ username } &startDate=${ startDate } &endDate=${ endDate } &dev=true` )
258+ . set ( "cookie" , `${ cookieName } =${ superUserToken } ` )
259+ . end ( function ( _err , res ) {
260+ expect ( res ) . to . have . status ( 200 ) ;
261+ expect ( res . body . message ) . to . equal ( "All Logs fetched successfully" ) ;
262+ return done ( ) ;
263+ } ) ;
264+ } ) ;
204265 } ) ;
205266
206267 describe ( "Add logs when user doc is update" , function ( ) {
0 commit comments