|
@@ -11,6 +11,13 @@ ObjectId = require("mongojs").ObjectId
|
|
|
|
|
|
|
|
describe "CollaboratorsInviteController", ->
|
|
describe "CollaboratorsInviteController", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
|
|
+ @User = class User
|
|
|
|
|
+ constructor: (options={}) -> this
|
|
|
|
|
+ @findOne: sinon.stub()
|
|
|
|
|
+ @Project = class Project
|
|
|
|
|
+ constructor: () ->
|
|
|
|
|
+ this
|
|
|
|
|
+ @findOne: sinon.stub()
|
|
|
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
|
@CollaboratorsInviteController = SandboxedModule.require modulePath, requires:
|
|
|
"../Project/ProjectGetter": @ProjectGetter = {}
|
|
"../Project/ProjectGetter": @ProjectGetter = {}
|
|
|
"./CollaboratorsInviteHandler": @CollaboratorsInviteHandler = {}
|
|
"./CollaboratorsInviteHandler": @CollaboratorsInviteHandler = {}
|
|
@@ -18,6 +25,8 @@ describe "CollaboratorsInviteController", ->
|
|
|
'../Subscription/LimitationsManager' : @LimitationsManager = {}
|
|
'../Subscription/LimitationsManager' : @LimitationsManager = {}
|
|
|
'../Project/ProjectEditorHandler' : @ProjectEditorHandler = {}
|
|
'../Project/ProjectEditorHandler' : @ProjectEditorHandler = {}
|
|
|
'../User/UserGetter': @UserGetter = {}
|
|
'../User/UserGetter': @UserGetter = {}
|
|
|
|
|
+ '../../models/Project': {Project: @Project}
|
|
|
|
|
+ '../../models/User': {User; @User}
|
|
|
'logger-sharelatex': @logger = {err: sinon.stub(), error: sinon.stub(), log: sinon.stub()}
|
|
'logger-sharelatex': @logger = {err: sinon.stub(), error: sinon.stub(), log: sinon.stub()}
|
|
|
@res = new MockResponse()
|
|
@res = new MockResponse()
|
|
|
@req = new MockRequest()
|
|
@req = new MockRequest()
|
|
@@ -169,10 +178,21 @@ describe "CollaboratorsInviteController", ->
|
|
|
_id: ObjectId(),
|
|
_id: ObjectId(),
|
|
|
token: "htnseuthaouse",
|
|
token: "htnseuthaouse",
|
|
|
sendingUserId: ObjectId(),
|
|
sendingUserId: ObjectId(),
|
|
|
- projectId: @projectId,
|
|
|
|
|
|
|
+ projectId: @project_id,
|
|
|
targetEmail: 'user@example.com'
|
|
targetEmail: 'user@example.com'
|
|
|
createdAt: new Date(),
|
|
createdAt: new Date(),
|
|
|
}
|
|
}
|
|
|
|
|
+ @fakeProject =
|
|
|
|
|
+ _id: @project_id
|
|
|
|
|
+ name: "some project"
|
|
|
|
|
+ owner_ref: @invite.sendingUserId
|
|
|
|
|
+ @owner =
|
|
|
|
|
+ _id: @fakeProject.owner_ref
|
|
|
|
|
+ first_name: "John"
|
|
|
|
|
+ last_name: "Doe"
|
|
|
|
|
+ email: "john@example.com"
|
|
|
|
|
+ @Project.findOne.callsArgWith(2, null, @fakeProject)
|
|
|
|
|
+ @User.findOne.callsArgWith(2, null, @owner)
|
|
|
@CollaboratorsInviteHandler.getInviteByToken = sinon.stub().callsArgWith(2, null, @invite)
|
|
@CollaboratorsInviteHandler.getInviteByToken = sinon.stub().callsArgWith(2, null, @invite)
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
|
@next = sinon.stub()
|
|
@next = sinon.stub()
|
|
@@ -277,7 +297,7 @@ describe "CollaboratorsInviteController", ->
|
|
|
@req.body =
|
|
@req.body =
|
|
|
token: "thsueothaueotauahsuet"
|
|
token: "thsueothaueotauahsuet"
|
|
|
@res.render = sinon.stub()
|
|
@res.render = sinon.stub()
|
|
|
- @res.sendStatus = sinon.stub()
|
|
|
|
|
|
|
+ @res.redirect = sinon.stub()
|
|
|
@CollaboratorsInviteHandler.acceptInvite = sinon.stub().callsArgWith(4, null)
|
|
@CollaboratorsInviteHandler.acceptInvite = sinon.stub().callsArgWith(4, null)
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
|
@next = sinon.stub()
|
|
@next = sinon.stub()
|
|
@@ -287,9 +307,9 @@ describe "CollaboratorsInviteController", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@CollaboratorsInviteController.acceptInvite @req, @res, @next
|
|
@CollaboratorsInviteController.acceptInvite @req, @res, @next
|
|
|
|
|
|
|
|
- it 'should produce a 201 response', ->
|
|
|
|
|
- @res.sendStatus.callCount.should.equal 1
|
|
|
|
|
- @res.sendStatus.calledWith(201).should.equal true
|
|
|
|
|
|
|
+ it 'should redirect to project page', () ->
|
|
|
|
|
+ @res.redirect.callCount.should.equal 1
|
|
|
|
|
+ @res.redirect.calledWith("/project/#{@project_id}").should.equal true
|
|
|
|
|
|
|
|
it 'should have called acceptInvite', ->
|
|
it 'should have called acceptInvite', ->
|
|
|
@CollaboratorsInviteHandler.acceptInvite.callCount.should.equal 1
|
|
@CollaboratorsInviteHandler.acceptInvite.callCount.should.equal 1
|
|
@@ -301,8 +321,8 @@ describe "CollaboratorsInviteController", ->
|
|
|
@CollaboratorsInviteHandler.acceptInvite = sinon.stub().callsArgWith(4, @err)
|
|
@CollaboratorsInviteHandler.acceptInvite = sinon.stub().callsArgWith(4, @err)
|
|
|
@CollaboratorsInviteController.acceptInvite @req, @res, @next
|
|
@CollaboratorsInviteController.acceptInvite @req, @res, @next
|
|
|
|
|
|
|
|
- it 'should not produce a 201 response', ->
|
|
|
|
|
- @res.sendStatus.callCount.should.equal 0
|
|
|
|
|
|
|
+ it 'should not redirect to project page', ->
|
|
|
|
|
+ @res.redirect.callCount.should.equal 0
|
|
|
|
|
|
|
|
it 'should call next with the error', ->
|
|
it 'should call next with the error', ->
|
|
|
@next.callCount.should.equal 1
|
|
@next.callCount.should.equal 1
|