From cb449f4b75fcaa66ddffa918c359c193a71e50aa Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 10 Jul 2018 10:31:25 +0100 Subject: [PATCH] Delete a subscription on expiry, rather than set personal plan code --- .../Subscription/LimitationsManager.coffee | 2 +- .../Subscription/SubscriptionUpdater.coffee | 18 +++++++++--------- .../SubscriptionUpdaterTests.coffee | 8 +++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee b/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee index a23372903b..5f5de9f549 100644 --- a/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee +++ b/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee @@ -19,7 +19,7 @@ module.exports = LimitationsManager = if user.features? and user.features.collaborators? callback null, user.features.collaborators else - callback null, Settings.defaultPlanCode.collaborators + callback null, Settings.defaultFeatures.collaborators canAddXCollaborators: (project_id, x_collaborators, callback = (error, allowed)->) -> @allowedNumberOfCollaboratorsInProject project_id, (error, allowed_number) => diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee index 7867db29b9..b5fce978a4 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee @@ -78,16 +78,16 @@ module.exports = SubscriptionUpdater = _updateSubscriptionFromRecurly: (recurlySubscription, subscription, callback)-> logger.log recurlySubscription:recurlySubscription, subscription:subscription, "updaing subscription" - plan = PlansLocator.findLocalPlanInSettings(recurlySubscription.plan.plan_code) if recurlySubscription.state == "expired" - subscription.recurlySubscription_id = undefined - subscription.planCode = Settings.defaultPlanCode - else - subscription.recurlySubscription_id = recurlySubscription.uuid - subscription.freeTrial.expiresAt = undefined - subscription.freeTrial.planCode = undefined - subscription.freeTrial.allowed = true - subscription.planCode = recurlySubscription.plan.plan_code + return SubscriptionUpdater.deleteSubscription subscription._id, callback + subscription.recurlySubscription_id = recurlySubscription.uuid + subscription.freeTrial.expiresAt = undefined + subscription.freeTrial.planCode = undefined + subscription.freeTrial.allowed = true + subscription.planCode = recurlySubscription.plan.plan_code + plan = PlansLocator.findLocalPlanInSettings(subscription.planCode) + if !plan? + return callback(new Error("plan code not found: #{subscription.planCode}")) if plan.groupPlan subscription.groupPlan = true subscription.membersLimit = plan.membersLimit diff --git a/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee b/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee index f97ba98ad4..376d526db0 100644 --- a/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee +++ b/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee @@ -103,6 +103,7 @@ describe "SubscriptionUpdater", -> describe "_updateSubscriptionFromRecurly", -> beforeEach -> @FeaturesUpdater.refreshFeatures = sinon.stub().callsArgWith(1) + @SubscriptionUpdater.deleteSubscription = sinon.stub().yields() it "should update the subscription with token etc when not expired", (done)-> @SubscriptionUpdater._updateSubscriptionFromRecurly @recurlySubscription, @subscription, (err)=> @@ -116,13 +117,10 @@ describe "SubscriptionUpdater", -> @FeaturesUpdater.refreshFeatures.calledWith(@adminUser._id).should.equal true done() - it "should remove the recurlySubscription_id when expired", (done)-> + it "should remove the subscription when expired", (done)-> @recurlySubscription.state = "expired" - @SubscriptionUpdater._updateSubscriptionFromRecurly @recurlySubscription, @subscription, (err)=> - assert.equal(@subscription.recurlySubscription_id, undefined) - @subscription.save.called.should.equal true - @FeaturesUpdater.refreshFeatures.calledWith(@adminUser._id).should.equal true + @SubscriptionUpdater.deleteSubscription.calledWith(@subscription._id).should.equal true done() it "should update all the users features", (done)->