From d8615ddba34cef3b459a837330cf743af924bee3 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Thu, 23 Apr 2020 07:52:36 -0400 Subject: [PATCH] Merge pull request #2761 from overleaf/jpa-user-controller-bail-out-next [UserController] updateUserSettings: bail out after calling next(err) GitOrigin-RevId: f1905c0c54f3feb98836443cbf8e080888d4901c --- .../app/src/Features/User/UserController.js | 2 +- .../test/unit/src/User/UserControllerTests.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/services/web/app/src/Features/User/UserController.js b/services/web/app/src/Features/User/UserController.js index b9c61517fc..c35a282f26 100644 --- a/services/web/app/src/Features/User/UserController.js +++ b/services/web/app/src/Features/User/UserController.js @@ -248,7 +248,7 @@ const UserController = { errorData.info.public.message = req.i18n.translate( 'problem_changing_email_address' ) - next( + return next( new HttpErrors.InternalServerError(errorData).withCause(err) ) } diff --git a/services/web/test/unit/src/User/UserControllerTests.js b/services/web/test/unit/src/User/UserControllerTests.js index 63d3aca28f..62c1c9ce68 100644 --- a/services/web/test/unit/src/User/UserControllerTests.js +++ b/services/web/test/unit/src/User/UserControllerTests.js @@ -405,6 +405,25 @@ describe('UserController', function() { this.UserController.updateUserSettings(this.req, this.res) }) + describe('when changeEmailAddress yields an error', function() { + it('should pass on an error and not send a success status', function(done) { + this.req.body.email = this.newEmail.toUpperCase() + this.UserUpdater.changeEmailAddress.callsArgWith(2, new Error()) + const next = err => { + expect(err).to.exist + process.nextTick(() => { + // logic in User.findById + expect(this.res.send.called).to.equal(false) + expect(this.res.sendStatus.called).to.equal(false) + // logic after error handling + expect(this.User.findById.callCount).to.equal(1) + done() + }) + } + this.UserController.updateUserSettings(this.req, this.res, next) + }) + }) + describe('when using an external auth source', function() { beforeEach(function() { this.UserUpdater.changeEmailAddress.callsArgWith(2)