Skip to content

Commit 5d10c72

Browse files
author
Janny
authored
create sequence for nosql id (#1354)
* create sequence for nosql id
1 parent 6342a03 commit 5d10c72

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

test/basic-querying.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,8 @@ describe('basic-querying', function() {
856856
if (err) return done(err);
857857
users.length.should.be.equal(2);
858858
var expectedUsers = ['John Lennon', 'Paul McCartney'];
859-
(expectedUsers.indexOf(users[0].name) > -1).should.be.ok();
860-
(expectedUsers.indexOf(users[1].name) > -1).should.be.ok();
859+
expectedUsers.indexOf(users[0].name).should.not.equal(-1);
860+
expectedUsers.indexOf(users[1].name).should.not.equal(-1);
861861
done();
862862
});
863863
});

test/relations.test.js

+27-14
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ describe('relations', function() {
574574
before(function(done) {
575575
db = getSchema();
576576
Physician = db.define('Physician', {name: String});
577-
Patient = db.define('Patient', {name: String, age: Number});
577+
Patient = db.define('Patient', {name: String, age: Number, sequence: Number});
578578
Appointment = db.define('Appointment', {date: {type: Date,
579579
default: function() {
580580
return new Date();
@@ -734,7 +734,7 @@ describe('relations', function() {
734734
context('with filter skip', function() {
735735
bdd.itIf(connectorCapabilities.supportPagination !== false,
736736
'skips the first patient', function(done) {
737-
physician.patients({skip: 1}, function(err, ch) {
737+
physician.patients({skip: 1, order: 'sequence'}, function(err, ch) {
738738
if (err) return done(err);
739739
should.exist(ch);
740740
ch.should.have.lengthOf(2);
@@ -767,7 +767,7 @@ describe('relations', function() {
767767
});
768768
context('with filter limit', function() {
769769
it('limits to 1 result', function(done) {
770-
physician.patients({limit: 1}, function(err, ch) {
770+
physician.patients({limit: 1, order: 'sequence'}, function(err, ch) {
771771
if (err) return done(err);
772772
should.exist(ch);
773773
ch.should.have.lengthOf(1);
@@ -782,7 +782,10 @@ describe('relations', function() {
782782
});
783783
context('with filter fields', function() {
784784
it('includes field \'name\' but not \'age\'', function(done) {
785-
var fieldsFilter = {fields: {name: true, age: false}};
785+
var fieldsFilter = {
786+
fields: {name: true, age: false},
787+
order: 'sequence',
788+
};
786789
physician.patients(fieldsFilter, function(err, ch) {
787790
if (err) return done(err);
788791
should.exist(ch);
@@ -832,8 +835,16 @@ describe('relations', function() {
832835
if (err) return done(err);
833836
should.exist(ch);
834837
ch.should.have.lengthOf(2);
835-
var resultIdArr = [ch[0].id, ch[1].id];
836-
assert.deepEqual(resultIdArr, idArr);
838+
if (typeof idArr[0] === 'object') {
839+
// mongodb returns `id` as an object
840+
idArr[0] = idArr[0].toString();
841+
idArr[1] = idArr[1].toString();
842+
idArr.indexOf(ch[0].id.toString()).should.not.equal(-1);
843+
idArr.indexOf(ch[1].id.toString()).should.not.equal(-1);
844+
} else {
845+
idArr.indexOf(ch[0].id).should.not.equal(-1);
846+
idArr.indexOf(ch[1].id).should.not.equal(-1);
847+
}
837848
done();
838849
});
839850
});
@@ -888,15 +899,17 @@ describe('relations', function() {
888899

889900
function createSampleData(done) {
890901
Physician.create(function(err, result) {
891-
result.patients.create({name: 'a', age: '10'}, function(err, p) {
892-
samplePatientId = p.id;
893-
result.patients.create({name: 'z', age: '20'}, function() {
894-
result.patients.create({name: 'c'}, function() {
895-
physician = result;
896-
done();
897-
});
902+
result.patients.create({name: 'a', age: '10', sequence: 1},
903+
function(err, p) {
904+
samplePatientId = p.id;
905+
result.patients.create({name: 'z', age: '20', sequence: 2},
906+
function() {
907+
result.patients.create({name: 'c', sequence: 3}, function() {
908+
physician = result;
909+
done();
910+
});
911+
});
898912
});
899-
});
900913
});
901914
};
902915
});

0 commit comments

Comments
 (0)