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
This commit is contained in:
mleanos
2015-08-28 18:19:33 -07:00
parent bbbe8772f2
commit 263adccd44

View File

@@ -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);