Merge pull request #537 from strongloop/cleanup/update-and-delete-tests

Clean up delete and update tests
This commit is contained in:
Simon Ho 2015-03-24 21:40:46 -07:00
commit b5188a5af4
1 changed files with 130 additions and 135 deletions

View File

@ -757,17 +757,11 @@ describe('manipulation', function () {
});
describe('deleteAll/destroyAll', function () {
it('should be defined as function', function() {
Person.deleteAll.should.be.a.Function;
Person.destroyAll.should.be.a.Function;
});
context('with multiple instances in the database', function() {
beforeEach(function deleteFixtures(done) {
beforeEach(function clearOldData(done) {
Person.deleteAll(done);
});
beforeEach(function createFixtures(done) {
beforeEach(function createTestData(done) {
Person.create([{
name: 'John'
}, {
@ -775,11 +769,16 @@ describe('manipulation', function () {
}], done);
});
it('should be defined as function', function() {
Person.deleteAll.should.be.a.Function;
Person.destroyAll.should.be.a.Function;
});
it('should only delete instances that satisfy the where condition',
function(done) {
Person.deleteAll({name: 'John'}, function(err, info) {
if (err) return done(err);
info.count.should.equal(1);
info.should.have.property('count', 1);
Person.find({where: {name: 'John'}}, function(err, data) {
if (err) return done(err);
data.should.have.length(0);
@ -796,7 +795,7 @@ describe('manipulation', function () {
function(done) {
Person.deleteAll({name: 'does-not-match'}, function(err, info) {
if (err) return done(err);
info.count.should.equal(0);
info.should.have.property('count', 0);
Person.count(function(err, count) {
if (err) return done(err);
count.should.equal(2);
@ -809,7 +808,7 @@ describe('manipulation', function () {
function(done) {
Person.deleteAll(function (err, info) {
if (err) return done(err);
info.count.should.equal(2);
info.should.have.property('count', 2);
Person.count(function(err, count) {
if (err) return done(err);
count.should.equal(0);
@ -818,7 +817,6 @@ describe('manipulation', function () {
});
});
});
});
describe('initialize', function () {
it('should initialize object properly', function () {
@ -1017,17 +1015,11 @@ describe('manipulation', function () {
});
describe('update/updateAll', function() {
it('should be defined as a function', function() {
Person.update.should.be.a.Function;
Person.updateAll.should.be.a.Function;
});
context('with multiple instances in the database', function() {
beforeEach(function deleteFixtures(done) {
beforeEach(function clearOldData(done) {
Person.destroyAll(done);
});
beforeEach(function createFixtures(done) {
beforeEach(function createTestData(done) {
Person.create([{
name: 'Brett Boe',
age: 19
@ -1046,13 +1038,17 @@ describe('manipulation', function () {
}], done);
});
it('should be defined as 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',
function(done) {
Person.update({name: 'Harry Hoe'}, {name: 'Marta Moe'}, function(err,
info) {
if (err) return done(err);
should.not.exist(err);
info.count.should.equal(0);
info.should.have.property('count', 0);
Person.find({where: {name: 'Harry Hoe'}}, function(err, people) {
if (err) return done(err);
people.should.be.empty;
@ -1066,7 +1062,7 @@ describe('manipulation', function () {
Person.update({name: 'Brett Boe'}, {name: 'Harry Hoe'}, function(err,
info) {
if (err) return done(err);
info.count.should.equal(1);
info.should.have.property('count', 1);
Person.find({where: {age: 19}}, function(err, people) {
if (err) return done(err);
people.should.have.length(1);
@ -1080,7 +1076,7 @@ describe('manipulation', function () {
function(done) {
Person.update({name: 'Harry Hoe'}, function(err, info) {
if (err) return done(err);
info.count.should.equal(5);
info.should.have.property('count', 5);
Person.find({where: {name: 'Brett Boe'}}, function(err, people) {
if (err) return done(err);
people.should.be.empty;
@ -1098,7 +1094,7 @@ describe('manipulation', function () {
Person.update({name: 'Brett Boe'}, {name: undefined, gender: 'male'},
function(err, info) {
if (err) return done(err);
info.count.should.equal(1);
info.should.have.property('count', 1);
Person.find({where: {name: 'Brett Boe'}}, function(err, people) {
if (err) return done(err);
people.should.have.length(1);
@ -1117,5 +1113,4 @@ describe('manipulation', function () {
});
});
});
});
});