Allow resending of invites
This commit is contained in:
+44
@@ -429,6 +429,50 @@ describe "CollaboratorsInviteController", ->
|
||||
it 'should call ProjectGetter.getProject', ->
|
||||
@ProjectGetter.getProject.callCount.should.equal 1
|
||||
|
||||
describe "resendInvite", ->
|
||||
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
Project_id: @project_id
|
||||
invite_id: @invite_id = "thuseoautoh"
|
||||
@req.session =
|
||||
user: _id: @current_user_id = "current-user-id"
|
||||
@res.render = sinon.stub()
|
||||
@res.sendStatus = sinon.stub()
|
||||
@CollaboratorsInviteHandler.resendInvite = sinon.stub().callsArgWith(2, null)
|
||||
@callback = sinon.stub()
|
||||
@next = sinon.stub()
|
||||
|
||||
describe 'when resendInvite does not produce an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@CollaboratorsInviteController.resendInvite @req, @res, @next
|
||||
|
||||
it 'should produce a 201 response', ->
|
||||
@res.sendStatus.callCount.should.equal 1
|
||||
@res.sendStatus.calledWith(201).should.equal true
|
||||
|
||||
it 'should have called resendInvite', ->
|
||||
@CollaboratorsInviteHandler.resendInvite.callCount.should.equal 1
|
||||
|
||||
describe 'when resendInvite produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@err = new Error('woops')
|
||||
@CollaboratorsInviteHandler.resendInvite = sinon.stub().callsArgWith(2, @err)
|
||||
@CollaboratorsInviteController.resendInvite @req, @res, @next
|
||||
|
||||
it 'should not produce a 201 response', ->
|
||||
@res.sendStatus.callCount.should.equal 0
|
||||
|
||||
it 'should call next with the error', ->
|
||||
@next.callCount.should.equal 1
|
||||
@next.calledWith(@err).should.equal true
|
||||
|
||||
it 'should have called resendInvite', ->
|
||||
@CollaboratorsInviteHandler.resendInvite.callCount.should.equal 1
|
||||
|
||||
|
||||
describe "revokeInvite", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
+61
@@ -209,6 +209,67 @@ describe "CollaboratorsInviteHandler", ->
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
describe 'resendInvite', ->
|
||||
|
||||
beforeEach ->
|
||||
@ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
||||
@CollaboratorsEmailHandler.notifyUserOfProjectInvite = sinon.stub()
|
||||
@call = (callback) =>
|
||||
@CollaboratorsInviteHandler.resendInvite @projectId, @inviteId, callback
|
||||
|
||||
describe 'when all goes well', ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
it 'should not produce an error', (done) ->
|
||||
@call (err) =>
|
||||
expect(err).to.not.be.instanceof Error
|
||||
expect(err).to.be.oneOf [null, undefined]
|
||||
done()
|
||||
|
||||
it 'should call ProjectInvite.findOne', (done) ->
|
||||
@call (err, invite) =>
|
||||
@ProjectInvite.findOne.callCount.should.equal 1
|
||||
@ProjectInvite.findOne.calledWith({_id: @inviteId, projectId: @projectId}).should.equal true
|
||||
done()
|
||||
|
||||
it 'should have called CollaboratorsEmailHandler.notifyUserOfProjectInvite', (done) ->
|
||||
@call (err, invite) =>
|
||||
@CollaboratorsEmailHandler.notifyUserOfProjectInvite.callCount.should.equal 1
|
||||
@CollaboratorsEmailHandler.notifyUserOfProjectInvite.calledWith(@projectId, @email).should.equal true
|
||||
done()
|
||||
|
||||
describe 'when findOne produces an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@ProjectInvite.findOne.callsArgWith(1, new Error('woops'))
|
||||
|
||||
it 'should produce an error', (done) ->
|
||||
@call (err, invite) =>
|
||||
expect(err).to.be.instanceof Error
|
||||
done()
|
||||
|
||||
it 'should not have called CollaboratorsEmailHandler.notifyUserOfProjectInvite', (done) ->
|
||||
@call (err, invite) =>
|
||||
@CollaboratorsEmailHandler.notifyUserOfProjectInvite.callCount.should.equal 0
|
||||
done()
|
||||
|
||||
describe 'when findOne does not find an invite', ->
|
||||
|
||||
beforeEach ->
|
||||
@ProjectInvite.findOne.callsArgWith(1, null, null)
|
||||
|
||||
it 'should not produce an error', (done) ->
|
||||
@call (err, invite) =>
|
||||
expect(err).to.not.be.instanceof Error
|
||||
expect(err).to.be.oneOf [null, undefined]
|
||||
done()
|
||||
|
||||
it 'should not have called CollaboratorsEmailHandler.notifyUserOfProjectInvite', (done) ->
|
||||
@call (err, invite) =>
|
||||
@CollaboratorsEmailHandler.notifyUserOfProjectInvite.callCount.should.equal 0
|
||||
done()
|
||||
|
||||
describe 'getInviteByToken', ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
Reference in New Issue
Block a user