|
@@ -12,6 +12,11 @@ describe "SubscriptionGroupHandler", ->
|
|
|
@newEmail = "bob@smith.com"
|
|
@newEmail = "bob@smith.com"
|
|
|
@user_id = "3121321"
|
|
@user_id = "3121321"
|
|
|
@user = {_id:@user_id, email:@newEmail}
|
|
@user = {_id:@user_id, email:@newEmail}
|
|
|
|
|
+ @subscription_id = "31DSd1123D"
|
|
|
|
|
+
|
|
|
|
|
+ @subscription =
|
|
|
|
|
+ admin_id:@adminUser_id
|
|
|
|
|
+ _id:@subscription_id
|
|
|
|
|
|
|
|
@SubscriptionLocator =
|
|
@SubscriptionLocator =
|
|
|
getUsersSubscription: sinon.stub()
|
|
getUsersSubscription: sinon.stub()
|
|
@@ -41,6 +46,10 @@ describe "SubscriptionGroupHandler", ->
|
|
|
@settings =
|
|
@settings =
|
|
|
siteUrl:"http://www.sharelatex.com"
|
|
siteUrl:"http://www.sharelatex.com"
|
|
|
|
|
|
|
|
|
|
+ @readStub = sinon.stub()
|
|
|
|
|
+ @NotificationsBuilder =
|
|
|
|
|
+ groupPlan: sinon.stub().returns({read:@readStub})
|
|
|
|
|
+
|
|
|
@Handler = SandboxedModule.require modulePath, requires:
|
|
@Handler = SandboxedModule.require modulePath, requires:
|
|
|
"logger-sharelatex": log:->
|
|
"logger-sharelatex": log:->
|
|
|
"../User/UserCreator": @UserCreator
|
|
"../User/UserCreator": @UserCreator
|
|
@@ -51,6 +60,7 @@ describe "SubscriptionGroupHandler", ->
|
|
|
"../Security/OneTimeTokenHandler":@OneTimeTokenHandler
|
|
"../Security/OneTimeTokenHandler":@OneTimeTokenHandler
|
|
|
"../Email/EmailHandler":@EmailHandler
|
|
"../Email/EmailHandler":@EmailHandler
|
|
|
"settings-sharelatex":@settings
|
|
"settings-sharelatex":@settings
|
|
|
|
|
+ "../Notifications/NotificationsBuilder": @NotificationsBuilder
|
|
|
"logger-sharelatex":
|
|
"logger-sharelatex":
|
|
|
err:->
|
|
err:->
|
|
|
log:->
|
|
log:->
|
|
@@ -59,28 +69,36 @@ describe "SubscriptionGroupHandler", ->
|
|
|
describe "addUserToGroup", ->
|
|
describe "addUserToGroup", ->
|
|
|
it "should find or create the user", (done)->
|
|
it "should find or create the user", (done)->
|
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false)
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false)
|
|
|
- @Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
|
|
|
|
|
|
+ @Handler.addUserToGroup @subscription, @newEmail, (err)=>
|
|
|
@UserCreator.getUserOrCreateHoldingAccount.calledWith(@newEmail).should.equal true
|
|
@UserCreator.getUserOrCreateHoldingAccount.calledWith(@newEmail).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should add the user to the group", (done)->
|
|
it "should add the user to the group", (done)->
|
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false)
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false)
|
|
|
- @Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
|
|
|
|
|
|
+ @Handler.addUserToGroup @subscription, @newEmail, (err)=>
|
|
|
@SubscriptionUpdater.addUserToGroup.calledWith(@adminUser_id, @user._id).should.equal true
|
|
@SubscriptionUpdater.addUserToGroup.calledWith(@adminUser_id, @user._id).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should not add the user to the group if the limit has been reached", (done)->
|
|
it "should not add the user to the group if the limit has been reached", (done)->
|
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, true)
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, true)
|
|
|
- @Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
|
|
|
|
|
|
+ @Handler.addUserToGroup @subscription, @newEmail, (err)=>
|
|
|
@SubscriptionUpdater.addUserToGroup.called.should.equal false
|
|
@SubscriptionUpdater.addUserToGroup.called.should.equal false
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should return error that limit has been reached", (done)->
|
|
it "should return error that limit has been reached", (done)->
|
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, true)
|
|
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, true)
|
|
|
- @Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
|
|
|
|
|
|
+ @Handler.addUserToGroup @subscription, @newEmail, (err)=>
|
|
|
err.limitReached.should.equal true
|
|
err.limitReached.should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
|
|
+ it "should mark any notification as read if it is part of a licence", (done)->
|
|
|
|
|
+ @LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false)
|
|
|
|
|
+ @Handler.addUserToGroup @subscription, @newEmail, (err)=>
|
|
|
|
|
+ @NotificationsBuilder.groupPlan.calledWith(@user, {subscription_id:@subscription._id}).should.equal true
|
|
|
|
|
+ @readStub.called.should.equal true
|
|
|
|
|
+ done()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
describe "removeUserFromGroup", ->
|
|
describe "removeUserFromGroup", ->
|
|
|
|
|
|
|
|
it "should call the subscription updater to remove the user", (done)->
|
|
it "should call the subscription updater to remove the user", (done)->
|
|
@@ -157,15 +175,14 @@ describe "SubscriptionGroupHandler", ->
|
|
|
describe "processGroupVerification", ->
|
|
describe "processGroupVerification", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@token = "31dDAd2Da"
|
|
@token = "31dDAd2Da"
|
|
|
- @subscription_id = "31DSd1123D"
|
|
|
|
|
@admin_id = "eDSda1ew"
|
|
@admin_id = "eDSda1ew"
|
|
|
- @SubscriptionLocator.getSubscription.callsArgWith(1, null, {admin_id:@admin_id})
|
|
|
|
|
|
|
+ @SubscriptionLocator.getSubscription.callsArgWith(1, null, @Subscription)
|
|
|
@Handler.addUserToGroup = sinon.stub().callsArgWith(2)
|
|
@Handler.addUserToGroup = sinon.stub().callsArgWith(2)
|
|
|
|
|
|
|
|
it "should addUserToGroup", (done)->
|
|
it "should addUserToGroup", (done)->
|
|
|
@OneTimeTokenHandler.getValueFromTokenAndExpire.callsArgWith(1, null, @subscription_id)
|
|
@OneTimeTokenHandler.getValueFromTokenAndExpire.callsArgWith(1, null, @subscription_id)
|
|
|
@Handler.processGroupVerification @email, @subscription_id, @token, (err)=>
|
|
@Handler.processGroupVerification @email, @subscription_id, @token, (err)=>
|
|
|
- @Handler.addUserToGroup.calledWith(@admin_id, @email).should.equal true
|
|
|
|
|
|
|
+ @Handler.addUserToGroup.calledWith(@Subscription, @email).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
it "should return token_not_found error if it couldn't get the token", (done)->
|
|
it "should return token_not_found error if it couldn't get the token", (done)->
|