-
Notifications
You must be signed in to change notification settings - Fork 71.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable id query with no date (#4481)
* Enable id query with no date * Add unit test for query.js
- Loading branch information
1 parent
d73958d
commit 6223212
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
require('should'); | ||
|
||
var moment = require('moment'); | ||
|
||
describe('query', function ( ) { | ||
var query = require('../lib/server/query'); | ||
|
||
it('should provide default options', function ( ) { | ||
var opts = query(); | ||
|
||
var low = moment().utc().subtract(4, 'days').subtract(1, 'minutes').format(); | ||
var high = moment().utc().subtract(4, 'days').add(1, 'minutes').format(); | ||
|
||
opts.date['$gte'].should.be.greaterThan(low); | ||
opts.date['$gte'].should.be.lessThan(high); | ||
}); | ||
|
||
it('should not override non default options', function ( ) { | ||
var opts = query({}, { | ||
deltaAgo: 2 * 24 * 60 * 60000, | ||
dateField: 'created_at' | ||
}); | ||
|
||
var low = moment().utc().subtract(2, 'days').subtract(1, 'minutes').format(); | ||
var high = moment().utc().subtract(2, 'days').add(1, 'minutes').format(); | ||
|
||
opts.created_at['$gte'].should.greaterThan(low); | ||
opts.created_at['$gte'].should.lessThan(high); | ||
}); | ||
|
||
it('should not enforce date filter if query includes id', function ( ) { | ||
var opts = query({ find: { _id: 1234 } }); | ||
|
||
(typeof opts.date).should.equal('undefined') | ||
}); | ||
}); |