Delete a subscription on expiry, rather than set personal plan code

This commit is contained in:
James Allen 2018-07-10 10:31:25 +01:00
parent 158cb58e29
commit cb449f4b75
3 changed files with 13 additions and 15 deletions

View file

@ -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) =>

View file

@ -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

View file

@ -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)->