Skip to content

Commit

Permalink
User.roles should be an array
Browse files Browse the repository at this point in the history
  • Loading branch information
andrglo committed Dec 10, 2015
1 parent 42e0631 commit f342338
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ module.exports = {

users: {
get: function(username) {
return redis.hgetall(USERS + username.toLowerCase());
return redis.hgetall(USERS + username.toLowerCase())
.then(user => {
if (user.roles) {
user.roles = user.roles.split(',');
}
return user;
});
},
create: function(user) {
return Promise.resolve().then(function() {
Expand Down
18 changes: 16 additions & 2 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,31 @@ describe('Users', function() {
authDb.users.create({
username: 'Andre',
password: '12345678',
firstName: 'André'
firstName: 'André',
roles: ['none']
}).then(function(res) {
res.should.be.true;
done();
}).catch(function(err) {
done(err);
});
});
it('Should read field roles as an array', function(done) {
authDb.users.get('andre').then(function(user) {
expect(user.roles).to.be.a('array');
expect(user.roles.length).to.equal(1);
done();
}).catch(function(err) {
done(err);
});
});
it('should update user Andre', function(done) {
authDb.users.update({
username: 'ANDRE',
password: '12345678',
firstName: 'Heitor',
lastName: 'Glória'
lastName: 'Glória',
roles: ['none', 'other']
}, 'andre').then(function(res) {
res.should.be.true;
done();
Expand All @@ -75,6 +86,9 @@ describe('Users', function() {
expect(authDb.users.checkPassword('12345678', user)).to.equal(true);
user.firstName.should.equal('Heitor');
user.lastName.should.equal('Glória');
expect(user.roles).to.be.a('array');
expect(user.roles.length).to.equal(2);
expect(user.roles).to.eql(['none', 'other']);
done();
}).catch(function(err) {
done(err);
Expand Down

0 comments on commit f342338

Please sign in to comment.