|
|
@@ -13,16 +13,42 @@ describe "Subscription Group Controller", ->
|
|
|
@GroupHandler =
|
|
|
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
|
|
|
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
|
|
+ isUserPartOfGroup: sinon.stub()
|
|
|
+ sendVerificationEmail:sinon.stub()
|
|
|
+ processGroupVerification:sinon.stub()
|
|
|
+
|
|
|
@SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
|
|
|
|
|
+ @SubscriptionDomainAllocator =
|
|
|
+ findDomainLicenceBySubscriptionId:sinon.stub()
|
|
|
+
|
|
|
+ @OneTimeTokenHandler =
|
|
|
+ getValueFromTokenAndExpire:sinon.stub()
|
|
|
+
|
|
|
+
|
|
|
+ @ErrorsController =
|
|
|
+ notFound:sinon.stub()
|
|
|
+
|
|
|
@Controller = SandboxedModule.require modulePath, requires:
|
|
|
"./SubscriptionGroupHandler":@GroupHandler
|
|
|
"logger-sharelatex": log:->
|
|
|
"./SubscriptionLocator": @SubscriptionLocator
|
|
|
+ "./SubscriptionDomainAllocator":@SubscriptionDomainAllocator
|
|
|
+ "../Errors/ErrorController":@ErrorsController
|
|
|
+
|
|
|
@adminUserId = "123jlkj"
|
|
|
+ @subscription_id = "123434325412"
|
|
|
+ @user_email = "bob@gmail.com"
|
|
|
@req =
|
|
|
session:
|
|
|
- user: _id: @adminUserId
|
|
|
+ user:
|
|
|
+ _id: @adminUserId
|
|
|
+ email:@user_email
|
|
|
+ params:
|
|
|
+ subscription_id:@subscription_id
|
|
|
+ query:{}
|
|
|
+
|
|
|
+ @token = "super-secret-token"
|
|
|
|
|
|
|
|
|
describe "addUserToGroup", ->
|
|
|
@@ -59,3 +85,85 @@ describe "Subscription Group Controller", ->
|
|
|
path.should.equal("/")
|
|
|
done()
|
|
|
@Controller.renderSubscriptionGroupAdminPage @req, res
|
|
|
+
|
|
|
+
|
|
|
+ describe "renderGroupInvitePage", ->
|
|
|
+ describe "with a valid licence", ->
|
|
|
+ beforeEach ->
|
|
|
+ @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns({subscription_id:@subscription_id, adminUser_id:@adminUserId})
|
|
|
+
|
|
|
+ it "should render subscriptions/group/invite if not part of group", (done)->
|
|
|
+ @GroupHandler.isUserPartOfGroup.callsArgWith(2, null, false)
|
|
|
+ res =
|
|
|
+ render : (pageName)=>
|
|
|
+ pageName.should.equal "subscriptions/group/invite"
|
|
|
+ done()
|
|
|
+ @Controller.renderGroupInvitePage @req, res
|
|
|
+
|
|
|
+ it "should redirect to custom page if is already part of group", (done)->
|
|
|
+ @GroupHandler.isUserPartOfGroup.callsArgWith(2, null, true)
|
|
|
+ res =
|
|
|
+ redirect : (location)=>
|
|
|
+ location.should.equal "/user/subscription/custom_account"
|
|
|
+ done()
|
|
|
+ @Controller.renderGroupInvitePage @req, res
|
|
|
+
|
|
|
+ describe "without a valid licence", ->
|
|
|
+ beforeEach ->
|
|
|
+ @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns(undefined)
|
|
|
+
|
|
|
+ it "should send a 500", (done)->
|
|
|
+ @Controller.renderGroupInvitePage @req, {}
|
|
|
+ @ErrorsController.notFound.called.should.equal true
|
|
|
+ done()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ describe "beginJoinGroup", ->
|
|
|
+ describe "with a valid licence", ->
|
|
|
+ beforeEach ->
|
|
|
+ @licenceName = "get amazing licence"
|
|
|
+ @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns({name:@licenceName})
|
|
|
+ @GroupHandler.sendVerificationEmail.callsArgWith(3)
|
|
|
+
|
|
|
+ it "should ask the SubscriptionGroupHandler to send the verification email", (done)->
|
|
|
+ res =
|
|
|
+ send : (statusCode)=>
|
|
|
+ statusCode.should.equal 200
|
|
|
+ @GroupHandler.sendVerificationEmail.calledWith(@subscription_id, @licenceName, @user_email).should.equal true
|
|
|
+ done()
|
|
|
+ @Controller.beginJoinGroup @req, res
|
|
|
+
|
|
|
+ describe "without a valid licence", ->
|
|
|
+ beforeEach ->
|
|
|
+ @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns(undefined)
|
|
|
+
|
|
|
+ it "should send a 500", (done)->
|
|
|
+ @Controller.beginJoinGroup @req, {}
|
|
|
+ @ErrorsController.notFound.called.should.equal true
|
|
|
+ done()
|
|
|
+
|
|
|
+
|
|
|
+ describe "completeJoin", ->
|
|
|
+ describe "with a valid licence", ->
|
|
|
+ beforeEach ->
|
|
|
+ @GroupHandler.processGroupVerification.callsArgWith(3)
|
|
|
+ @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns({name:@licenceName})
|
|
|
+
|
|
|
+ it "should redirect to the success page upon processGroupVerification", (done)->
|
|
|
+ @req.query.token = @token
|
|
|
+ res =
|
|
|
+ redirect : (location)=>
|
|
|
+ @GroupHandler.processGroupVerification.calledWith(@user_email, @subscription_id, @token).should.equal true
|
|
|
+ location.should.equal "/user/subscription/#{@subscription_id}/group/successful-join"
|
|
|
+ done()
|
|
|
+ @Controller.completeJoin @req, res
|
|
|
+
|
|
|
+ describe "without a valid licence", ->
|
|
|
+ beforeEach ->
|
|
|
+ @SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId.returns(undefined)
|
|
|
+
|
|
|
+ it "should send a 500", (done)->
|
|
|
+ @Controller.completeJoin @req, {}
|
|
|
+ @ErrorsController.notFound.called.should.equal true
|
|
|
+ done()
|