Run juggler tests for Cloudant (#1414)

This commit is contained in:
Janny 2017-07-11 14:56:39 -04:00 committed by GitHub
parent 5da8170d9e
commit b9129e6973
5 changed files with 122 additions and 108 deletions

View File

@ -51,7 +51,6 @@ describe('basic-querying', function() {
connectorCapabilities.geoPoint = (db.adapter.name != 'dashdb') && (db.adapter.name != 'db2') && connectorCapabilities.geoPoint = (db.adapter.name != 'dashdb') && (db.adapter.name != 'db2') &&
(db.adapter.name != 'informix') && (db.adapter.name != 'cassandra'); (db.adapter.name != 'informix') && (db.adapter.name != 'cassandra');
if (connectorCapabilities.geoPoint) userModelDef.addressLoc = {type: 'GeoPoint'}; if (connectorCapabilities.geoPoint) userModelDef.addressLoc = {type: 'GeoPoint'};
User = db.define('User', userModelDef); User = db.define('User', userModelDef);
db.automigrate(done); db.automigrate(done);
}); });
@ -387,15 +386,16 @@ describe('basic-querying', function() {
}); });
}); });
it('should support date "lt" that is satisfied', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
User.find({where: {birthday: {'lt': new Date('1980-12-07')}, 'should support date "lt" that is satisfied', function(done) {
}}, function(err, users) { User.find({where: {birthday: {'lt': new Date('1980-12-07')},
should.not.exist(err); }}, function(err, users) {
users.should.have.property('length', 1); should.not.exist(err);
users[0].name.should.equal('Paul McCartney'); users.should.have.property('length', 1);
done(); users[0].name.should.equal('Paul McCartney');
done();
});
}); });
});
it('should support number "gte" that is satisfied', function(done) { it('should support number "gte" that is satisfied', function(done) {
User.find({where: {order: {'gte': 3}}}, function(err, users) { User.find({where: {order: {'gte': 3}}}, function(err, users) {
@ -464,16 +464,17 @@ describe('basic-querying', function() {
}); });
}); });
it('should support string "gte" that is satisfied', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
User.find({where: {name: {'gte': 'Paul McCartney'}}}, function(err, users) { 'should support string "gte" that is satisfied', function(done) {
should.not.exist(err); User.find({where: {name: {'gte': 'Paul McCartney'}}}, function(err, users) {
users.should.have.property('length', 4); should.not.exist(err);
for (var ix = 0; ix < users.length; ix++) { users.should.have.property('length', 4);
users[ix].name.should.be.greaterThanOrEqual('Paul McCartney'); for (var ix = 0; ix < users.length; ix++) {
} users[ix].name.should.be.greaterThanOrEqual('Paul McCartney');
done(); }
done();
});
}); });
});
it('should support string "gt" that is not satisfied', function(done) { it('should support string "gt" that is not satisfied', function(done) {
User.find({where: {name: {'gt': 'xyz'}, User.find({where: {name: {'gt': 'xyz'},
@ -484,29 +485,31 @@ describe('basic-querying', function() {
}); });
}); });
it('should support string "gt" that is satisfied', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
User.find({where: {name: {'gt': 'Paul McCartney'}, 'should support string "gt" that is satisfied', function(done) {
}}, function(err, users) { User.find({where: {name: {'gt': 'Paul McCartney'},
should.not.exist(err); }}, function(err, users) {
users.should.have.property('length', 3); should.not.exist(err);
for (var ix = 0; ix < users.length; ix++) { users.should.have.property('length', 3);
users[ix].name.should.be.greaterThan('Paul McCartney'); for (var ix = 0; ix < users.length; ix++) {
} users[ix].name.should.be.greaterThan('Paul McCartney');
done(); }
done();
});
}); });
});
it('should support string "lt" that is satisfied', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
User.find({where: {name: {'lt': 'Paul McCartney'}, 'should support string "lt" that is satisfied', function(done) {
}}, function(err, users) { User.find({where: {name: {'lt': 'Paul McCartney'},
should.not.exist(err); }}, function(err, users) {
users.should.have.property('length', 2); should.not.exist(err);
for (var ix = 0; ix < users.length; ix++) { users.should.have.property('length', 2);
users[ix].name.should.be.lessThan('Paul McCartney'); for (var ix = 0; ix < users.length; ix++) {
} users[ix].name.should.be.lessThan('Paul McCartney');
done(); }
done();
});
}); });
});
it('should support boolean "gte" that is satisfied', function(done) { it('should support boolean "gte" that is satisfied', function(done) {
User.find({where: {vip: {'gte': true}, User.find({where: {vip: {'gte': true},
@ -880,8 +883,10 @@ describe('basic-querying', function() {
}); });
}); });
it('should support nested property for order in query', function(done) { bdd.itIf(connectorCapabilities.adhocSort,
User.find({where: {'address.state': 'CA'}, order: 'address.city DESC'}, 'should support nested property for order in query',
function(done) {
User.find({where: {'address.state': 'CA'}, order: 'address.city DESC'},
function(err, users) { function(err, users) {
if (err) return done(err); if (err) return done(err);
users.length.should.be.equal(2); users.length.should.be.equal(2);
@ -889,7 +894,7 @@ describe('basic-querying', function() {
users[1].address.city.should.be.eql('San Jose'); users[1].address.city.should.be.eql('San Jose');
done(); done();
}); });
}); });
it('should support multi-level nested array property in query', function(done) { it('should support multi-level nested array property in query', function(done) {
User.find({where: {'address.tags.tag': 'business'}}, function(err, users) { User.find({where: {'address.tags.tag': 'business'}}, function(err, users) {
@ -937,16 +942,17 @@ describe('basic-querying', function() {
describe('findOne', function() { describe('findOne', function() {
before(seed); before(seed);
it('should find first record (default sort by id)', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
User.all({order: 'id'}, function(err, users) { 'should find first record (default sort by id)', function(done) {
User.findOne(function(e, u) { User.all({order: 'id'}, function(err, users) {
should.not.exist(e); User.findOne(function(e, u) {
should.exist(u); should.not.exist(e);
u.id.toString().should.equal(users[0].id.toString()); should.exist(u);
done(); u.id.toString().should.equal(users[0].id.toString());
done();
});
}); });
}); });
});
bdd.itIf(connectorCapabilities.adhocSort, 'should find first record', function(done) { bdd.itIf(connectorCapabilities.adhocSort, 'should find first record', function(done) {
User.findOne({order: 'order'}, function(e, u) { User.findOne({order: 'order'}, function(e, u) {

View File

@ -175,6 +175,7 @@ describe('datatypes', function() {
describe('model option persistUndefinedAsNull', function() { describe('model option persistUndefinedAsNull', function() {
var TestModel, isStrict; var TestModel, isStrict;
before(function(done) { before(function(done) {
db = getSchema();
TestModel = db.define( TestModel = db.define(
'TestModel', 'TestModel',
{ {

View File

@ -84,42 +84,44 @@ describe('include', function() {
}); });
}); });
it('should not save in db included models, in query returned models', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
const originalStrict = User.definition.settings.strict; 'should not save in db included models, in query returned models',
User.definition.settings.strict = true; // Change to test regression for issue #1252 function(done) {
const finish = (err) => { const originalStrict = User.definition.settings.strict;
// Restore original user strict property User.definition.settings.strict = true; // Change to test regression for issue #1252
User.definition.settings.strict = originalStrict; const finish = (err) => {
done(err); // Restore original user strict property
}; User.definition.settings.strict = originalStrict;
User.findOne({where: {name: 'User A'}, include: 'posts'}, function(err, user) { done(err);
if (err) return finish(err); };
if (!user) return finish(new Error('User Not found to check relation not saved')); User.findOne({where: {name: 'User A'}, include: 'posts'}, function(err, user) {
user.save(function(err) { // save the returned user
if (err) return finish(err); if (err) return finish(err);
// should not store in db the posts if (!user) return finish(new Error('User Not found to check relation not saved'));
var dsName = User.dataSource.name; user.save(function(err) { // save the returned user
if (dsName === 'memory') { if (err) return finish(err);
JSON.parse(User.dataSource.adapter.cache.User[1]).should.not.have.property('posts'); // should not store in db the posts
finish(); var dsName = User.dataSource.name;
} else if (dsName === 'mongodb') { // Check native mongodb connector if (dsName === 'memory') {
JSON.parse(User.dataSource.adapter.cache.User[1]).should.not.have.property('posts');
finish();
} else if (dsName === 'mongodb') { // Check native mongodb connector
// get hold of native mongodb collection // get hold of native mongodb collection
var dbCollection = User.dataSource.connector.collection(User.modelName); var dbCollection = User.dataSource.connector.collection(User.modelName);
dbCollection.findOne({_id: user.id}) dbCollection.findOne({_id: user.id})
.then(function(foundUser) { .then(function(foundUser) {
if (!foundUser) { if (!foundUser) {
finish(new Error('User not found to check posts not saved')); finish(new Error('User not found to check posts not saved'));
} }
foundUser.should.not.have.property('posts'); foundUser.should.not.have.property('posts');
finish(); finish();
}) })
.catch(finish); .catch(finish);
} else { // TODO make native checks for other connectors as well } else { // TODO make native checks for other connectors as well
finish(); finish();
} }
});
}); });
}); });
});
it('should fetch Passport - Owner - Posts', function(done) { it('should fetch Passport - Owner - Posts', function(done) {
Passport.find({include: {owner: 'posts'}}, function(err, passports) { Passport.find({include: {owner: 'posts'}}, function(err, passports) {
@ -309,7 +311,7 @@ describe('include', function() {
}); });
}); });
bdd.itIf(connectorCapabilities.adhocSort === false, bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
'should support limit - no sort', function(done) { 'should support limit - no sort', function(done) {
Passport.find({ Passport.find({
include: { include: {

View File

@ -398,6 +398,7 @@ describe('manipulation', function() {
}); });
it('should save existing object', function(done) { it('should save existing object', function(done) {
// Cloudant could not guarantee findOne always return the same item
Person.findOne(function(err, p) { Person.findOne(function(err, p) {
if (err) return done(err); if (err) return done(err);
p.name = 'Hans'; p.name = 'Hans';
@ -414,6 +415,7 @@ describe('manipulation', function() {
}); });
it('should save existing object (promise variant)', function(done) { it('should save existing object (promise variant)', function(done) {
// Cloudant could not guarantee findOne always return the same item
Person.findOne() Person.findOne()
.then(function(p) { .then(function(p) {
p.name = 'Fritz'; p.name = 'Fritz';

View File

@ -572,7 +572,8 @@ describe('relations', function() {
before(function(done) { before(function(done) {
Physician = db.define('Physician', {name: String}); Physician = db.define('Physician', {name: String});
Patient = db.define('Patient', {name: String, age: Number, sequence: Number}); Patient = db.define('Patient', {name: String, age: Number,
sequence: {type: Number, index: true}});
Appointment = db.define('Appointment', {date: {type: Date, Appointment = db.define('Appointment', {date: {type: Date,
default: function() { default: function() {
return new Date(); return new Date();
@ -2933,26 +2934,27 @@ describe('relations', function() {
}); });
}); });
it('should find polymorphic items - article', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
if (!article) return done(); 'should find polymorphic items - article', function(done) {
Article.findById(article.id, function(err, article) { if (!article) return done();
article.pictures(function(err, pics) { Article.findById(article.id, function(err, article) {
// If deleteWithOtherThanId is not implemented, the above test is skipped and article.pictures(function(err, pics) {
// the remove did not take place. Thus +1. // If deleteWithOtherThanId is not implemented, the above test is skipped and
var expectedLength = connectorCapabilities.deleteWithOtherThanId !== false ? // the remove did not take place. Thus +1.
var expectedLength = connectorCapabilities.deleteWithOtherThanId !== false ?
2 : 3; 2 : 3;
pics.should.have.length(expectedLength); pics.should.have.length(expectedLength);
const names = pics.map(p => p.name); const names = pics.map(p => p.name);
if (connectorCapabilities.adhocSort !== false) { if (connectorCapabilities.adhocSort !== false) {
names.should.eql(['Article Pic 1', 'Article Pic 2']); names.should.eql(['Article Pic 1', 'Article Pic 2']);
} else { } else {
names.should.containDeep(['Article Pic 1', 'Article Pic 2', 'Example']); names.should.containDeep(['Article Pic 1', 'Article Pic 2', 'Example']);
} }
done(); done();
});
}); });
}); });
});
it('should check if polymorphic relation exists - article', function(done) { it('should check if polymorphic relation exists - article', function(done) {
if (!article) return done(); if (!article) return done();
@ -3821,17 +3823,18 @@ describe('relations', function() {
}); });
}); });
it('should get the related item on scope - verify', function(done) { bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
Supplier.findById(supplierId, function(e, supplier) { 'should get the related item on scope - verify', function(done) {
should.not.exist(e); Supplier.findById(supplierId, function(e, supplier) {
should.exist(supplier);
supplier.account(function(err, act) {
should.not.exist(e); should.not.exist(e);
should.not.exist(act); should.exist(supplier);
done(); supplier.account(function(err, act) {
should.not.exist(e);
should.not.exist(act);
done();
});
}); });
}); });
});
it('should have deleted related item', function(done) { it('should have deleted related item', function(done) {
Supplier.findById(supplierId, function(e, supplier) { Supplier.findById(supplierId, function(e, supplier) {
@ -3874,7 +3877,7 @@ describe('relations', function() {
companyBoardId = companyBoard.id; companyBoardId = companyBoard.id;
should.not.exist(e); should.not.exist(e);
should.exist(companyBoard); should.exist(companyBoard);
companyBoard.boss.create({id: 'a01'}, function(err, account) { companyBoard.boss.create({id: 'bossa01'}, function(err, account) {
companyBoard.boss(function(e, boss) { companyBoard.boss(function(e, boss) {
bossId = boss.id; bossId = boss.id;
should.not.exist(e); should.not.exist(e);