Run juggler tests for Cloudant (#1414)
This commit is contained in:
parent
5da8170d9e
commit
b9129e6973
|
@ -51,7 +51,6 @@ describe('basic-querying', function() {
|
|||
connectorCapabilities.geoPoint = (db.adapter.name != 'dashdb') && (db.adapter.name != 'db2') &&
|
||||
(db.adapter.name != 'informix') && (db.adapter.name != 'cassandra');
|
||||
if (connectorCapabilities.geoPoint) userModelDef.addressLoc = {type: 'GeoPoint'};
|
||||
|
||||
User = db.define('User', userModelDef);
|
||||
db.automigrate(done);
|
||||
});
|
||||
|
@ -387,15 +386,16 @@ describe('basic-querying', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support date "lt" that is satisfied', function(done) {
|
||||
User.find({where: {birthday: {'lt': new Date('1980-12-07')},
|
||||
}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 1);
|
||||
users[0].name.should.equal('Paul McCartney');
|
||||
done();
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should support date "lt" that is satisfied', function(done) {
|
||||
User.find({where: {birthday: {'lt': new Date('1980-12-07')},
|
||||
}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 1);
|
||||
users[0].name.should.equal('Paul McCartney');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support number "gte" that is satisfied', function(done) {
|
||||
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) {
|
||||
User.find({where: {name: {'gte': 'Paul McCartney'}}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 4);
|
||||
for (var ix = 0; ix < users.length; ix++) {
|
||||
users[ix].name.should.be.greaterThanOrEqual('Paul McCartney');
|
||||
}
|
||||
done();
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should support string "gte" that is satisfied', function(done) {
|
||||
User.find({where: {name: {'gte': 'Paul McCartney'}}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 4);
|
||||
for (var ix = 0; ix < users.length; ix++) {
|
||||
users[ix].name.should.be.greaterThanOrEqual('Paul McCartney');
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support string "gt" that is not satisfied', function(done) {
|
||||
User.find({where: {name: {'gt': 'xyz'},
|
||||
|
@ -484,29 +485,31 @@ describe('basic-querying', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support string "gt" that is satisfied', function(done) {
|
||||
User.find({where: {name: {'gt': 'Paul McCartney'},
|
||||
}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 3);
|
||||
for (var ix = 0; ix < users.length; ix++) {
|
||||
users[ix].name.should.be.greaterThan('Paul McCartney');
|
||||
}
|
||||
done();
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should support string "gt" that is satisfied', function(done) {
|
||||
User.find({where: {name: {'gt': 'Paul McCartney'},
|
||||
}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 3);
|
||||
for (var ix = 0; ix < users.length; ix++) {
|
||||
users[ix].name.should.be.greaterThan('Paul McCartney');
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support string "lt" that is satisfied', function(done) {
|
||||
User.find({where: {name: {'lt': 'Paul McCartney'},
|
||||
}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 2);
|
||||
for (var ix = 0; ix < users.length; ix++) {
|
||||
users[ix].name.should.be.lessThan('Paul McCartney');
|
||||
}
|
||||
done();
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should support string "lt" that is satisfied', function(done) {
|
||||
User.find({where: {name: {'lt': 'Paul McCartney'},
|
||||
}}, function(err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 2);
|
||||
for (var ix = 0; ix < users.length; ix++) {
|
||||
users[ix].name.should.be.lessThan('Paul McCartney');
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support boolean "gte" that is satisfied', function(done) {
|
||||
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) {
|
||||
User.find({where: {'address.state': 'CA'}, order: 'address.city DESC'},
|
||||
bdd.itIf(connectorCapabilities.adhocSort,
|
||||
'should support nested property for order in query',
|
||||
function(done) {
|
||||
User.find({where: {'address.state': 'CA'}, order: 'address.city DESC'},
|
||||
function(err, users) {
|
||||
if (err) return done(err);
|
||||
users.length.should.be.equal(2);
|
||||
|
@ -889,7 +894,7 @@ describe('basic-querying', function() {
|
|||
users[1].address.city.should.be.eql('San Jose');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should support multi-level nested array property in query', function(done) {
|
||||
User.find({where: {'address.tags.tag': 'business'}}, function(err, users) {
|
||||
|
@ -937,16 +942,17 @@ describe('basic-querying', function() {
|
|||
describe('findOne', function() {
|
||||
before(seed);
|
||||
|
||||
it('should find first record (default sort by id)', function(done) {
|
||||
User.all({order: 'id'}, function(err, users) {
|
||||
User.findOne(function(e, u) {
|
||||
should.not.exist(e);
|
||||
should.exist(u);
|
||||
u.id.toString().should.equal(users[0].id.toString());
|
||||
done();
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should find first record (default sort by id)', function(done) {
|
||||
User.all({order: 'id'}, function(err, users) {
|
||||
User.findOne(function(e, u) {
|
||||
should.not.exist(e);
|
||||
should.exist(u);
|
||||
u.id.toString().should.equal(users[0].id.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.itIf(connectorCapabilities.adhocSort, 'should find first record', function(done) {
|
||||
User.findOne({order: 'order'}, function(e, u) {
|
||||
|
|
|
@ -175,6 +175,7 @@ describe('datatypes', function() {
|
|||
describe('model option persistUndefinedAsNull', function() {
|
||||
var TestModel, isStrict;
|
||||
before(function(done) {
|
||||
db = getSchema();
|
||||
TestModel = db.define(
|
||||
'TestModel',
|
||||
{
|
||||
|
|
|
@ -84,42 +84,44 @@ describe('include', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should not save in db included models, in query returned models', function(done) {
|
||||
const originalStrict = User.definition.settings.strict;
|
||||
User.definition.settings.strict = true; // Change to test regression for issue #1252
|
||||
const finish = (err) => {
|
||||
// Restore original user strict property
|
||||
User.definition.settings.strict = originalStrict;
|
||||
done(err);
|
||||
};
|
||||
User.findOne({where: {name: 'User A'}, include: 'posts'}, function(err, user) {
|
||||
if (err) return finish(err);
|
||||
if (!user) return finish(new Error('User Not found to check relation not saved'));
|
||||
user.save(function(err) { // save the returned user
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should not save in db included models, in query returned models',
|
||||
function(done) {
|
||||
const originalStrict = User.definition.settings.strict;
|
||||
User.definition.settings.strict = true; // Change to test regression for issue #1252
|
||||
const finish = (err) => {
|
||||
// Restore original user strict property
|
||||
User.definition.settings.strict = originalStrict;
|
||||
done(err);
|
||||
};
|
||||
User.findOne({where: {name: 'User A'}, include: 'posts'}, function(err, user) {
|
||||
if (err) return finish(err);
|
||||
// should not store in db the posts
|
||||
var dsName = User.dataSource.name;
|
||||
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
|
||||
if (!user) return finish(new Error('User Not found to check relation not saved'));
|
||||
user.save(function(err) { // save the returned user
|
||||
if (err) return finish(err);
|
||||
// should not store in db the posts
|
||||
var dsName = User.dataSource.name;
|
||||
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
|
||||
var dbCollection = User.dataSource.connector.collection(User.modelName);
|
||||
dbCollection.findOne({_id: user.id})
|
||||
.then(function(foundUser) {
|
||||
if (!foundUser) {
|
||||
finish(new Error('User not found to check posts not saved'));
|
||||
}
|
||||
foundUser.should.not.have.property('posts');
|
||||
finish();
|
||||
})
|
||||
.catch(finish);
|
||||
} else { // TODO make native checks for other connectors as well
|
||||
finish();
|
||||
}
|
||||
var dbCollection = User.dataSource.connector.collection(User.modelName);
|
||||
dbCollection.findOne({_id: user.id})
|
||||
.then(function(foundUser) {
|
||||
if (!foundUser) {
|
||||
finish(new Error('User not found to check posts not saved'));
|
||||
}
|
||||
foundUser.should.not.have.property('posts');
|
||||
finish();
|
||||
})
|
||||
.catch(finish);
|
||||
} else { // TODO make native checks for other connectors as well
|
||||
finish();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch Passport - Owner - Posts', function(done) {
|
||||
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) {
|
||||
Passport.find({
|
||||
include: {
|
||||
|
|
|
@ -398,6 +398,7 @@ describe('manipulation', function() {
|
|||
});
|
||||
|
||||
it('should save existing object', function(done) {
|
||||
// Cloudant could not guarantee findOne always return the same item
|
||||
Person.findOne(function(err, p) {
|
||||
if (err) return done(err);
|
||||
p.name = 'Hans';
|
||||
|
@ -414,6 +415,7 @@ describe('manipulation', function() {
|
|||
});
|
||||
|
||||
it('should save existing object (promise variant)', function(done) {
|
||||
// Cloudant could not guarantee findOne always return the same item
|
||||
Person.findOne()
|
||||
.then(function(p) {
|
||||
p.name = 'Fritz';
|
||||
|
|
|
@ -572,7 +572,8 @@ describe('relations', function() {
|
|||
|
||||
before(function(done) {
|
||||
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,
|
||||
default: function() {
|
||||
return new Date();
|
||||
|
@ -2933,26 +2934,27 @@ describe('relations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should find polymorphic items - article', function(done) {
|
||||
if (!article) return done();
|
||||
Article.findById(article.id, function(err, article) {
|
||||
article.pictures(function(err, pics) {
|
||||
// If deleteWithOtherThanId is not implemented, the above test is skipped and
|
||||
// the remove did not take place. Thus +1.
|
||||
var expectedLength = connectorCapabilities.deleteWithOtherThanId !== false ?
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should find polymorphic items - article', function(done) {
|
||||
if (!article) return done();
|
||||
Article.findById(article.id, function(err, article) {
|
||||
article.pictures(function(err, pics) {
|
||||
// If deleteWithOtherThanId is not implemented, the above test is skipped and
|
||||
// the remove did not take place. Thus +1.
|
||||
var expectedLength = connectorCapabilities.deleteWithOtherThanId !== false ?
|
||||
2 : 3;
|
||||
pics.should.have.length(expectedLength);
|
||||
pics.should.have.length(expectedLength);
|
||||
|
||||
const names = pics.map(p => p.name);
|
||||
if (connectorCapabilities.adhocSort !== false) {
|
||||
names.should.eql(['Article Pic 1', 'Article Pic 2']);
|
||||
} else {
|
||||
names.should.containDeep(['Article Pic 1', 'Article Pic 2', 'Example']);
|
||||
}
|
||||
done();
|
||||
const names = pics.map(p => p.name);
|
||||
if (connectorCapabilities.adhocSort !== false) {
|
||||
names.should.eql(['Article Pic 1', 'Article Pic 2']);
|
||||
} else {
|
||||
names.should.containDeep(['Article Pic 1', 'Article Pic 2', 'Example']);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should check if polymorphic relation exists - article', function(done) {
|
||||
if (!article) return done();
|
||||
|
@ -3821,17 +3823,18 @@ describe('relations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should get the related item on scope - verify', function(done) {
|
||||
Supplier.findById(supplierId, function(e, supplier) {
|
||||
should.not.exist(e);
|
||||
should.exist(supplier);
|
||||
supplier.account(function(err, act) {
|
||||
bdd.itIf(connectorCapabilities.cloudantCompatible !== false,
|
||||
'should get the related item on scope - verify', function(done) {
|
||||
Supplier.findById(supplierId, function(e, supplier) {
|
||||
should.not.exist(e);
|
||||
should.not.exist(act);
|
||||
done();
|
||||
should.exist(supplier);
|
||||
supplier.account(function(err, act) {
|
||||
should.not.exist(e);
|
||||
should.not.exist(act);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should have deleted related item', function(done) {
|
||||
Supplier.findById(supplierId, function(e, supplier) {
|
||||
|
@ -3874,7 +3877,7 @@ describe('relations', function() {
|
|||
companyBoardId = companyBoard.id;
|
||||
should.not.exist(e);
|
||||
should.exist(companyBoard);
|
||||
companyBoard.boss.create({id: 'a01'}, function(err, account) {
|
||||
companyBoard.boss.create({id: 'bossa01'}, function(err, account) {
|
||||
companyBoard.boss(function(e, boss) {
|
||||
bossId = boss.id;
|
||||
should.not.exist(e);
|
||||
|
|
Loading…
Reference in New Issue