mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-06 17:58:20 +02:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user