|
|
@@ -173,6 +173,7 @@ describe "CollaboratorsInviteController", ->
|
|
|
@req.session =
|
|
|
user: _id: @current_user_id = "current-user-id"
|
|
|
@res.render = sinon.stub()
|
|
|
+ @res.redirect = sinon.stub()
|
|
|
@res.sendStatus = sinon.stub()
|
|
|
@invite = {
|
|
|
_id: ObjectId(),
|
|
|
@@ -186,6 +187,8 @@ describe "CollaboratorsInviteController", ->
|
|
|
_id: @project_id
|
|
|
name: "some project"
|
|
|
owner_ref: @invite.sendingUserId
|
|
|
+ collaberator_refs: []
|
|
|
+ readOnly_refs: []
|
|
|
@owner =
|
|
|
_id: @fakeProject.owner_ref
|
|
|
first_name: "John"
|
|
|
@@ -210,41 +213,41 @@ describe "CollaboratorsInviteController", ->
|
|
|
it 'should not call next', ->
|
|
|
@next.callCount.should.equal 0
|
|
|
|
|
|
- it 'should call getInviteByToken', ->
|
|
|
- @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
-
|
|
|
it 'should call Project.findOne', ->
|
|
|
@Project.findOne.callCount.should.equal 1
|
|
|
@Project.findOne.calledWith({_id: @project_id}).should.equal true
|
|
|
|
|
|
+ it 'should call getInviteByToken', ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
+
|
|
|
it 'should call User.findOne', ->
|
|
|
@User.findOne.callCount.should.equal 1
|
|
|
@User.findOne.calledWith({_id: @fakeProject.owner_ref}).should.equal true
|
|
|
|
|
|
- describe 'when the getInviteByToken produces an error', ->
|
|
|
+ describe 'when Project.findOne produces an error', ->
|
|
|
|
|
|
beforeEach ->
|
|
|
- @err = new Error('woops')
|
|
|
- @CollaboratorsInviteHandler.getInviteByToken.callsArgWith(2, @err)
|
|
|
+ @Project.findOne.callsArgWith(2, new Error('woops'))
|
|
|
@CollaboratorsInviteController.viewInvite @req, @res, @next
|
|
|
|
|
|
- it 'should call next with the error', ->
|
|
|
+ it 'should produce an error', ->
|
|
|
@next.callCount.should.equal 1
|
|
|
- @next.calledWith(@err).should.equal true
|
|
|
+ expect(@next.firstCall.args[0]).to.be.instanceof Error
|
|
|
|
|
|
- it 'should call getInviteByToken', ->
|
|
|
- @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
+ it 'should call Project.findOne', ->
|
|
|
+ @Project.findOne.callCount.should.equal 1
|
|
|
+ @Project.findOne.calledWith({_id: @project_id}).should.equal true
|
|
|
|
|
|
- it 'should not call Project.findOne', ->
|
|
|
- @Project.findOne.callCount.should.equal 0
|
|
|
+ it 'should not call getInviteByToken', ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 0
|
|
|
|
|
|
it 'should not call User.findOne', ->
|
|
|
@User.findOne.callCount.should.equal 0
|
|
|
|
|
|
- describe 'when the getInviteByToken does not produce an invite', ->
|
|
|
+ describe 'when Project.findOne does not find a project', ->
|
|
|
|
|
|
beforeEach ->
|
|
|
- @CollaboratorsInviteHandler.getInviteByToken.callsArgWith(2, null, null)
|
|
|
+ @Project.findOne.callsArgWith(2, null, null)
|
|
|
@CollaboratorsInviteController.viewInvite @req, @res, @next
|
|
|
|
|
|
it 'should render the not-valid view template', ->
|
|
|
@@ -254,54 +257,83 @@ describe "CollaboratorsInviteController", ->
|
|
|
it 'should not call next', ->
|
|
|
@next.callCount.should.equal 0
|
|
|
|
|
|
- it 'should call getInviteByToken', ->
|
|
|
- @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
+ it 'should call Project.findOne', ->
|
|
|
+ @Project.findOne.callCount.should.equal 1
|
|
|
+ @Project.findOne.calledWith({_id: @project_id}).should.equal true
|
|
|
|
|
|
- it 'should not call Project.findOne', ->
|
|
|
- @Project.findOne.callCount.should.equal 0
|
|
|
+ it 'should not call getInviteByToken', ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 0
|
|
|
|
|
|
it 'should not call User.findOne', ->
|
|
|
@User.findOne.callCount.should.equal 0
|
|
|
|
|
|
- describe 'when Project.findOne produces an error', ->
|
|
|
+ describe 'when the getInviteByToken produces an error', ->
|
|
|
|
|
|
beforeEach ->
|
|
|
- @Project.findOne.callsArgWith(2, new Error('woops'))
|
|
|
+ @err = new Error('woops')
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callsArgWith(2, @err)
|
|
|
@CollaboratorsInviteController.viewInvite @req, @res, @next
|
|
|
|
|
|
- it 'should produce an error', ->
|
|
|
+ it 'should call next with the error', ->
|
|
|
@next.callCount.should.equal 1
|
|
|
- expect(@next.firstCall.args[0]).to.be.instanceof Error
|
|
|
-
|
|
|
- it 'should call getInviteByToken', ->
|
|
|
- @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
+ @next.calledWith(@err).should.equal true
|
|
|
|
|
|
it 'should call Project.findOne', ->
|
|
|
@Project.findOne.callCount.should.equal 1
|
|
|
- @Project.findOne.calledWith({_id: @project_id}).should.equal true
|
|
|
+
|
|
|
+ it 'should call getInviteByToken', ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
|
|
|
it 'should not call User.findOne', ->
|
|
|
@User.findOne.callCount.should.equal 0
|
|
|
|
|
|
- describe 'when Project.findOne does not find a project', ->
|
|
|
+ describe 'when the getInviteByToken does not produce an invite', ->
|
|
|
|
|
|
- beforeEach ->
|
|
|
- @Project.findOne.callsArgWith(2, null, null)
|
|
|
- @CollaboratorsInviteController.viewInvite @req, @res, @next
|
|
|
+ describe 'when the user is not already a member of this project', ->
|
|
|
|
|
|
- it 'should render the not-valid view template', ->
|
|
|
- @res.render.callCount.should.equal 1
|
|
|
- @res.render.calledWith('project/invite/not-valid').should.equal true
|
|
|
+ beforeEach ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callsArgWith(2, null, null)
|
|
|
+ @CollaboratorsInviteController.viewInvite @req, @res, @next
|
|
|
|
|
|
- it 'should not call next', ->
|
|
|
- @next.callCount.should.equal 0
|
|
|
+ it 'should render the not-valid view template', ->
|
|
|
+ @res.render.callCount.should.equal 1
|
|
|
+ @res.render.calledWith('project/invite/not-valid').should.equal true
|
|
|
|
|
|
- it 'should call Project.findOne', ->
|
|
|
- @Project.findOne.callCount.should.equal 1
|
|
|
- @Project.findOne.calledWith({_id: @project_id}).should.equal true
|
|
|
+ it 'should not call next', ->
|
|
|
+ @next.callCount.should.equal 0
|
|
|
|
|
|
- it 'should not call User.findOne', ->
|
|
|
- @User.findOne.callCount.should.equal 0
|
|
|
+ it 'should call Project.findOne', ->
|
|
|
+ @Project.findOne.callCount.should.equal 1
|
|
|
+
|
|
|
+ it 'should call getInviteByToken', ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
+
|
|
|
+ it 'should not call User.findOne', ->
|
|
|
+ @User.findOne.callCount.should.equal 0
|
|
|
+
|
|
|
+ describe 'when the user is already a member of the project', ->
|
|
|
+
|
|
|
+ beforeEach ->
|
|
|
+ @fakeProject.collaberator_refs = [ObjectId(), @current_user_id, ObjectId()]
|
|
|
+ @Project.findOne.callsArgWith(2, null, @fakeProject)
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callsArgWith(2, null, null)
|
|
|
+ @CollaboratorsInviteController.viewInvite @req, @res, @next
|
|
|
+
|
|
|
+ it 'should redirect to the project page', ->
|
|
|
+ @res.redirect.callCount.should.equal 1
|
|
|
+ @res.redirect.calledWith("/project/#{@project_id}").should.equal true
|
|
|
+
|
|
|
+ it 'should not call next', ->
|
|
|
+ @next.callCount.should.equal 0
|
|
|
+
|
|
|
+ it 'should call Project.findOne', ->
|
|
|
+ @Project.findOne.callCount.should.equal 1
|
|
|
+
|
|
|
+ it 'should call getInviteByToken', ->
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken.callCount.should.equal 1
|
|
|
+
|
|
|
+ it 'should not call User.findOne', ->
|
|
|
+ @User.findOne.callCount.should.equal 0
|
|
|
|
|
|
describe 'when User.findOne produces an error', ->
|
|
|
|