@@ -198,6 +198,93 @@ describe("Logs", function () {
198
198
expect ( Array . from ( uniqueTypes ) [ 0 ] ) . to . equal ( "REQUEST_CREATED" ) ;
199
199
} ) ;
200
200
201
+ it ( "Should throw error when start date is greater than end date in dev mode" , async function ( ) {
202
+ await cleanDb ( ) ;
203
+
204
+ const startDate = Date . now ( ) ;
205
+ const endDate = startDate - 86400000 ;
206
+
207
+ try {
208
+ await logsQuery . fetchAllLogs ( {
209
+ dev : "true" ,
210
+ startDate : startDate . toString ( ) ,
211
+ endDate : endDate . toString ( ) ,
212
+ size : 3 ,
213
+ } ) ;
214
+ throw new Error ( "Expected fetchAllLogs to throw an error, but it did not." ) ;
215
+ } catch ( error ) {
216
+ expect ( error ) . to . be . instanceOf ( Error ) ;
217
+ expect ( error . message ) . to . equal ( "Start date cannot be greater than end date." ) ;
218
+ expect ( error ) . to . have . property ( "statusCode" , 400 ) ;
219
+ }
220
+ } ) ;
221
+
222
+ it ( "Should return logs within the specified date range in dev mode" , async function ( ) {
223
+ await cleanDb ( ) ;
224
+
225
+ const endDate = Date . now ( ) ;
226
+ const startDate = endDate - 86400000 * 7 ;
227
+
228
+ const result = await logsQuery . fetchAllLogs ( {
229
+ dev : "true" ,
230
+ startDate : startDate . toString ( ) ,
231
+ endDate : endDate . toString ( ) ,
232
+ size : 3 ,
233
+ } ) ;
234
+
235
+ expect ( result ) . to . have . property ( "allLogs" ) ;
236
+ if ( result . allLogs . length > 0 ) {
237
+ result . allLogs . forEach ( ( log ) => {
238
+ expect ( log ) . to . have . property ( "timestamp" ) ;
239
+ } ) ;
240
+ }
241
+ } ) ;
242
+
243
+ it ( "Should ignore date filters when not in dev mode" , async function ( ) {
244
+ const endDate = Date . now ( ) ;
245
+ const startDate = endDate - 86400000 * 7 ;
246
+
247
+ const result = await logsQuery . fetchAllLogs ( {
248
+ dev : "false" ,
249
+ startDate : startDate . toString ( ) ,
250
+ endDate : endDate . toString ( ) ,
251
+ size : 3 ,
252
+ } ) ;
253
+
254
+ expect ( result ) . to . have . property ( "allLogs" ) ;
255
+ expect ( result ) . to . have . property ( "prev" ) ;
256
+ expect ( result ) . to . have . property ( "next" ) ;
257
+ expect ( result ) . to . have . property ( "page" ) ;
258
+ } ) ;
259
+
260
+ it ( "Should handle only start date filter in dev mode" , async function ( ) {
261
+ const startDate = Date . now ( ) - 86400000 * 14 ;
262
+
263
+ const result = await logsQuery . fetchAllLogs ( {
264
+ dev : "true" ,
265
+ startDate : startDate . toString ( ) ,
266
+ size : 3 ,
267
+ } ) ;
268
+
269
+ expect ( result ) . to . have . property ( "allLogs" ) ;
270
+ expect ( result ) . to . have . property ( "prev" ) ;
271
+ expect ( result ) . to . have . property ( "next" ) ;
272
+ } ) ;
273
+
274
+ it ( "Should handle only end date filter in dev mode" , async function ( ) {
275
+ const endDate = Date . now ( ) ;
276
+
277
+ const result = await logsQuery . fetchAllLogs ( {
278
+ dev : "true" ,
279
+ endDate : endDate . toString ( ) ,
280
+ size : 3 ,
281
+ } ) ;
282
+
283
+ expect ( result ) . to . have . property ( "allLogs" ) ;
284
+ expect ( result ) . to . have . property ( "prev" ) ;
285
+ expect ( result ) . to . have . property ( "next" ) ;
286
+ } ) ;
287
+
201
288
it ( "Should return null if no logs are presnet the logs for specific types" , async function ( ) {
202
289
await cleanDb ( ) ;
203
290
const result = await logsQuery . fetchAllLogs ( { } ) ;
0 commit comments