diff --git a/services/web/app/src/Features/Editor/EditorHttpController.js b/services/web/app/src/Features/Editor/EditorHttpController.js index 75a27449a6..79a1b387f1 100644 --- a/services/web/app/src/Features/Editor/EditorHttpController.js +++ b/services/web/app/src/Features/Editor/EditorHttpController.js @@ -28,6 +28,7 @@ const CollaboratorsInviteHandler = require('../Collaborators/CollaboratorsInvite const PrivilegeLevels = require('../Authorization/PrivilegeLevels') const TokenAccessHandler = require('../TokenAccess/TokenAccessHandler') const AuthenticationController = require('../Authentication/AuthenticationController') +const Errors = require('../Errors/Errors') module.exports = EditorHttpController = { joinProject(req, res, next) { @@ -73,7 +74,7 @@ module.exports = EditorHttpController = { return callback(error) } if (project == null) { - return callback(new Error('not found')) + return callback(new Errors.NotFoundError('project not found')) } return CollaboratorsHandler.getInvitedMembersWithPrivilegeLevels( project_id, diff --git a/services/web/test/unit/src/Editor/EditorHttpControllerTests.js b/services/web/test/unit/src/Editor/EditorHttpControllerTests.js index 03f589f123..845b19a113 100644 --- a/services/web/test/unit/src/Editor/EditorHttpControllerTests.js +++ b/services/web/test/unit/src/Editor/EditorHttpControllerTests.js @@ -16,6 +16,7 @@ const modulePath = require('path').join( __dirname, '../../../../app/src/Features/Editor/EditorHttpController' ) +const Errors = require('../../../../app/src/Features/Errors/Errors') describe('EditorHttpController', function() { beforeEach(function() { @@ -37,7 +38,8 @@ describe('EditorHttpController', function() { '../Collaborators/CollaboratorsHandler': (this.CollaboratorsHandler = {}), '../Collaborators/CollaboratorsInviteHandler': (this.CollaboratorsInviteHandler = {}), '../TokenAccess/TokenAccessHandler': (this.TokenAccessHandler = {}), - '../Authentication/AuthenticationController': (this.AuthenticationController = {}) + '../Authentication/AuthenticationController': (this.AuthenticationController = {}), + '../Errors/Errors': Errors } }) @@ -186,6 +188,24 @@ describe('EditorHttpController', function() { .callsArgWith(2, null, this.user)) }) + describe('when project is not found', function() { + beforeEach(function() { + this.ProjectGetter.getProjectWithoutDocLines.yields(null, null) + return this.EditorHttpController._buildJoinProjectView( + this.req, + this.project_id, + this.user_id, + this.callback + ) + }) + + it('should handle return not found error', function() { + let args = this.callback.lastCall.args + args.length.should.equal(1) + args[0].should.be.instanceof(Errors.NotFoundError) + }) + }) + describe('when authorized', function() { beforeEach(function() { this.AuthorizationManager.getPrivilegeLevelForProject = sinon