From 4e60e6285ed033af07e38d423bbde2168e46835f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 23 Mar 2017 12:56:51 +0100 Subject: [PATCH] address code review comments --- common/models/user.js | 6 +++--- test/user.integration.js | 2 +- test/user.test.js | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/common/models/user.js b/common/models/user.js index 32e940adf..364e7d466 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -383,7 +383,7 @@ module.exports = function(User) { const err = new Error(`User ${userId} not found`); Object.assign(err, { code: 'USER_NOT_FOUND', - statusCode: 400, + statusCode: 401, }); return cb(err); } @@ -391,7 +391,7 @@ module.exports = function(User) { inst.hasPassword(oldPassword, function(err, isMatch) { if (err) return cb(err); if (!isMatch) { - const err = new Error('Incorrect current password'); + const err = new Error('Invalid current password'); Object.assign(err, { code: 'INVALID_PASSWORD', statusCode: 400, @@ -869,7 +869,7 @@ module.exports = function(User) { UserModel.remoteMethod( 'changePassword', { - description: 'Change password of the current user.', + description: 'Change a user\'s password.', accepts: [ {arg: 'id', type: 'any', http: ctx => ctx.req.accessToken && ctx.req.accessToken.userId, diff --git a/test/user.integration.js b/test/user.integration.js index 9ef64bb75..39372c195 100644 --- a/test/user.integration.js +++ b/test/user.integration.js @@ -118,7 +118,7 @@ describe('users - integration', function() { .expect(401, done); }); - it('changes password of the current user', function() { + it('updates the user\'s password', function() { const User = app.models.User; const credentials = {email: 'change@example.com', password: 'pass'}; return User.create(credentials) diff --git a/test/user.test.js b/test/user.test.js index 3e79619be..5019a3070 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -1308,8 +1308,8 @@ describe('User', function() { success => { throw new Error('changePassword should have failed'); }, err => { // workaround for chai problem - // object tested must be an array, an object, or a string, - // but error given + // object tested must be an array, an object, + // or a string, but error given const props = Object.assign({}, err); expect(props).to.contain({ code: 'INVALID_PASSWORD', @@ -1318,7 +1318,7 @@ describe('User', function() { }); }); - it('fails with 404 for unknown user id', () => { + it('fails with 401 for unknown user id', () => { return User.changePassword('unknown-id', 'pass', 'pass').then( success => { throw new Error('changePassword should have failed'); }, err => { @@ -1328,12 +1328,12 @@ describe('User', function() { const props = Object.assign({}, err); expect(props).to.contain({ code: 'USER_NOT_FOUND', - statusCode: 400, + statusCode: 401, }); }); }); - it('forwards "options" argument', () => { + it('forwards the "options" argument', () => { const options = {testFlag: true}; const observedOptions = [];