Skip to content

Commit

Permalink
create sequence for nosql id (#1354)
Browse files Browse the repository at this point in the history
* create sequence for nosql id
  • Loading branch information
Janny committed May 2, 2017
1 parent 6342a03 commit 5d10c72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions test/basic-querying.test.js
Expand Up @@ -856,8 +856,8 @@ describe('basic-querying', function() {
if (err) return done(err);
users.length.should.be.equal(2);
var expectedUsers = ['John Lennon', 'Paul McCartney'];
(expectedUsers.indexOf(users[0].name) > -1).should.be.ok();
(expectedUsers.indexOf(users[1].name) > -1).should.be.ok();
expectedUsers.indexOf(users[0].name).should.not.equal(-1);
expectedUsers.indexOf(users[1].name).should.not.equal(-1);
done();
});
});
Expand Down
41 changes: 27 additions & 14 deletions test/relations.test.js
Expand Up @@ -574,7 +574,7 @@ describe('relations', function() {
before(function(done) {
db = getSchema();
Physician = db.define('Physician', {name: String});
Patient = db.define('Patient', {name: String, age: Number});
Patient = db.define('Patient', {name: String, age: Number, sequence: Number});
Appointment = db.define('Appointment', {date: {type: Date,
default: function() {
return new Date();
Expand Down Expand Up @@ -734,7 +734,7 @@ describe('relations', function() {
context('with filter skip', function() {
bdd.itIf(connectorCapabilities.supportPagination !== false,
'skips the first patient', function(done) {
physician.patients({skip: 1}, function(err, ch) {
physician.patients({skip: 1, order: 'sequence'}, function(err, ch) {
if (err) return done(err);
should.exist(ch);
ch.should.have.lengthOf(2);
Expand Down Expand Up @@ -767,7 +767,7 @@ describe('relations', function() {
});
context('with filter limit', function() {
it('limits to 1 result', function(done) {
physician.patients({limit: 1}, function(err, ch) {
physician.patients({limit: 1, order: 'sequence'}, function(err, ch) {
if (err) return done(err);
should.exist(ch);
ch.should.have.lengthOf(1);
Expand All @@ -782,7 +782,10 @@ describe('relations', function() {
});
context('with filter fields', function() {
it('includes field \'name\' but not \'age\'', function(done) {
var fieldsFilter = {fields: {name: true, age: false}};
var fieldsFilter = {
fields: {name: true, age: false},
order: 'sequence',
};
physician.patients(fieldsFilter, function(err, ch) {
if (err) return done(err);
should.exist(ch);
Expand Down Expand Up @@ -832,8 +835,16 @@ describe('relations', function() {
if (err) return done(err);
should.exist(ch);
ch.should.have.lengthOf(2);
var resultIdArr = [ch[0].id, ch[1].id];
assert.deepEqual(resultIdArr, idArr);
if (typeof idArr[0] === 'object') {
// mongodb returns `id` as an object
idArr[0] = idArr[0].toString();
idArr[1] = idArr[1].toString();
idArr.indexOf(ch[0].id.toString()).should.not.equal(-1);
idArr.indexOf(ch[1].id.toString()).should.not.equal(-1);
} else {
idArr.indexOf(ch[0].id).should.not.equal(-1);
idArr.indexOf(ch[1].id).should.not.equal(-1);
}
done();
});
});
Expand Down Expand Up @@ -888,15 +899,17 @@ describe('relations', function() {

function createSampleData(done) {
Physician.create(function(err, result) {
result.patients.create({name: 'a', age: '10'}, function(err, p) {
samplePatientId = p.id;
result.patients.create({name: 'z', age: '20'}, function() {
result.patients.create({name: 'c'}, function() {
physician = result;
done();
});
result.patients.create({name: 'a', age: '10', sequence: 1},
function(err, p) {
samplePatientId = p.id;
result.patients.create({name: 'z', age: '20', sequence: 2},
function() {
result.patients.create({name: 'c', sequence: 3}, function() {
physician = result;
done();
});
});
});
});
});
};
});
Expand Down

0 comments on commit 5d10c72

Please sign in to comment.