From 5f8952450e0deee81391a05b045dc34226daef92 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Tue, 2 Aug 2016 16:08:05 +0100 Subject: [PATCH] Test `getInviteCount` --- .../CollaboratorsInviteHandlerTests.coffee | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteHandlerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteHandlerTests.coffee index e89488598f..4e9a2cc95a 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsInviteHandlerTests.coffee @@ -20,6 +20,7 @@ describe "CollaboratorsInviteHandler", -> @findOne: sinon.stub() @find: sinon.stub() @remove: sinon.stub() + @count: sinon.stub() @Crypto = Crypto @CollaboratorsInviteHandler = SandboxedModule.require modulePath, requires: 'settings-sharelatex': @settings = {} @@ -48,6 +49,34 @@ describe "CollaboratorsInviteHandler", -> privileges: @privileges createdAt: new Date() + describe 'getInviteCount', -> + + beforeEach -> + @ProjectInvite.count.callsArgWith(1, null, 2) + @call = (callback) => + @CollaboratorsInviteHandler.getInviteCount @projectId, callback + + 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 the count of documents', (done) -> + @call (err, count) => + expect(count).to.equal 2 + done() + + describe 'when model.count produces an error', -> + + beforeEach -> + @ProjectInvite.count.callsArgWith(1, new Error('woops')) + + it 'should produce an error', (done) -> + @call (err, count) => + expect(err).to.be.instanceof Error + done() + describe 'getAllInvites', -> beforeEach ->