Use the id in methods that modify a subscription
This will make it easier to allow a user to manage multiple groups.
This commit is contained in:
@@ -23,6 +23,7 @@ describe "LimitationsManager", ->
|
||||
|
||||
@SubscriptionLocator =
|
||||
getUsersSubscription: sinon.stub()
|
||||
getSubscription: sinon.stub()
|
||||
|
||||
@LimitationsManager = SandboxedModule.require modulePath, requires:
|
||||
'../Project/ProjectGetter': @ProjectGetter
|
||||
@@ -310,21 +311,21 @@ describe "LimitationsManager", ->
|
||||
]
|
||||
|
||||
it "should return true if the limit is hit (including members and invites)", (done)->
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
|
||||
@SubscriptionLocator.getSubscription.callsArgWith(1, null, @subscription)
|
||||
@LimitationsManager.hasGroupMembersLimitReached @user_id, (err, limitReached)->
|
||||
limitReached.should.equal true
|
||||
done()
|
||||
|
||||
it "should return false if the limit is not hit (including members and invites)", (done)->
|
||||
@subscription.membersLimit = 4
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
|
||||
@SubscriptionLocator.getSubscription.callsArgWith(1, null, @subscription)
|
||||
@LimitationsManager.hasGroupMembersLimitReached @user_id, (err, limitReached)->
|
||||
limitReached.should.equal false
|
||||
done()
|
||||
|
||||
it "should return true if the limit has been exceded (including members and invites)", (done)->
|
||||
@subscription.membersLimit = 2
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
|
||||
@SubscriptionLocator.getSubscription.callsArgWith(1, null, @subscription)
|
||||
@LimitationsManager.hasGroupMembersLimitReached @user_id, (err, limitReached)->
|
||||
limitReached.should.equal true
|
||||
done()
|
||||
@@ -379,4 +380,3 @@ describe "LimitationsManager", ->
|
||||
@V1SubscriptionManager.getSubscriptionsFromV1.calledWith(@user_id).should.equal true
|
||||
result.should.equal false
|
||||
done()
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ describe "SubscriptionGroupController", ->
|
||||
beforeEach ->
|
||||
@user = {_id:"!@312431",email:"user@email.com"}
|
||||
@adminUserId = "123jlkj"
|
||||
@subscription_id = "123434325412"
|
||||
@subscriptionId = "123434325412"
|
||||
@user_email = "bob@gmail.com"
|
||||
@req =
|
||||
session:
|
||||
@@ -18,15 +18,19 @@ describe "SubscriptionGroupController", ->
|
||||
_id: @adminUserId
|
||||
email:@user_email
|
||||
params:
|
||||
subscription_id:@subscription_id
|
||||
subscriptionId:@subscriptionId
|
||||
query:{}
|
||||
@subscription = {}
|
||||
@subscription = {
|
||||
_id: @subscriptionId
|
||||
}
|
||||
@GroupHandler =
|
||||
addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
|
||||
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
||||
isUserPartOfGroup: sinon.stub()
|
||||
getPopulatedListOfMembers: sinon.stub().callsArgWith(1, null, [@user])
|
||||
@SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
||||
@SubscriptionLocator =
|
||||
getManagedSubscription: sinon.stub().callsArgWith(1, null, @subscription)
|
||||
|
||||
@AuthenticationController =
|
||||
getLoggedInUserId: (req) -> req.session.user._id
|
||||
getSessionUser: (req) -> req.session.user
|
||||
@@ -55,25 +59,25 @@ describe "SubscriptionGroupController", ->
|
||||
|
||||
describe "addUserToGroup", ->
|
||||
|
||||
it "should use the admin id for the logged in user and take the email address from the body", (done)->
|
||||
it "should use the subscription id for the logged in user and take the email address from the body", (done)->
|
||||
newEmail = " boB@gmaiL.com "
|
||||
@req.body = email: newEmail
|
||||
res =
|
||||
json : (data)=>
|
||||
@GroupHandler.addUserToGroup.calledWith(@adminUserId, "bob@gmail.com").should.equal true
|
||||
@GroupHandler.addUserToGroup.calledWith(@subscriptionId, "bob@gmail.com").should.equal true
|
||||
data.user.should.deep.equal @user
|
||||
done()
|
||||
@Controller.addUserToGroup @req, res
|
||||
|
||||
|
||||
describe "removeUserFromGroup", ->
|
||||
it "should use the admin id for the logged in user and take the user id from the params", (done)->
|
||||
it "should use the subscription id for the logged in user and take the user id from the params", (done)->
|
||||
userIdToRemove = "31231"
|
||||
@req.params = user_id: userIdToRemove
|
||||
|
||||
res =
|
||||
send : =>
|
||||
@GroupHandler.removeUserFromGroup.calledWith(@adminUserId, userIdToRemove).should.equal true
|
||||
@GroupHandler.removeUserFromGroup.calledWith(@subscriptionId, userIdToRemove).should.equal true
|
||||
done()
|
||||
@Controller.removeUserFromGroup @req, res
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ describe "SubscriptionGroupHandler", ->
|
||||
beforeEach ->
|
||||
@LimitationsManager.hasGroupMembersLimitReached.callsArgWith(1, null, false, @subscription)
|
||||
@UserGetter.getUserByAnyEmail.callsArgWith(1, null, @user)
|
||||
|
||||
|
||||
it "should find the user", (done)->
|
||||
@Handler.addUserToGroup @adminUser_id, @newEmail, (err)=>
|
||||
@UserGetter.getUserByAnyEmail.calledWith(@newEmail).should.equal true
|
||||
@@ -156,13 +156,13 @@ describe "SubscriptionGroupHandler", ->
|
||||
describe "getPopulatedListOfMembers", ->
|
||||
beforeEach ->
|
||||
@subscription = {}
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
|
||||
@SubscriptionLocator.getSubscription.callsArgWith(1, null, @subscription)
|
||||
@UserGetter.getUser.callsArgWith(1, null, {_id:"31232"})
|
||||
|
||||
it "should locate the subscription", (done)->
|
||||
@UserGetter.getUser.callsArgWith(1, null, {_id:"31232"})
|
||||
@Handler.getPopulatedListOfMembers @adminUser_id, (err, users)=>
|
||||
@SubscriptionLocator.getUsersSubscription.calledWith(@adminUser_id).should.equal true
|
||||
@Handler.getPopulatedListOfMembers @subscriptionId, (err, users)=>
|
||||
@SubscriptionLocator.getSubscription.calledWith(@subscriptionId).should.equal true
|
||||
done()
|
||||
|
||||
it "should get the users by id", (done)->
|
||||
|
||||
@@ -18,6 +18,7 @@ describe "SubscriptionUpdater", ->
|
||||
@otherUserId = "5208dd34438842e2db000005"
|
||||
@allUserIds = ["13213", "dsadas", "djsaiud89"]
|
||||
@subscription = subscription =
|
||||
_id: "111111111111111111111111"
|
||||
admin_id: @adminUser._id
|
||||
member_ids: @allUserIds
|
||||
save: sinon.stub().callsArgWith(0)
|
||||
@@ -26,6 +27,7 @@ describe "SubscriptionUpdater", ->
|
||||
@user_id = @adminuser_id
|
||||
|
||||
@groupSubscription =
|
||||
_id: "222222222222222222222222"
|
||||
admin_id: @adminUser._id
|
||||
member_ids: @allUserIds
|
||||
save: sinon.stub().callsArgWith(0)
|
||||
@@ -158,9 +160,9 @@ describe "SubscriptionUpdater", ->
|
||||
@SubscriptionUpdater.addUsersToGroup = sinon.stub().yields(null)
|
||||
|
||||
it "delegates to addUsersToGroup", (done)->
|
||||
@SubscriptionUpdater.addUserToGroup @adminUser._id, @otherUserId, =>
|
||||
@SubscriptionUpdater.addUserToGroup @subscription._id, @otherUserId, =>
|
||||
@SubscriptionUpdater.addUsersToGroup
|
||||
.calledWith(@adminUser._id, [@otherUserId]).should.equal true
|
||||
.calledWith(@subscription._id, [@otherUserId]).should.equal true
|
||||
done()
|
||||
|
||||
describe "addUsersToGroup", ->
|
||||
@@ -168,16 +170,16 @@ describe "SubscriptionUpdater", ->
|
||||
@FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
|
||||
|
||||
it "should add the user ids to the group as a set", (done)->
|
||||
@SubscriptionUpdater.addUsersToGroup @adminUser._id, [@otherUserId], =>
|
||||
@SubscriptionUpdater.addUsersToGroup @subscription._id, [@otherUserId], =>
|
||||
searchOps =
|
||||
admin_id: @adminUser._id
|
||||
_id: @subscription._id
|
||||
insertOperation =
|
||||
{ $push: { member_ids: { $each: [@otherUserId] } } }
|
||||
@findAndModifyStub.calledWith(searchOps, insertOperation).should.equal true
|
||||
done()
|
||||
|
||||
it "should update the users features", (done)->
|
||||
@SubscriptionUpdater.addUserToGroup @adminUser._id, @otherUserId, =>
|
||||
@SubscriptionUpdater.addUserToGroup @subscription._id, @otherUserId, =>
|
||||
@FeaturesUpdater.refreshFeatures.calledWith(@otherUserId).should.equal true
|
||||
done()
|
||||
|
||||
@@ -186,16 +188,16 @@ describe "SubscriptionUpdater", ->
|
||||
@FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1)
|
||||
|
||||
it "should pull the users id from the group", (done)->
|
||||
@SubscriptionUpdater.removeUserFromGroup @adminUser._id, @otherUserId, =>
|
||||
@SubscriptionUpdater.removeUserFromGroup @subscription._id, @otherUserId, =>
|
||||
searchOps =
|
||||
admin_id:@adminUser._id
|
||||
_id: @subscription._id
|
||||
removeOperation =
|
||||
"$pull": {member_ids:@otherUserId}
|
||||
@updateStub.calledWith(searchOps, removeOperation).should.equal true
|
||||
done()
|
||||
|
||||
it "should update the users features", (done)->
|
||||
@SubscriptionUpdater.removeUserFromGroup @adminUser._id, @otherUserId, =>
|
||||
@SubscriptionUpdater.removeUserFromGroup @subscription._id, @otherUserId, =>
|
||||
@FeaturesUpdater.refreshFeatures.calledWith(@otherUserId).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user