From 263adccd443c53659b45b390f7fcfc875f980c99 Mon Sep 17 00:00:00 2001 From: mleanos Date: Fri, 28 Aug 2015 18:19:33 -0700 Subject: [PATCH] User model tests for roles Added tests for the User model's roles field. Should be able to update existing user with valid roles Should NOT be able to update existing user WITHOUT a role Should NOT be able to update existing user with INVALID role --- .../tests/server/user.server.model.tests.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules/users/tests/server/user.server.model.tests.js b/modules/users/tests/server/user.server.model.tests.js index 66890671c7..c0ad1eeee5 100644 --- a/modules/users/tests/server/user.server.model.tests.js +++ b/modules/users/tests/server/user.server.model.tests.js @@ -92,6 +92,54 @@ describe('User Model Unit Tests:', function () { }); }); + it('should be able to update an existing user with valid roles without problems', function (done) { + var _user = new User(user); + + _user.save(function (err) { + should.not.exist(err); + _user.roles = ['user', 'admin']; + _user.save(function (err) { + should.not.exist(err); + _user.remove(function (err) { + should.not.exist(err); + done(); + }); + }); + }); + }); + + it('should be able to show an error when trying to update an existing user without a role', function (done) { + var _user = new User(user); + + _user.save(function (err) { + should.not.exist(err); + _user.roles = []; + _user.save(function (err) { + should.exist(err); + _user.remove(function (err) { + should.not.exist(err); + done(); + }); + }); + }); + }); + + it('should be able to show an error when trying to update an existing user with a invalid role', function (done) { + var _user = new User(user); + + _user.save(function (err) { + should.not.exist(err); + _user.roles = ['invalid-user-role-enum']; + _user.save(function (err) { + should.exist(err); + _user.remove(function (err) { + should.not.exist(err); + done(); + }); + }); + }); + }); + it('should confirm that saving user model doesnt change the password', function (done) { var _user = new User(user);