From 3d719af71e693a837c2ee1efb08ad541b3c47977 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 31 Mar 2016 18:04:20 +0100 Subject: [PATCH] if subscription is downgraded don't use plan code on subscription, use default instead --- .../Features/Subscription/SubscriptionUpdater.coffee | 2 +- .../Subscription/SubscriptionUpdaterTests.coffee | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee index b317be605a..a4a0864d4f 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee @@ -88,7 +88,7 @@ module.exports = SubscriptionUpdater = logger.err err:err, user_id:user, "error getting subscription or group for _setUsersMinimumFeatures" return callback(err) {subscription, groupSubscription} = results - if subscription? and subscription.planCode? + if subscription? and subscription.planCode? and subscription.planCode != Settings.defaultPlanCode logger.log user_id:user_id, "using users subscription plan code for features" UserFeaturesUpdater.updateFeatures user_id, subscription.planCode, callback else if groupSubscription? and groupSubscription.planCode? diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee index 3ae7eee71b..ffef94157b 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee @@ -183,8 +183,6 @@ describe "SubscriptionUpdater", -> describe "_setUsersMinimumFeatures", -> - - it "should call updateFeatures with the subscription if set", (done)-> @SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription) @SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null) @@ -205,6 +203,16 @@ describe "SubscriptionUpdater", -> assert.equal args[1], @groupSubscription.planCode done() + it "should call not call updateFeatures with users subscription if the subscription plan code is the default one (downgraded)", (done)-> + @subscription.planCode = @Settings.defaultPlanCode + @SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription) + @SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null, @groupSubscription) + @SubscriptionUpdater._setUsersMinimumFeatures @adminuser_id, (err)=> + args = @UserFeaturesUpdater.updateFeatures.args[0] + assert.equal args[0], @adminUser._id + assert.equal args[1], @groupSubscription.planCode + done() + it "should call updateFeatures with default if there are no subscriptions for user", (done)-> @SubscriptionLocator.getUsersSubscription.callsArgWith(1, null)