|
|
@@ -35,6 +35,7 @@ describe "CollaboratorsInviteHandler", ->
|
|
|
@email = "user@example.com"
|
|
|
@userId = ObjectId()
|
|
|
@inviteId = ObjectId()
|
|
|
+ @token = 'hnhteaosuhtaeosuahs'
|
|
|
@privileges = "readAndWrite"
|
|
|
|
|
|
describe 'inviteToProject', ->
|
|
|
@@ -56,6 +57,7 @@ describe "CollaboratorsInviteHandler", ->
|
|
|
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 produce the invite object', (done) ->
|
|
|
@@ -96,7 +98,6 @@ describe "CollaboratorsInviteHandler", ->
|
|
|
|
|
|
beforeEach ->
|
|
|
@ProjectInvite.remove.callsArgWith(1, null)
|
|
|
- @CollaboratorsEmailHandler.notifyUserOfProjectInvite = sinon.stub()
|
|
|
@call = (callback) =>
|
|
|
@CollaboratorsInviteHandler.revokeInvite @projectId, @inviteId, callback
|
|
|
|
|
|
@@ -107,6 +108,7 @@ describe "CollaboratorsInviteHandler", ->
|
|
|
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.remove', (done) ->
|
|
|
@@ -124,3 +126,81 @@ describe "CollaboratorsInviteHandler", ->
|
|
|
@call (err) =>
|
|
|
expect(err).to.be.instanceof Error
|
|
|
done()
|
|
|
+
|
|
|
+ describe 'getInviteByToken', ->
|
|
|
+
|
|
|
+ beforeEach ->
|
|
|
+ @theDarkFuture = new Date()
|
|
|
+ @theDarkFuture.setYear(40000)
|
|
|
+ @fakeInvite =
|
|
|
+ _id: @inviteId
|
|
|
+ email: @email
|
|
|
+ token: @token
|
|
|
+ sendingUserId: @sendingUserId
|
|
|
+ projectId: @projectId
|
|
|
+ privileges: @privileges
|
|
|
+ createdAt: new Date()
|
|
|
+ expiresAt: @theDarkFuture
|
|
|
+ @ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
|
|
+ @call = (callback) =>
|
|
|
+ @CollaboratorsInviteHandler.getInviteByToken @projectId, @token, 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 produce the invite object', (done) ->
|
|
|
+ @call (err, invite) =>
|
|
|
+ expect(invite).to.deep.equal @fakeInvite
|
|
|
+ done()
|
|
|
+
|
|
|
+ it 'should call ProjectInvite.findOne', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ @ProjectInvite.findOne.callCount.should.equal 1
|
|
|
+ @ProjectInvite.findOne.calledWith({projectId: @projectId, token: @token}).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) =>
|
|
|
+ expect(err).to.be.instanceof Error
|
|
|
+ done()
|
|
|
+
|
|
|
+ describe 'when findOne does not find an invite', ->
|
|
|
+
|
|
|
+ beforeEach ->
|
|
|
+ @ProjectInvite.findOne.callsArgWith(1, null, null)
|
|
|
+
|
|
|
+ it 'should produce an error', (done) ->
|
|
|
+ @call (err) =>
|
|
|
+ expect(err).to.be.instanceof Error
|
|
|
+ done()
|
|
|
+
|
|
|
+ describe 'when the invite is expired', ->
|
|
|
+
|
|
|
+ beforeEach ->
|
|
|
+ @theDeepPast = new Date()
|
|
|
+ @theDeepPast.setYear(1977)
|
|
|
+ @fakeInvite.expiresAt = @theDeepPast
|
|
|
+ @ProjectInvite.findOne.callsArgWith(1, null, @fakeInvite)
|
|
|
+
|
|
|
+ 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 not produce an invite object', (done) ->
|
|
|
+ @call (err, invite) =>
|
|
|
+ expect(invite).to.be.oneOf [null, undefined]
|
|
|
+ done()
|