Add a getAllInvites api endpoint

This commit is contained in:
Shane Kilkelly
2016-07-25 11:17:47 +01:00
parent 8dea179b01
commit 73fed8b0bf
5 changed files with 109 additions and 0 deletions
@@ -25,6 +25,48 @@ describe "CollaboratorsInviteController", ->
@project_id = "project-id-123"
@callback = sinon.stub()
describe 'getAllInvites', ->
beforeEach ->
@fakeInvites = [
{_id: ObjectId(), one: 1},
{_id: ObjectId(), two: 2}
]
@req.params =
Project_id: @project_id
@res.json = sinon.stub()
@next = sinon.stub()
describe 'when all goes well', ->
beforeEach ->
@CollaboratorsInviteHandler.getAllInvites = sinon.stub().callsArgWith(1, null, @fakeInvites)
@CollaboratorsInviteController.getAllInvites @req, @res, @next
it 'should not produce an error', ->
@next.callCount.should.equal 0
it 'should produce a list of invite objects', ->
@res.json.callCount.should.equal 1
@res.json.calledWith({invites: @fakeInvites}).should.equal true
it 'should have called CollaboratorsInviteHandler.getAllInvites', ->
@CollaboratorsInviteHandler.getAllInvites.callCount.should.equal 1
@CollaboratorsInviteHandler.getAllInvites.calledWith(@project_id).should.equal true
describe 'when CollaboratorsInviteHandler.getAllInvites produces an error', ->
beforeEach ->
@CollaboratorsInviteHandler.getAllInvites = sinon.stub().callsArgWith(1, new Error('woops'))
@CollaboratorsInviteController.getAllInvites @req, @res, @next
it 'should produce an error', ->
@next.callCount.should.equal 1
@next.firstCall.args[0].should.be.instanceof Error
# # # #
describe 'inviteToProject', ->
beforeEach ->
@@ -18,6 +18,7 @@ describe "CollaboratorsInviteHandler", ->
this
save: sinon.stub()
@findOne: sinon.stub()
@find: sinon.stub()
@remove: sinon.stub()
@Project = class Project
constructor: () ->
@@ -54,6 +55,49 @@ describe "CollaboratorsInviteHandler", ->
privileges: @privileges
createdAt: new Date()
describe 'getAllInvites', ->
beforeEach ->
@fakeInvites = [
{_id: ObjectId(), one: 1},
{_id: ObjectId(), two: 2}
]
@ProjectInvite.find.callsArgWith(1, null, @fakeInvites)
@call = (callback) =>
@CollaboratorsInviteHandler.getAllInvites @projectId, callback
describe 'when all goes well', ->
beforeEach ->
it 'should not produce an error', (done) ->
@call (err, invites) =>
expect(err).to.not.be.instanceof Error
expect(err).to.be.oneOf [null, undefined]
done()
it 'should produce a list of invite objects', (done) ->
@call (err, invites) =>
expect(invites).to.not.be.oneOf [null, undefined]
expect(invites).to.deep.equal @fakeInvites
done()
it 'should have called ProjectInvite.find', (done) ->
@call (err, invites) =>
@ProjectInvite.find.callCount.should.equal 1
@ProjectInvite.find.calledWith({projectId: @projectId}).should.equal true
done()
describe 'when ProjectInvite.find produces an error', ->
beforeEach ->
@ProjectInvite.find.callsArgWith(1, new Error('woops'))
it 'should produce an error', (done) ->
@call (err, invites) =>
expect(err).to.be.instanceof Error
done()
describe 'inviteToProject', ->
beforeEach ->