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

Commit

Permalink
[test] add basic test for concurrentUpdate()
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenarchy committed May 23, 2015
1 parent 9e3045b commit 7459785
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions test/concurrentPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var mongoose = require('mongoose');
var erase = require('mongoose-erase');
var async = require('async');
var should = require('should');

var concurrentPlugin = require('../');

Expand All @@ -12,18 +13,40 @@ describe('concurrentPlugin()', function() {
mongoose, 'mongodb://localhost/concurrentPluginTests'
));

function registerArticleSchema() {
var articleSchema = new mongoose.Schema({
title: String
function registerUserSchema(options) {
var userSchema = new mongoose.Schema({
name: String,
age: Number
});
// register concurrentPlugin
articleSchema.plugin(concurrentPlugin);
return mongoose.model('Article', articleSchema);
userSchema.plugin(concurrentPlugin, options);
return mongoose.model('User', userSchema);
}

it('should use the provided revision field name', function(done) {
var User = registerUserSchema({fieldName: '_rev'});
User.create({name: 'Darth'}, function(err, darth) {
darth.should.have.property('_rev').which.is.exactly(0);
done();
});
});

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

async.waterfall([
function(cb) {
User.create({name: 'Darth', age: 42}, cb);
},
function(darth, cb) {
darth.name = 'Darth Vader';
darth.concurrentUpdate(darth._revision, cb);
}
], function(err, darth) {
if (err) {return done(err);}
darth.should.have.property('_revision').which.is.exactly(1);
done();
});
});

});

0 comments on commit 7459785

Please sign in to comment.