if subscription is downgraded don't use plan code on subscription, use default instead

This commit is contained in:
Henry Oswald 2016-03-31 18:04:20 +01:00
parent 81cd2adfd3
commit 3d719af71e
2 changed files with 11 additions and 3 deletions

View file

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

View file

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