Merge pull request #530 from strongloop/fix/clean-up-delete-and-update-mainipulation-tests
Clean up update/delete manipulation tests
This commit is contained in:
commit
77ff8541cc
|
@ -756,22 +756,30 @@ describe('manipulation', function () {
|
||||||
it('should destroy filtered set of records');
|
it('should destroy filtered set of records');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteAll/destroyAll', function () {
|
describe('when deleteAll/destroyAll executes', function () {
|
||||||
beforeEach(function clearOldData(done) {
|
it('should be defined as function', function() {
|
||||||
|
Person.deleteAll.should.be.a.Function;
|
||||||
|
Person.destroyAll.should.be.a.Function;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with multiple instances in the database', function() {
|
||||||
|
beforeEach(function deleteFixtures(done) {
|
||||||
Person.deleteAll(done);
|
Person.deleteAll(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function createTestData(done) {
|
beforeEach(function createFixtures(done) {
|
||||||
Person.create([
|
Person.create([{
|
||||||
{ name: 'John' },
|
name: 'John'
|
||||||
{ name: 'Jane' }
|
}, {
|
||||||
], done);
|
name: 'Jane'
|
||||||
|
}], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should only delete instances that satisfy the where condition', function (done) {
|
it('should only delete instances that satisfy the where condition',
|
||||||
Person.deleteAll({name: 'John'}, function (err, result) {
|
function(done) {
|
||||||
|
Person.deleteAll({name: 'John'}, function(err, info) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
result.should.have.property('count', 1);
|
info.count.should.equal(1);
|
||||||
Person.find({where: {name: 'John'}}, function(err, data) {
|
Person.find({where: {name: 'John'}}, function(err, data) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
data.should.have.length(0);
|
data.should.have.length(0);
|
||||||
|
@ -784,10 +792,11 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report zero deleted instances', function (done) {
|
it('should report zero deleted instances when no matches are found',
|
||||||
Person.deleteAll({name: 'does-not-match'}, function (err, result) {
|
function(done) {
|
||||||
|
Person.deleteAll({name: 'does-not-match'}, function(err, info) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
result.should.have.property('count', 0);
|
info.count.should.equal(0);
|
||||||
Person.count(function(err, count) {
|
Person.count(function(err, count) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
count.should.equal(2);
|
count.should.equal(2);
|
||||||
|
@ -796,10 +805,11 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete all instances when "where" is not provided', function(done) {
|
it('should delete all instances when the where condition is not provided',
|
||||||
Person.deleteAll(function (err, result) {
|
function(done) {
|
||||||
|
Person.deleteAll(function (err, info) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
result.should.have.property('count', 2);
|
info.count.should.equal(2);
|
||||||
Person.count(function(err, count) {
|
Person.count(function(err, count) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
count.should.equal(0);
|
count.should.equal(0);
|
||||||
|
@ -808,6 +818,7 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('initialize', function () {
|
describe('initialize', function () {
|
||||||
it('should initialize object properly', function () {
|
it('should initialize object properly', function () {
|
||||||
|
@ -1005,8 +1016,14 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('update/updateAll', function() {
|
describe('when update/updateAll executes', function() {
|
||||||
beforeEach(function destroyFixtures(done) {
|
it('should be defined as a function', function() {
|
||||||
|
Person.update.should.be.a.Function;
|
||||||
|
Person.updateAll.should.be.a.Function;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with existing instances in the database', function() {
|
||||||
|
beforeEach(function deleteFixtures(done) {
|
||||||
Person.destroyAll(done);
|
Person.destroyAll(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1029,19 +1046,15 @@ describe('manipulation', function () {
|
||||||
}], done);
|
}], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be a function', function() {
|
|
||||||
Person.update.should.be.a.Function;
|
|
||||||
Person.updateAll.should.be.a.Function;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not update instances that do not satisfy the where condition',
|
it('should not update instances that do not satisfy the where condition',
|
||||||
function(done) {
|
function(done) {
|
||||||
Person.update({name: 'Harry Hoe'}, {name: 'Marta Moe'}, function(err,
|
Person.update({name: 'Harry Hoe'}, {name: 'Marta Moe'}, function(err,
|
||||||
results) {
|
info) {
|
||||||
|
if (err) return done(err);
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
results.should.have.property('count', 0);
|
info.count.should.equal(0);
|
||||||
Person.find({where: {name: 'Harry Hoe'}}, function(err, people) {
|
Person.find({where: {name: 'Harry Hoe'}}, function(err, people) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
people.should.be.empty;
|
people.should.be.empty;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1051,11 +1064,11 @@ describe('manipulation', function () {
|
||||||
it('should update instances that satisfy the where condition',
|
it('should update instances that satisfy the where condition',
|
||||||
function(done) {
|
function(done) {
|
||||||
Person.update({name: 'Brett Boe'}, {name: 'Harry Hoe'}, function(err,
|
Person.update({name: 'Brett Boe'}, {name: 'Harry Hoe'}, function(err,
|
||||||
results) {
|
info) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
results.should.have.property('count', 1);
|
info.count.should.equal(1);
|
||||||
Person.find({where: {age: 19}}, function(err, people) {
|
Person.find({where: {age: 19}}, function(err, people) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
people.should.have.length(1);
|
people.should.have.length(1);
|
||||||
people[0].name.should.equal('Harry Hoe');
|
people[0].name.should.equal('Harry Hoe');
|
||||||
done();
|
done();
|
||||||
|
@ -1065,14 +1078,14 @@ describe('manipulation', function () {
|
||||||
|
|
||||||
it('should update all instances when the where condition is not provided',
|
it('should update all instances when the where condition is not provided',
|
||||||
function(done) {
|
function(done) {
|
||||||
Person.update({name: 'Harry Hoe'}, function(err, results) {
|
Person.update({name: 'Harry Hoe'}, function(err, info) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
results.should.have.property('count', 5);
|
info.count.should.equal(5);
|
||||||
Person.find({where: {name: 'Brett Boe'}}, function(err, people) {
|
Person.find({where: {name: 'Brett Boe'}}, function(err, people) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
people.should.be.empty;
|
people.should.be.empty;
|
||||||
Person.find({where: {name: 'Harry Hoe'}}, function(err, people) {
|
Person.find({where: {name: 'Harry Hoe'}}, function(err, people) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
people.should.have.length(5);
|
people.should.have.length(5);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1083,11 +1096,11 @@ describe('manipulation', function () {
|
||||||
it('should ignore where conditions with undefined values',
|
it('should ignore where conditions with undefined values',
|
||||||
function(done) {
|
function(done) {
|
||||||
Person.update({name: 'Brett Boe'}, {name: undefined, gender: 'male'},
|
Person.update({name: 'Brett Boe'}, {name: undefined, gender: 'male'},
|
||||||
function(err, results) {
|
function(err, info) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
results.should.have.property('count', 1)
|
info.count.should.equal(1);
|
||||||
Person.find({where: {name: 'Brett Boe'}}, function(err, people) {
|
Person.find({where: {name: 'Brett Boe'}}, function(err, people) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
people.should.have.length(1);
|
people.should.have.length(1);
|
||||||
people[0].name.should.equal('Brett Boe');
|
people[0].name.should.equal('Brett Boe');
|
||||||
done();
|
done();
|
||||||
|
@ -1105,3 +1118,4 @@ describe('manipulation', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue