diff --git a/src/routes/user.js b/src/routes/user.js index 90302e93a..a8dc4c3f9 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -76,6 +76,7 @@ function createUser(req, res, next) { } function update(req, res, next) { + assert.strictEqual(typeof req.params.userId, 'string'); assert.strictEqual(typeof req.user, 'object'); assert.strictEqual(typeof req.body, 'object'); @@ -84,12 +85,17 @@ function update(req, res, next) { if (req.user.tokenType !== tokendb.TYPE_USER) return next(new HttpError(403, 'Token type not allowed')); - user.update(req.user.id, req.user.username, req.body.email || req.user.email, req.body.displayName || req.user.displayName, function (error) { - if (error && error.reason === UserError.BAD_EMAIL) return next(new HttpError(400, error.message)); - if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'User not found')); + user.get(req.params.userId, function (error, result) { + if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user')); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(204)); + user.update(req.params.userId, result.username, req.body.email || result.email, req.body.displayName || result.displayName, function (error) { + if (error && error.reason === UserError.BAD_EMAIL) return next(new HttpError(400, error.message)); + if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'User not found')); + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(204)); + }); }); } diff --git a/src/test/user-test.js b/src/test/user-test.js index 9a73b3de2..9bf85bd9c 100644 --- a/src/test/user-test.js +++ b/src/test/user-test.js @@ -356,6 +356,22 @@ describe('User', function () { }); }); }); + + it('succeeds with same data', function (done) { + user.update(USERNAME, USERNAME_NEW, EMAIL_NEW, DISPLAY_NAME_NEW, function (error) { + expect(error).to.not.be.ok(); + + user.get(USERNAME, function (error, result) { + expect(error).to.not.be.ok(); + expect(result).to.be.ok(); + expect(result.email).to.equal(EMAIL_NEW); + expect(result.username).to.equal(USERNAME_NEW); + expect(result.displayName).to.equal(DISPLAY_NAME_NEW); + + done(); + }); + }); + }); }); describe('admin change', function () {