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

Commit

Permalink
User model tests for roles
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mleanos committed Aug 29, 2015
1 parent bbbe877 commit 263adcc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions modules/users/tests/server/user.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 263adcc

Please sign in to comment.