2014-02-12 05:23:40 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
should = require('chai').should()
|
|
|
|
sinon = require 'sinon'
|
|
|
|
assert = require("chai").assert
|
|
|
|
modulePath = "../../../../app/js/Features/Subscription/SubscriptionGroupHandler"
|
|
|
|
|
|
|
|
|
2015-06-01 07:43:42 -04:00
|
|
|
describe "SubscriptionGroupHandler", ->
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@adminUser_id = "12321"
|
|
|
|
@newEmail = "bob@smith.com"
|
2015-05-27 11:33:47 -04:00
|
|
|
@user_id = "3121321"
|
2017-06-08 07:12:08 -04:00
|
|
|
@email = "jim@example.com"
|
2015-05-27 11:33:47 -04:00
|
|
|
@user = {_id:@user_id, email:@newEmail}
|
2016-02-18 06:43:43 -05:00
|
|
|
@subscription_id = "31DSd1123D"
|
|
|
|
|
|
|
|
@subscription =
|
2018-06-29 12:01:34 -04:00
|
|
|
admin_id: @adminUser_id
|
|
|
|
manager_ids: [@adminUser_id]
|
2016-02-18 06:43:43 -05:00
|
|
|
_id:@subscription_id
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-05-29 10:35:46 -04:00
|
|
|
@SubscriptionLocator =
|
2014-02-12 05:23:40 -05:00
|
|
|
getUsersSubscription: sinon.stub()
|
2015-05-27 11:33:47 -04:00
|
|
|
getSubscriptionByMemberIdAndId: sinon.stub()
|
2015-05-27 15:50:16 -04:00
|
|
|
getSubscription: sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-05-29 10:35:46 -04:00
|
|
|
@UserCreator =
|
2014-02-12 05:23:40 -05:00
|
|
|
getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user)
|
|
|
|
|
|
|
|
@SubscriptionUpdater =
|
|
|
|
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
2018-06-01 06:23:25 -04:00
|
|
|
|
|
|
|
@TeamInvitesHandler =
|
2018-06-07 10:35:18 -04:00
|
|
|
createInvite: sinon.stub().callsArgWith(2)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-05-23 10:12:23 -04:00
|
|
|
@UserGetter =
|
2018-05-24 09:55:12 -04:00
|
|
|
getUser: sinon.stub()
|
2018-05-28 10:09:22 -04:00
|
|
|
getUserByAnyEmail: sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
@LimitationsManager =
|
|
|
|
hasGroupMembersLimitReached: sinon.stub()
|
|
|
|
|
2015-05-27 15:50:16 -04:00
|
|
|
@OneTimeTokenHandler =
|
|
|
|
getValueFromTokenAndExpire:sinon.stub()
|
|
|
|
getNewToken:sinon.stub()
|
|
|
|
|
|
|
|
@EmailHandler =
|
|
|
|
sendEmail:sinon.stub()
|
|
|
|
|
2018-05-29 10:35:46 -04:00
|
|
|
@Subscription =
|
|
|
|
update: sinon.stub().yields()
|
|
|
|
|
|
|
|
@settings =
|
2015-05-27 15:50:16 -04:00
|
|
|
siteUrl:"http://www.sharelatex.com"
|
|
|
|
|
2016-02-18 06:43:43 -05:00
|
|
|
@readStub = sinon.stub()
|
|
|
|
@NotificationsBuilder =
|
|
|
|
groupPlan: sinon.stub().returns({read:@readStub})
|
|
|
|
|
2018-10-25 11:08:19 -04:00
|
|
|
@UserMembershipViewModel =
|
|
|
|
build: (email) -> { email }
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
@Handler = SandboxedModule.require modulePath, requires:
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
"../User/UserCreator": @UserCreator
|
|
|
|
"./SubscriptionUpdater": @SubscriptionUpdater
|
2018-06-01 06:23:25 -04:00
|
|
|
"./TeamInvitesHandler": @TeamInvitesHandler
|
2014-02-12 05:23:40 -05:00
|
|
|
"./SubscriptionLocator": @SubscriptionLocator
|
2018-05-29 10:35:46 -04:00
|
|
|
"../../models/Subscription": Subscription: @Subscription
|
2018-05-23 10:12:23 -04:00
|
|
|
"../User/UserGetter": @UserGetter
|
2014-02-12 05:23:40 -05:00
|
|
|
"./LimitationsManager": @LimitationsManager
|
2015-05-27 15:50:16 -04:00
|
|
|
"../Security/OneTimeTokenHandler":@OneTimeTokenHandler
|
|
|
|
"../Email/EmailHandler":@EmailHandler
|
|
|
|
"settings-sharelatex":@settings
|
2016-02-18 06:43:43 -05:00
|
|
|
"../Notifications/NotificationsBuilder": @NotificationsBuilder
|
2018-10-25 11:08:19 -04:00
|
|
|
"../UserMembership/UserMembershipViewModel": @UserMembershipViewModel
|
2018-05-29 10:35:46 -04:00
|
|
|
"logger-sharelatex":
|
2015-05-27 15:50:16 -04:00
|
|
|
err:->
|
|
|
|
log:->
|
2016-02-22 11:50:41 -05:00
|
|
|
warn:->
|
2015-05-27 15:50:16 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "removeUserFromGroup", ->
|
|
|
|
|
|
|
|
it "should call the subscription updater to remove the user", (done)->
|
|
|
|
@Handler.removeUserFromGroup @adminUser_id, @user._id, (err)=>
|
|
|
|
@SubscriptionUpdater.removeUserFromGroup.calledWith(@adminUser_id, @user._id).should.equal true
|
|
|
|
done()
|
|
|
|
|
2018-05-29 10:35:46 -04:00
|
|
|
describe "replaceUserReferencesInGroups", ->
|
2018-06-29 12:01:34 -04:00
|
|
|
beforeEach (done)->
|
2018-05-29 10:35:46 -04:00
|
|
|
@oldId = "ba5eba11"
|
|
|
|
@newId = "5ca1ab1e"
|
2018-06-29 12:01:34 -04:00
|
|
|
@Handler.replaceUserReferencesInGroups @oldId, @newId, ->
|
|
|
|
done()
|
2018-05-29 10:35:46 -04:00
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
it "replaces the admin_id", ->
|
2018-05-29 10:35:46 -04:00
|
|
|
@Subscription.update.calledWith(
|
|
|
|
{ admin_id: @oldId },
|
|
|
|
{ admin_id: @newId }
|
|
|
|
).should.equal true
|
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
it "replaces the manager_ids", ->
|
2018-05-29 10:35:46 -04:00
|
|
|
@Subscription.update.calledWith(
|
2018-06-29 12:01:34 -04:00
|
|
|
{manager_ids:"ba5eba11"},{$addToSet:{manager_ids:"5ca1ab1e"}},{multi:true}
|
2018-05-29 10:35:46 -04:00
|
|
|
).should.equal true
|
|
|
|
|
|
|
|
@Subscription.update.calledWith(
|
2018-06-29 12:01:34 -04:00
|
|
|
{manager_ids:"ba5eba11"},{$pull:{manager_ids:"ba5eba11"}},{multi:true}
|
2018-05-29 10:35:46 -04:00
|
|
|
).should.equal true
|
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
it "replaces the member ids", ->
|
|
|
|
@Subscription.update.calledWith(
|
|
|
|
{ member_ids: @oldId },
|
|
|
|
{ $addToSet: { member_ids: @newId } }
|
|
|
|
).should.equal true
|
|
|
|
|
|
|
|
@Subscription.update.calledWith(
|
|
|
|
{ member_ids: @oldId },
|
|
|
|
{ $pull: { member_ids: @oldId } }
|
|
|
|
).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-05-27 11:33:47 -04:00
|
|
|
describe "isUserPartOfGroup", ->
|
|
|
|
beforeEach ->
|
|
|
|
@subscription_id = "123ed13123"
|
|
|
|
|
|
|
|
it "should return true when user is part of subscription", (done)->
|
|
|
|
@SubscriptionLocator.getSubscriptionByMemberIdAndId.callsArgWith(2, null, {_id:@subscription_id})
|
|
|
|
@Handler.isUserPartOfGroup @user_id, @subscription_id, (err, partOfGroup)->
|
|
|
|
partOfGroup.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should return false when no subscription is found", (done)->
|
|
|
|
@SubscriptionLocator.getSubscriptionByMemberIdAndId.callsArgWith(2, null)
|
|
|
|
@Handler.isUserPartOfGroup @user_id, @subscription_id, (err, partOfGroup)->
|
|
|
|
partOfGroup.should.equal false
|
|
|
|
done()
|