@@ -146,7 +146,7 @@ describe('queryFilter()', function () {
146146 name : { '$options' : 'i' , '$regex' : 'jorge' }
147147 } ] ,
148148 'school.name' : 'UEPB' ,
149- 'timestamp' : '2018-12-05T00:00:00.000Z ' ,
149+ 'timestamp' : '2018-12-05T00:00:00' ,
150150 '$or' : [ { job : 'Developer' } , { job : 'Engineer' } ]
151151 }
152152
@@ -174,8 +174,8 @@ describe('queryFilter()', function () {
174174 const expect_filters = {
175175 name : 'lucas' ,
176176 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' } ,
179179 sleep_hour : '22:40'
180180 }
181181
@@ -193,15 +193,14 @@ describe('queryFilter()', function () {
193193 options . default . filters = expect_filters
194194
195195 qs ( { } ) ( req , res , function next ( ) {
196- console . log ( 'req: ' , req . query . filters ) ;
197196 validate ( req , options )
198197 } )
199198 done ( )
200199 } )
201200 } )
202201
203202 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 ) {
205204 const expect_filters = {
206205 $and : [
207206 { created_at : { $lt : new Date ( ) . toISOString ( ) } } ,
@@ -222,7 +221,28 @@ describe('queryFilter()', function () {
222221 done ( )
223222 } )
224223
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 ) {
226246
227247 const expect_filters = {
228248 $and : [
@@ -243,15 +263,36 @@ describe('queryFilter()', function () {
243263 done ( )
244264 } )
245265
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+
246287 it ( 'should return req.query with set period and date_end param' , function ( done ) {
247288
248289 const expect_filters = {
249290 $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 ( ) } }
252293 ]
253294 }
254- const query = { period : '1m' , date_end : '2018-12-13 ' }
295+ const query = { period : '1m' , date_end : '2018-12-09 ' }
255296 const req = httpMocks . createRequest ( { method : 'GET' , url : '/' , query : query } )
256297 const res = httpMocks . createResponse ( )
257298
@@ -265,7 +306,7 @@ describe('queryFilter()', function () {
265306 } )
266307
267308 it ( 'should return req.query with set period as day params' , function ( done ) {
268- const now = new Date ( ) ;
309+ const now = new Date ( )
269310 const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
270311 const beforeToday = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) - 9 ) )
271312 const expect_filters = {
@@ -290,7 +331,7 @@ describe('queryFilter()', function () {
290331
291332 it ( 'should return req.query with set period as week params' , function ( done ) {
292333
293- const now = new Date ( ) ;
334+ const now = new Date ( )
294335 const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
295336 const beforeToday = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) - 14 ) )
296337 const expect_filters = {
@@ -314,7 +355,7 @@ describe('queryFilter()', function () {
314355 } )
315356 it ( 'should return req.query with set period as month params' , function ( done ) {
316357
317- const now = new Date ( ) ;
358+ const now = new Date ( )
318359 const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
319360 const beforeToday = dateToString ( new Date ( now . getFullYear ( ) , ( now . getMonth ( ) - 1 ) , now . getDate ( ) ) )
320361 const expect_filters = {
@@ -339,7 +380,7 @@ describe('queryFilter()', function () {
339380
340381 it ( 'should return req.query with set period as year params' , function ( done ) {
341382
342- const now = new Date ( ) ;
383+ const now = new Date ( )
343384 const today = dateToString ( new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) + 1 ) )
344385 const beforeToday = dateToString ( new Date ( now . getFullYear ( ) - 1 , now . getMonth ( ) , now . getDate ( ) ) )
345386 const expect_filters = {
0 commit comments