@@ -146,7 +146,7 @@ describe('queryFilter()', function () {
146
146
name : { '$options' : 'i' , '$regex' : 'jorge' }
147
147
} ] ,
148
148
'school.name' : 'UEPB' ,
149
- 'timestamp' : '2018-12-05T00:00:00.000Z ' ,
149
+ 'timestamp' : '2018-12-05T00:00:00' ,
150
150
'$or' : [ { job : 'Developer' } , { job : 'Engineer' } ]
151
151
}
152
152
@@ -174,8 +174,8 @@ describe('queryFilter()', function () {
174
174
const expect_filters = {
175
175
name : 'lucas' ,
176
176
age : { $gt : 30 } ,
177
- timestamp : { $gt : '2018-12-05T00:00:00.000Z ' } ,
178
- created_at : { $lte : '2018-12-06T00:00:00.000Z ' } ,
177
+ timestamp : { $gt : '2018-12-05T00:00:00' } ,
178
+ created_at : { $lte : '2018-12-06T00:00:00' } ,
179
179
sleep_hour : '22:40'
180
180
}
181
181
@@ -193,15 +193,14 @@ describe('queryFilter()', function () {
193
193
options . default . filters = expect_filters
194
194
195
195
qs ( { } ) ( req , res , function next ( ) {
196
- console . log ( 'req: ' , req . query . filters ) ;
197
196
validate ( req , options )
198
197
} )
199
198
done ( )
200
199
} )
201
200
} )
202
201
203
202
context ( 'when query contains date filters param' , function ( ) {
204
- it ( 'should return req.query with set date_start params' , function ( done ) {
203
+ it ( 'should return req.query with set date_start params as date ' , function ( done ) {
205
204
const expect_filters = {
206
205
$and : [
207
206
{ created_at : { $lt : new Date ( ) . toISOString ( ) } } ,
@@ -222,7 +221,28 @@ describe('queryFilter()', function () {
222
221
done ( )
223
222
} )
224
223
225
- it ( 'should return req.query with set date_start and date_end params' , function ( done ) {
224
+ it ( 'should return req.query with set date_start params as dateTime' , function ( done ) {
225
+ const expect_filters = {
226
+ $and : [
227
+ { created_at : { $lt : new Date ( ) . toISOString ( ) } } ,
228
+ { created_at : { $gte : '2018-12-05T00:00:00.000Z' } }
229
+ ]
230
+ }
231
+
232
+ const query = { date_start : '2018-12-05T00:00:00' }
233
+ const req = httpMocks . createRequest ( { method : 'GET' , url : '/' , query : query } )
234
+ const res = httpMocks . createResponse ( )
235
+
236
+ const options = JSON . parse ( JSON . stringify ( default_options ) )
237
+ options . default . filters = expect_filters
238
+
239
+ qs ( { } ) ( req , res , function next ( ) {
240
+ validateFilterWithDate ( req , options )
241
+ } )
242
+ done ( )
243
+ } )
244
+
245
+ it ( 'should return req.query with set date_start and date_end params as date' , function ( done ) {
226
246
227
247
const expect_filters = {
228
248
$and : [
@@ -243,15 +263,36 @@ describe('queryFilter()', function () {
243
263
done ( )
244
264
} )
245
265
266
+ it ( 'should return req.query with set date_start and date_end params as dateTime' , function ( done ) {
267
+
268
+ const expect_filters = {
269
+ $and : [
270
+ { created_at : { $lt : '2018-12-11T00:00:00.000Z' } } ,
271
+ { created_at : { $gte : '2018-12-01T00:00:00.000Z' } } ]
272
+ }
273
+
274
+ const query = { date_start : '2018-12-01T00:00:00' , date_end : '2018-12-11T00:00:00' }
275
+ const req = httpMocks . createRequest ( { method : 'GET' , url : '/' , query : query } )
276
+ const res = httpMocks . createResponse ( )
277
+
278
+ const options = JSON . parse ( JSON . stringify ( default_options ) )
279
+ options . default . filters = expect_filters
280
+
281
+ qs ( { } ) ( req , res , function next ( ) {
282
+ validateFilterWithDate ( req , options )
283
+ } )
284
+ done ( )
285
+ } )
286
+
246
287
it ( 'should return req.query with set period and date_end param' , function ( done ) {
247
288
248
289
const expect_filters = {
249
290
$and : [
250
- { created_at : { $lt : new Date ( '2018-12-13 ' ) . toISOString ( ) } } ,
251
- { created_at : { $gte : new Date ( '2018-11-12 ' ) . toISOString ( ) } }
291
+ { created_at : { $lt : new Date ( '2018-12-09 ' ) . toISOString ( ) } } ,
292
+ { created_at : { $gte : new Date ( '2018-11-10 ' ) . toISOString ( ) } }
252
293
]
253
294
}
254
- const query = { period : '1m' , date_end : '2018-12-13 ' }
295
+ const query = { period : '1m' , date_end : '2018-12-09 ' }
255
296
const req = httpMocks . createRequest ( { method : 'GET' , url : '/' , query : query } )
256
297
const res = httpMocks . createResponse ( )
257
298
@@ -265,7 +306,7 @@ describe('queryFilter()', function () {
265
306
} )
266
307
267
308
it ( 'should return req.query with set period as day params' , function ( done ) {
268
- const now = new Date ( ) ;
309
+ const now = new Date ( )
269
310
const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
270
311
const beforeToday = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) - 9 ) )
271
312
const expect_filters = {
@@ -290,7 +331,7 @@ describe('queryFilter()', function () {
290
331
291
332
it ( 'should return req.query with set period as week params' , function ( done ) {
292
333
293
- const now = new Date ( ) ;
334
+ const now = new Date ( )
294
335
const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
295
336
const beforeToday = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) - 14 ) )
296
337
const expect_filters = {
@@ -314,7 +355,7 @@ describe('queryFilter()', function () {
314
355
} )
315
356
it ( 'should return req.query with set period as month params' , function ( done ) {
316
357
317
- const now = new Date ( ) ;
358
+ const now = new Date ( )
318
359
const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
319
360
const beforeToday = dateToString ( new Date ( now . getFullYear ( ) , ( now . getMonth ( ) - 1 ) , now . getDate ( ) ) )
320
361
const expect_filters = {
@@ -339,7 +380,7 @@ describe('queryFilter()', function () {
339
380
340
381
it ( 'should return req.query with set period as year params' , function ( done ) {
341
382
342
- const now = new Date ( ) ;
383
+ const now = new Date ( )
343
384
const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
344
385
const beforeToday = dateToString ( new Date ( now . getFullYear ( ) - 1 , now . getMonth ( ) , now . getDate ( ) ) )
345
386
const expect_filters = {
0 commit comments