mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Don't consider current features when assignin bonus
This commit is contained in:
parent
3a8b5d23d8
commit
156c417df0
2 changed files with 18 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue