Test revokeInvite

This commit is contained in:
Shane Kilkelly 2016-07-22 13:33:21 +01:00
parent c9cfcddbe9
commit e34b124c73

View file

@ -17,7 +17,8 @@ describe "CollaboratorsInviteHandler", ->
this[k] = v this[k] = v
this this
save: sinon.stub() save: sinon.stub()
findOne: sinon.stub() @findOne: sinon.stub()
@remove: sinon.stub()
@Project = {} @Project = {}
@Crypto = Crypto @Crypto = Crypto
@CollaboratorsInviteHandler = SandboxedModule.require modulePath, requires: @CollaboratorsInviteHandler = SandboxedModule.require modulePath, requires:
@ -33,6 +34,7 @@ describe "CollaboratorsInviteHandler", ->
@sendingUserId = ObjectId() @sendingUserId = ObjectId()
@email = "user@example.com" @email = "user@example.com"
@userId = ObjectId() @userId = ObjectId()
@inviteId = ObjectId()
@privileges = "readAndWrite" @privileges = "readAndWrite"
describe 'inviteToProject', -> describe 'inviteToProject', ->
@ -89,3 +91,36 @@ describe "CollaboratorsInviteHandler", ->
@call (err, invite) => @call (err, invite) =>
expect(err).to.be.instanceof Error expect(err).to.be.instanceof Error
done() done()
describe 'revokeInvite', ->
beforeEach ->
@ProjectInvite.remove.callsArgWith(1, null)
@CollaboratorsEmailHandler.notifyUserOfProjectInvite = sinon.stub()
@call = (callback) =>
@CollaboratorsInviteHandler.revokeInvite @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
done()
it 'should call ProjectInvite.remove', (done) ->
@call (err) =>
@ProjectInvite.remove.callCount.should.equal 1
@ProjectInvite.remove.calledWith({projectId: @projectId, _id: @inviteId}).should.equal true
done()
describe 'when remove produces an error', ->
beforeEach ->
@ProjectInvite.remove.callsArgWith(1, new Error('woops'))
it 'should produce an error', (done) ->
@call (err) =>
expect(err).to.be.instanceof Error
done()