Skip to content
This repository has been archived by the owner on Aug 9, 2018. It is now read-only.

Commit

Permalink
[test] add test for concurrentRemove
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenarchy committed May 24, 2015
1 parent f52c2ab commit 7ba964a
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion test/concurrentPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,59 @@ describe('concurrentPlugin()', function() {
});
});

});
}); // concurrentUpdate()

describe('concurrentRemove()', function() {

it('should allow removing if revision matches', function(done) {
var User = registerUserSchema();

async.waterfall([
function(cb) {
User.create({name: 'Darth', age: 42}, cb);
},
function(darth, cb) {
darth.concurrentRemove(darth._revision, cb);
},
function(darth, cb) {
darth.should.have.properties({
_revision: 0,
name: 'Darth',
age: 42
});
cb();
}
], done);
});

it('should deny removing if revision does not match', function(done) {
var User = registerUserSchema();
var darthOrig;

async.waterfall([
function(cb) {
User.create({name: 'Darth', age: 42}, cb);
},
function(darth, cb) {
darthOrig = darth;
darth.concurrentRemove(darth._revision - 1, cb);
}
], function(err, darth) {
should(err).be.Error;
should.not.exist(darth);
// check if document is unchanged in db
User.findById(darthOrig._id, function(err, darth) {
should.not.exist(err);
darth.should.have.properties({
_revision: 0,
name: 'Darth',
age: 42
});
done();
});
});
});

}); // concurrentRemove()

});

0 comments on commit 7ba964a

Please sign in to comment.