Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added date tests to basic-querying to ensure client encoding is applied ... #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions test/basic-querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('basic-querying', function() {
name: {type: String, sort: true},
email: {type: String, index: true},
role: {type: String, index: true},
order: {type: Number, index: true, sort: true}
order: {type: Number, index: true, sort: true},
birthday: { type: Date }
});

db.automigrate(done);
Expand Down Expand Up @@ -132,6 +133,15 @@ describe('basic-querying', function() {
});
});

it('should query date ranges', function(done) {
User.all({where: {birthday: {lt: new Date('1940-10-10'), gt: new Date('1940-10-01')}}}, function(err, users) {
should.not.exist(err);
should.exist(users);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
});

describe('count', function() {
Expand All @@ -155,6 +165,15 @@ describe('basic-querying', function() {
done();
});
});

it('should support date filtering', function(done) {
User.count({birthday: {lt: new Date('1940-10-01')}}, function(err, n) {
should.not.exist(err);
should.exist(n);
n.should.equal(2);
done();
});
});
});

describe('findOne', function() {
Expand Down Expand Up @@ -215,6 +234,14 @@ describe('basic-querying', function() {
});
});

it('should work with date equality', function(done) {
User.findOne({where: {birthday: new Date('1940-10-09')}}, function(e, u) {
should.not.exist(e);
should.exist(u);
u.name.should.equal('John Lennon');
done();
});
});
});

describe('exists', function() {
Expand Down Expand Up @@ -254,17 +281,19 @@ function seed(done) {
name: 'John Lennon',
mail: '[email protected]',
role: 'lead',
order: 2
order: 2,
birthday: new Date('1940-10-09')
}, {
name: 'Paul McCartney',
mail: '[email protected]',
role: 'lead',
order: 1
order: 1,
birthday: new Date('1942-06-18')
},
{name: 'George Harrison', order: 5},
{name: 'Ringo Starr', order: 6},
{name: 'Pete Best', order: 4},
{name: 'Stuart Sutcliffe', order: 3}
{name: 'George Harrison', birthday: new Date('1943-02-25'), order: 5},
{name: 'Ringo Starr', birthday: new Date('1940-07-07'), order: 6},
{name: 'Pete Best', birthday: new Date('1941-11-24'), order: 4},
{name: 'Stuart Sutcliffe', birthday: new Date('1940-06-23'), order: 3}
];
User.destroyAll(function() {
beatles.forEach(function(beatle) {
Expand Down