Merge pull request #1087 from strongloop/fix-bson-object-id-errors-for-ci

Fix BSON Object ID errors for CI
This commit is contained in:
Simon Ho 2016-09-08 14:28:09 -07:00 committed by GitHub
commit 664a7dfcd4
2 changed files with 43 additions and 34 deletions

View File

@ -269,9 +269,10 @@ describe('include', function() {
if (err) return done(err); if (err) return done(err);
var passport = user.passports()[0]; var passport = user.passports()[0];
passport.id.should.equal(1); // eql instead of equal because mongo uses object id type
passport.ownerId.should.equal(1); passport.id.should.eql(createdPassports[0].id);
passport.number.should.equal('1'); passport.ownerId.should.eql(createdPassports[0].ownerId);
passport.number.should.eql(createdPassports[0].number);
done(); done();
}); });
@ -284,8 +285,8 @@ describe('include', function() {
scope: { scope: {
where: { where: {
and: [ and: [
{id: 1}, {id: createdPosts[0].id},
{userId: 1}, {userId: createdPosts[0].userId},
{title: 'Post A'}, {title: 'Post A'},
], ],
}, },
@ -296,13 +297,14 @@ describe('include', function() {
user.name.should.equal('User A'); user.name.should.equal('User A');
user.age.should.equal(21); user.age.should.equal(21);
user.id.should.equal(1); user.id.should.eql(createdUsers[0].id);
var posts = user.posts(); var posts = user.posts();
posts.length.should.equal(1); posts.length.should.equal(1);
var post = posts[0]; var post = posts[0];
post.title.should.equal('Post A'); post.title.should.equal('Post A');
post.userId.should.equal(1); // eql instead of equal because mongo uses object id type
post.id.should.equal(1); post.userId.should.eql(createdPosts[0].userId);
post.id.should.eql(createdPosts[0].id);
done(); done();
}); });
@ -337,7 +339,7 @@ describe('include', function() {
if (err) return done(err); if (err) return done(err);
var ids = user.posts().map(function(p) { return p.id; }); var ids = user.posts().map(function(p) { return p.id; });
ids.should.eql([2, 3]); ids.should.eql([createdPosts[1].id, createdPosts[2].id]);
done(); done();
}); });
@ -355,7 +357,7 @@ describe('include', function() {
if (err) return done(err); if (err) return done(err);
var ids = user.posts().map(function(p) { return p.id; }); var ids = user.posts().map(function(p) { return p.id; });
ids.should.eql([2, 3]); ids.should.eql([createdPosts[1].id, createdPosts[2].id]);
done(); done();
}); });
@ -368,7 +370,11 @@ describe('include', function() {
var posts = user.posts(); var posts = user.posts();
var ids = posts.map(function(p) { return p.id; }); var ids = posts.map(function(p) { return p.id; });
ids.should.eql([1, 2, 3]); ids.should.eql([
createdPosts[0].id,
createdPosts[1].id,
createdPosts[2].id,
]);
done(); done();
}); });
@ -428,11 +434,13 @@ describe('include', function() {
user.name.should.equal('User A'); user.name.should.equal('User A');
user.age.should.equal(21); user.age.should.equal(21);
user.id.should.equal(1); // eql instead of equal because mongo uses object id type
user.id.should.eql(createdUsers[0].id);
var profile = user.profile(); var profile = user.profile();
profile.profileName.should.equal('Profile A'); profile.profileName.should.equal('Profile A');
profile.userId.should.equal(1); // eql instead of equal because mongo uses object id type
profile.id.should.equal(1); profile.userId.should.eql(createdProfiles[0].userId);
profile.id.should.eql(createdProfiles[0].id);
done(); done();
}); });
@ -444,7 +452,8 @@ describe('include', function() {
user.name.should.equal('User A'); user.name.should.equal('User A');
user.age.should.equal(21); user.age.should.equal(21);
user.id.should.equal(1); // eql instead of equal because mongo uses object id type
user.id.should.eql(createdUsers[0].id);
user.posts().length.should.equal(3); user.posts().length.should.equal(3);
done(); done();
@ -478,18 +487,18 @@ describe('include', function() {
patient.address(address); patient.address(address);
patient.save(function() { patient.save(function() {
physician.patients({include: 'address'}, physician.patients({include: 'address'},
function(err, posts) { function(err, patients) {
if (err) return done(err); if (err) return done(err);
posts.should.be.an.instanceOf(Array).and.have.length(1); patients.should.have.length(1);
var p = posts[0]; var p = patients[0];
p.name.should.equal('a'); p.name.should.equal('a');
p.addressId.should.equal(1); p.addressId.should.eql(patient.addressId);
p.address().id.should.equal(1); p.address().id.should.eql(address.id);
p.address().name.should.equal('z'); p.address().name.should.equal('z');
done(); done();
}); });
}); });
}); });
}); });
@ -502,12 +511,12 @@ describe('include', function() {
if (err) return done(err); if (err) return done(err);
profile.profileName.should.equal('Profile A'); profile.profileName.should.equal('Profile A');
profile.userId.should.equal(1); profile.userId.should.eql(createdProfiles[0].userId);
profile.id.should.equal(1); profile.id.should.eql(createdProfiles[0].id);
var user = profile.user(); var user = profile.user();
user.name.should.equal('User A'); user.name.should.equal('User A');
user.age.should.equal(21); user.age.should.equal(21);
user.id.should.equal(1); user.id.should.eql(createdUsers[0].id);
done(); done();
}); });
@ -946,6 +955,10 @@ describe('include', function() {
}); });
}); });
var createdUsers = [];
var createdPassports = [];
var createdProfiles = [];
var createdPosts = [];
function setup(done) { function setup(done) {
db = getSchema(); db = getSchema();
City = db.define('City'); City = db.define('City');
@ -991,10 +1004,6 @@ function setup(done) {
Part.hasAndBelongsToMany(Assembly); Part.hasAndBelongsToMany(Assembly);
db.automigrate(function() { db.automigrate(function() {
var createdUsers = [];
var createdPassports = [];
var createdProfiles = [];
var createdPosts = [];
createUsers(); createUsers();
function createUsers() { function createUsers() {
clearAndCreate( clearAndCreate(

View File

@ -1119,7 +1119,7 @@ describe('manipulation', function() {
p.replaceAttributes({title: 'b'}, function(err, data) { p.replaceAttributes({title: 'b'}, function(err, data) {
if (err) return done(err); if (err) return done(err);
Post._warned.cannotOverwritePKInBeforeSaveHook.should.equal(true); Post._warned.cannotOverwritePKInBeforeSaveHook.should.equal(true);
data.id.should.equal(postInstance.id); data.id.should.eql(postInstance.id);
done(); done();
}); });
}); });
@ -1154,7 +1154,7 @@ describe('manipulation', function() {
p.replaceAttributes({title: 'b'}, function(err, data) { p.replaceAttributes({title: 'b'}, function(err, data) {
if (err) return done(err); if (err) return done(err);
Post._warned.cannotOverwritePKInLoadedHook.should.equal(true); Post._warned.cannotOverwritePKInLoadedHook.should.equal(true);
data.id.should.equal(postInstance.id); data.id.should.eql(postInstance.id);
done(); done();
}); });
}); });