Improve logging, add acceptance tests for joinProject json

This commit is contained in:
Shane Kilkelly 2016-08-16 11:17:45 +01:00
parent b68af254ff
commit da40f54d55
2 changed files with 30 additions and 0 deletions

View file

@ -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

View file

@ -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