Don't consider current features when assignin bonus

This commit is contained in:
James Allen 2018-06-26 11:26:07 +01:00
parent 3a8b5d23d8
commit 156c417df0
2 changed files with 18 additions and 15 deletions

View file

@ -18,21 +18,7 @@ module.exports = ReferalFeatures =
_calculateFeatures : (user)->
bonusLevel = ReferalFeatures._getBonusLevel(user)
currentFeatures = _.clone(user.features) #need to clone because we exend with underscore later
betterBonusFeatures = {}
_.each Settings.bonus_features["#{bonusLevel}"], (bonusLevel, key)->
currentLevel = user?.features?[key]
if _.isBoolean(currentLevel) and currentLevel == false
betterBonusFeatures[key] = bonusLevel
if _.isNumber(currentLevel)
if currentLevel == -1
return
bonusIsGreaterThanCurrent = currentLevel < bonusLevel
if bonusIsGreaterThanCurrent or bonusLevel == -1
betterBonusFeatures[key] = bonusLevel
newFeatures = _.extend(currentFeatures, betterBonusFeatures)
return newFeatures
return Settings.bonus_features?["#{bonusLevel}"] or Settings.defaultFeatures
_getBonusLevel: (user)->
highestBonusLevel = 0

View file

@ -83,6 +83,23 @@ describe "FeatureUpdater.refreshFeatures", ->
))
done()
describe "when the user is due bonus features and has extra features that no longer apply", ->
beforeEach ->
User.update {
_id: @user._id
}, {
refered_user_count: 10,
'features.github': true
} # returns a promise
it "should set their features to the bonus set and downgrade the extras", (done) ->
syncUserAndGetFeatures @user, (error, features) =>
throw error if error?
expect(features).to.deep.equal(Object.assign(
{}, settings.defaultFeatures, settings.bonus_features[9]
))
done()
describe "when the user has a v1 plan", ->
beforeEach ->
MockV1Api.setUser 42, plan_name: 'free'