diff --git a/core/test/integration/model/model_users_spec.js b/core/test/integration/model/model_users_spec.js index d65320e35f..6ae7fc51b8 100644 --- a/core/test/integration/model/model_users_spec.js +++ b/core/test/integration/model/model_users_spec.js @@ -5,9 +5,11 @@ var testUtils = require('../../utils'), when = require('when'), sinon = require('sinon'), uuid = require('node-uuid'), + _ = require('lodash'), // Stuff we are testing UserModel = require('../../../server/models').User, + RoleModel = require('../../../server/models').Role, context = testUtils.context.admin, sandbox = sinon.sandbox.create(); @@ -125,7 +127,7 @@ describe('User Model', function run() { }); describe('Basic Operations', function () { - beforeEach(testUtils.setup('owner')); + beforeEach(testUtils.setup('owner', 'role')); it('sets last login time on successful login', function (done) { var userData = testUtils.DataGenerator.forModel.users[0]; @@ -211,6 +213,28 @@ describe('User Model', function run() { }).catch(done); }); + it('can add', function (done) { + var userData = testUtils.DataGenerator.forModel.users[2]; + + sandbox.stub(UserModel, 'gravatarLookup', function (userData) { + return when.resolve(userData); + }); + + RoleModel.findOne().then(function (role) { + userData.roles = [role.toJSON()]; + + return UserModel.add(userData, _.extend({}, context)); + }).then(function (createdUser) { + should.exist(createdUser); + createdUser.has('uuid').should.equal(true); + createdUser.get('password').should.not.equal(userData.password, 'password was hashed'); + createdUser.get('email').should.eql(userData.email, 'email address correct'); + createdUser.related('roles').toJSON()[0].name.should.eql('Administrator', 'role set correctly'); + + done(); + }).catch(done); + }); + it('can destroy', function (done) { var firstUser = {id: 1}; diff --git a/core/test/utils/fixtures/data-generator.js b/core/test/utils/fixtures/data-generator.js index 203e24aee4..393bf2f331 100644 --- a/core/test/utils/fixtures/data-generator.js +++ b/core/test/utils/fixtures/data-generator.js @@ -414,7 +414,8 @@ DataGenerator.forModel = (function () { var posts, tags, - users; + users, + roles; posts = _.map(DataGenerator.Content.posts, function (post) { return _.pick(post, 'title', 'markdown'); @@ -430,10 +431,15 @@ DataGenerator.forModel = (function () { }, user); }); + roles = _.map(DataGenerator.Content.roles, function (role, id) { + return _.extend({}, role, {id: id + 1}); + }); + return { posts: posts, tags: tags, - users: users + users: users, + roles: roles }; }());