Rename functions to make distinction between invited/token members

This commit is contained in:
Shane Kilkelly
2017-09-21 09:30:38 +01:00
parent 91ec0da239
commit ef7e1ceabf
6 changed files with 58 additions and 58 deletions
@@ -82,7 +82,7 @@ describe "CollaboratorsController", ->
@res.json = sinon.stub()
@next = sinon.stub()
@members = [{a: 1}]
@CollaboratorsHandler.getAllMembers = sinon.stub().callsArgWith(1, null, @members)
@CollaboratorsHandler.getAllInvitedMembers = sinon.stub().callsArgWith(1, null, @members)
@CollaboratorsController.getAllMembers(@req, @res, @next)
it 'should not produce an error', ->
@@ -93,13 +93,13 @@ describe "CollaboratorsController", ->
@res.json.calledWith({members: @members}).should.equal true
it 'should call CollaboratorsHandler.getAllMembers', ->
@CollaboratorsHandler.getAllMembers.callCount.should.equal 1
@CollaboratorsHandler.getAllInvitedMembers.callCount.should.equal 1
describe 'when CollaboratorsHandler.getAllMembers produces an error', ->
describe 'when CollaboratorsHandler.getAllInvitedMembers produces an error', ->
beforeEach ->
@res.json = sinon.stub()
@next = sinon.stub()
@CollaboratorsHandler.getAllMembers = sinon.stub().callsArgWith(1, new Error('woops'))
@CollaboratorsHandler.getAllInvitedMembers = sinon.stub().callsArgWith(1, new Error('woops'))
@CollaboratorsController.getAllMembers(@req, @res, @next)
it 'should produce an error', ->
@@ -157,17 +157,17 @@ describe "CollaboratorsHandler", ->
expect(level).to.equal false
done()
describe "isUserMemberOfProject", ->
describe "isUserInvitedMemberOfProject", ->
beforeEach ->
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels = sinon.stub()
describe "when user is a member of the project", ->
beforeEach ->
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
{ id: "not-the-user", privilegeLevel: "readOnly" }
{ id: @user_id, privilegeLevel: "readAndWrite" }
{ id: "not-the-user", privilegeLevel: "readOnly", source: 'invite' }
{ id: @user_id, privilegeLevel: "readAndWrite", source: 'invite' }
])
@CollaboratorHandler.isUserMemberOfProject @user_id, @project_id, @callback
@CollaboratorHandler.isUserInvitedMemberOfProject @user_id, @project_id, @callback
it "should return true and the privilegeLevel", ->
@callback
@@ -179,7 +179,7 @@ describe "CollaboratorsHandler", ->
@CollaboratorHandler.getMemberIdsWithPrivilegeLevels.withArgs(@project_id).yields(null, [
{ id: "not-the-user", privilegeLevel: "readOnly" }
])
@CollaboratorHandler.isUserMemberOfProject @user_id, @project_id, @callback
@CollaboratorHandler.isUserInvitedMemberOfProject @user_id, @project_id, @callback
it "should return false", ->
@callback
@@ -314,7 +314,7 @@ describe "CollaboratorsHandler", ->
.calledWith(project_id, @user_id)
.should.equal true
describe 'getAllMembers', ->
describe 'getAllInvitedMembers', ->
beforeEach ->
@owning_user = {_id: 'owner-id', email: 'owner@example.com', features: {a: 1}}
@@ -323,14 +323,14 @@ describe "CollaboratorsHandler", ->
{user: @owning_user, privilegeLevel: "owner"},
{user: @readwrite_user, privilegeLevel: "readAndWrite"}
]
@CollaboratorHandler.getMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, null, @members)
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, null, @members)
@ProjectEditorHandler.buildOwnerAndMembersViews = sinon.stub().returns(@views = {
owner: @owning_user,
ownerFeatures: @owning_user.features,
members: [ {_id: @readwrite_user._id, email: @readwrite_user.email} ]
})
@callback = sinon.stub()
@CollaboratorHandler.getAllMembers @project_id, @callback
@CollaboratorHandler.getAllInvitedMembers @project_id, @callback
it 'should not produce an error', ->
@callback.callCount.should.equal 1
@@ -341,8 +341,8 @@ describe "CollaboratorsHandler", ->
expect(@callback.firstCall.args[1]).to.deep.equal @views.members
it 'should call getMembersWithPrivileges', ->
@CollaboratorHandler.getMembersWithPrivilegeLevels.callCount.should.equal 1
@CollaboratorHandler.getMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.callCount.should.equal 1
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
it 'should call ProjectEditorHandler.buildOwnerAndMembersViews', ->
@ProjectEditorHandler.buildOwnerAndMembersViews.callCount.should.equal 1
@@ -351,14 +351,14 @@ describe "CollaboratorsHandler", ->
describe 'when getMembersWithPrivileges produces an error', ->
beforeEach ->
@CollaboratorHandler.getMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, new Error('woops'))
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels = sinon.stub().callsArgWith(1, new Error('woops'))
@ProjectEditorHandler.buildOwnerAndMembersViews = sinon.stub().returns(@views = {
owner: @owning_user,
ownerFeatures: @owning_user.features,
members: [ {_id: @readwrite_user._id, email: @readwrite_user.email} ]
})
@callback = sinon.stub()
@CollaboratorHandler.getAllMembers @project_id, @callback
@CollaboratorHandler.getAllInvitedMembers @project_id, @callback
it 'should produce an error', ->
@callback.callCount.should.equal 1
@@ -366,8 +366,8 @@ describe "CollaboratorsHandler", ->
expect(@callback.firstCall.args[0]).to.be.instanceof Error
it 'should call getMembersWithPrivileges', ->
@CollaboratorHandler.getMembersWithPrivilegeLevels.callCount.should.equal 1
@CollaboratorHandler.getMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.callCount.should.equal 1
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels.firstCall.args[0].should.equal @project_id
it 'should not call ProjectEditorHandler.buildOwnerAndMembersViews', ->
@ProjectEditorHandler.buildOwnerAndMembersViews.callCount.should.equal 0
@@ -317,7 +317,7 @@ describe "CollaboratorsInviteController", ->
last_name: "Doe"
email: "john@example.com"
@CollaboratorsHandler.isUserMemberOfProject = sinon.stub().callsArgWith(2, null, false, null)
@CollaboratorsHandler.isUserInvitedMemberOfProject = sinon.stub().callsArgWith(2, null, false, null)
@CollaboratorsInviteHandler.getInviteByToken = sinon.stub().callsArgWith(2, null, @invite)
@ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, @fakeProject)
@UserGetter.getUser.callsArgWith(2, null, @owner)
@@ -337,9 +337,9 @@ describe "CollaboratorsInviteController", ->
it 'should not call next', ->
@next.callCount.should.equal 0
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -356,7 +356,7 @@ describe "CollaboratorsInviteController", ->
describe 'when user is already a member of the project', ->
beforeEach ->
@CollaboratorsHandler.isUserMemberOfProject = sinon.stub().callsArgWith(2, null, true, null)
@CollaboratorsHandler.isUserInvitedMemberOfProject = sinon.stub().callsArgWith(2, null, true, null)
@CollaboratorsInviteController.viewInvite @req, @res, @next
it 'should redirect to the project page', ->
@@ -366,9 +366,9 @@ describe "CollaboratorsInviteController", ->
it 'should not call next with an error', ->
@next.callCount.should.equal 0
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should not call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 0
@@ -379,19 +379,19 @@ describe "CollaboratorsInviteController", ->
it 'should not call ProjectGetter.getProject', ->
@ProjectGetter.getProject.callCount.should.equal 0
describe 'when isUserMemberOfProject produces an error', ->
describe 'when isUserInvitedMemberOfProject produces an error', ->
beforeEach ->
@CollaboratorsHandler.isUserMemberOfProject = sinon.stub().callsArgWith(2, new Error('woops'))
@CollaboratorsHandler.isUserInvitedMemberOfProject = sinon.stub().callsArgWith(2, new Error('woops'))
@CollaboratorsInviteController.viewInvite @req, @res, @next
it 'should call next with an error', ->
@next.callCount.should.equal 1
expect(@next.firstCall.args[0]).to.be.instanceof Error
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should not call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 0
@@ -413,13 +413,13 @@ describe "CollaboratorsInviteController", ->
@next.callCount.should.equal 1
@next.calledWith(@err).should.equal true
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should not call User.getUser', ->
@UserGetter.getUser.callCount.should.equal 0
@@ -440,13 +440,13 @@ describe "CollaboratorsInviteController", ->
it 'should not call next', ->
@next.callCount.should.equal 0
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should not call User.getUser', ->
@UserGetter.getUser.callCount.should.equal 0
@@ -464,9 +464,9 @@ describe "CollaboratorsInviteController", ->
@next.callCount.should.equal 1
expect(@next.firstCall.args[0]).to.be.instanceof Error
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -491,9 +491,9 @@ describe "CollaboratorsInviteController", ->
it 'should not call next', ->
@next.callCount.should.equal 0
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -515,9 +515,9 @@ describe "CollaboratorsInviteController", ->
@next.callCount.should.equal 1
expect(@next.firstCall.args[0]).to.be.instanceof Error
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -542,9 +542,9 @@ describe "CollaboratorsInviteController", ->
it 'should not call next', ->
@next.callCount.should.equal 0
it 'should call CollaboratorsHandler.isUserMemberOfProject', ->
@CollaboratorsHandler.isUserMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call CollaboratorsHandler.isUserInvitedMemberOfProject', ->
@CollaboratorsHandler.isUserInvitedMemberOfProject.callCount.should.equal 1
@CollaboratorsHandler.isUserInvitedMemberOfProject.calledWith(@current_user_id, @project_id).should.equal true
it 'should call getInviteByToken', ->
@CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
@@ -791,4 +791,4 @@ describe "CollaboratorsInviteController", ->
@RateLimiter.addCount = sinon.stub().callsArgWith(1, null, true)
@CollaboratorsInviteController._checkRateLimit @sendingUserId, (err, result)=>
@RateLimiter.addCount.args[0][0].throttle.should.equal(10)
done()
done()