From da40f54d55812d5ddf89cfc17cccbbfe0598e7ac Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Tue, 16 Aug 2016 11:17:45 +0100 Subject: [PATCH] Improve logging, add acceptance tests for joinProject json --- .../Editor/EditorHttpController.coffee | 3 +++ .../coffee/ProjectInviteTests.coffee | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/services/web/app/coffee/Features/Editor/EditorHttpController.coffee b/services/web/app/coffee/Features/Editor/EditorHttpController.coffee index 5c53a11348..b091c16c8b 100644 --- a/services/web/app/coffee/Features/Editor/EditorHttpController.coffee +++ b/services/web/app/coffee/Features/Editor/EditorHttpController.coffee @@ -31,6 +31,7 @@ module.exports = EditorHttpController = ProjectDeleter.unmarkAsDeletedByExternalSource project_id _buildJoinProjectView: (project_id, user_id, callback = (error, project, privilegeLevel) ->) -> + logger.log {project_id, user_id}, "building the joinProject view" ProjectGetter.getProjectWithoutDocLines project_id, (error, project) -> return callback(error) if error? return callback(new Error("not found")) if !project? @@ -41,9 +42,11 @@ module.exports = EditorHttpController = AuthorizationManager.getPrivilegeLevelForProject user_id, project_id, (error, privilegeLevel) -> return callback(error) if error? if !privilegeLevel? or privilegeLevel == PrivilegeLevels.NONE + logger.log {project_id, user_id, privilegeLevel}, "not an acceptable privilege level, returning null" return callback null, null, false CollaboratorsInviteHandler.getAllInvites project_id, (error, invites) -> return callback(error) if error? + logger.log {project_id, user_id, privilegeLevel}, "returning project model view" callback(null, ProjectEditorHandler.buildProjectModelView(project, members, invites), privilegeLevel diff --git a/services/web/test/acceptance/coffee/ProjectInviteTests.coffee b/services/web/test/acceptance/coffee/ProjectInviteTests.coffee index c2614b5eb0..8e207948a1 100644 --- a/services/web/test/acceptance/coffee/ProjectInviteTests.coffee +++ b/services/web/test/acceptance/coffee/ProjectInviteTests.coffee @@ -95,6 +95,19 @@ tryGetInviteList = (user, projectId, callback=(err, response, body)->) -> json: true }, callback +tryJoinProject = (user, projectId, callback=(err, response, body)->) -> + user.getCsrfToken (error) => + return callback(error) if error? + user.request.post { + url: "/project/#{projectId}/join" + qs: {user_id: user._id} + auth: + user: settings.apis.web.user + pass: settings.apis.web.pass + sendImmediately: true + json: true + jar: false + }, callback # Expectations expectProjectAccess = (user, projectId, callback=(err,result)->) -> @@ -185,6 +198,15 @@ expectInviteListCount = (user, projectId, count, callback=(err)->) -> expect(body.invites.length).to.equal count callback() +expectInvitesInJoinProjectCount = (user, projectId, count, callback=(err,result)->) -> + tryJoinProject user, projectId, (err, response, body) -> + expect(err).to.be.oneOf [null, undefined] + expect(response.statusCode).to.equal 200 + expect(body.project).to.contain.keys ['invites'] + expect(body.project.invites.length).to.equal count + callback() + + describe "ProjectInviteTests", -> before (done) -> @@ -245,8 +267,12 @@ describe "ProjectInviteTests", -> @invite = invite cb() (cb) => expectInviteListCount @sendingUser, @projectId, 1, cb + # check the joinProject view + (cb) => expectInvitesInJoinProjectCount @sendingUser, @projectId, 1, cb + # revoke invite (cb) => revokeInvite @sendingUser, @projectId, @invite._id, cb (cb) => expectInviteListCount @sendingUser, @projectId, 0, cb + (cb) => expectInvitesInJoinProjectCount @sendingUser, @projectId, 0, cb ], done it 'should allow the project owner to many invites at once', (done) -> @@ -268,6 +294,7 @@ describe "ProjectInviteTests", -> cb() # should have two (cb) => expectInviteListCount @sendingUser, @projectId, 2, cb + (cb) => expectInvitesInJoinProjectCount @sendingUser, @projectId, 2, cb # revoke first (cb) => revokeInvite @sendingUser, @projectId, @inviteOne._id, cb (cb) => expectInviteListCount @sendingUser, @projectId, 1, cb