Skip to content

Commit

Permalink
updated test module version
Browse files Browse the repository at this point in the history
  • Loading branch information
nisaacson committed Jun 16, 2013
1 parent 022bcf8 commit d66ecc5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/authenticate.js
Expand Up @@ -17,6 +17,7 @@ module.exports = function(userData, cb) {
var password = userData.password
// test a matching password
user.comparePassword(password, function(err, isMatch) {
var clientUser
if (err) {
return cb({
message: 'failed to authenticate user',
Expand All @@ -25,7 +26,8 @@ module.exports = function(userData, cb) {
})
}
if (isMatch) {
return cb(null, user)
clientUser = user.toClient()
return cb(null, clientUser)
}
return cb({
message: 'failed to authenticate user',
Expand Down
2 changes: 1 addition & 1 deletion lib/changeEmail.js
Expand Up @@ -24,7 +24,7 @@ module.exports = function(changeData, cb) {
stack: new Error().stack
})
}
return cb(null, user)
return cb(null, user.toClient())
})
})
}
11 changes: 10 additions & 1 deletion lib/changePassword.js
Expand Up @@ -32,7 +32,16 @@ module.exports = function(changeData, cb) {
})
}
user.password = changeData.newPassword
user.save(cb)
user.save(function(err) {
if (err) {
return cb({
message: 'failed to change user password',
error: err,
stack: new Error().stack
})
}
return cb(null, user.toClient())
})
})
})
}
8 changes: 8 additions & 0 deletions lib/models/user.js
Expand Up @@ -41,4 +41,12 @@ UserSchema.methods.comparePassword = function(candidatePassword, cb) {
});
};
var UserModel = mongoose.model('User', UserSchema);
UserModel.prototype.toClient = function() {
var self = this

var clientUser = this.toObject();
clientUser._id = clientUser._id.toString();
delete clientUser.password;
return clientUser
}
module.exports = UserModel
2 changes: 1 addition & 1 deletion lib/register.js
Expand Up @@ -28,7 +28,7 @@ module.exports = function(userData, cb) {
stack: new Error().stack
})
}
return cb(null, user)
return cb(null, user.toClient())
}
user.save(callback);
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -34,7 +34,7 @@
"nconf": "~0.6.7"
},
"devDependencies": {
"userific-test": "0.0.4",
"userific-test": "0.0.5",
"mocha": "~1.10.0",
"should": "~1.2.2",
"eyespect": "~0.1.10"
Expand Down
13 changes: 11 additions & 2 deletions test/mongoose-test.js
Expand Up @@ -22,8 +22,17 @@ describe('Userific Mongoose Backend', function() {
done(null)
})
})
it('should find user', function() {
User.find({})
it('toClient should strip password from user object', function(done) {
var user = new User()
user.email = 'newUser@example.com'
user.password = 'barPassword'
user.save(function (err) {
should.not.exist(err)
var clientUser = user.toClient()
should.exist(clientUser)
should.not.exist(clientUser.password)
done()
})
})
testSuite(backend)
})

0 comments on commit d66ecc5

Please sign in to comment.