mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 23:37:19 +00:00
after subscription is updated always check bonus
This commit is contained in:
parent
9a60617162
commit
fae7d431f4
2 changed files with 12 additions and 3 deletions
|
@ -7,6 +7,7 @@ PlansLocator = require("./PlansLocator")
|
|||
Settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
ObjectId = require('mongoose').Types.ObjectId
|
||||
ReferalAllocator = require("../Referal/ReferalAllocator")
|
||||
|
||||
oneMonthInSeconds = 60 * 60 * 24 * 30
|
||||
|
||||
|
@ -69,6 +70,7 @@ module.exports =
|
|||
jobs = allIds.map (user_id)->
|
||||
return (cb)->
|
||||
UserFeaturesUpdater.updateFeatures user_id, subscription.planCode, cb
|
||||
async.parallel jobs, callback
|
||||
jobs.push (cb)-> ReferalAllocator.assignBonus subscription.admin_id, cb
|
||||
async.series jobs, callback
|
||||
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ describe "Subscription Updater", ->
|
|||
@PlansLocator =
|
||||
findLocalPlanInSettings: sinon.stub().returns({})
|
||||
|
||||
|
||||
@ReferalAllocator = assignBonus:sinon.stub().callsArgWith(1)
|
||||
@ReferalAllocator.cock = true
|
||||
@SubscriptionUpdater = SandboxedModule.require modulePath, requires:
|
||||
'../../models/Subscription': Subscription:@SubscriptionModel
|
||||
'./UserFeaturesUpdater': @UserFeaturesUpdater
|
||||
|
@ -53,13 +54,14 @@ describe "Subscription Updater", ->
|
|||
'./PlansLocator': @PlansLocator
|
||||
"logger-sharelatex": log:->
|
||||
'settings-sharelatex': @Settings
|
||||
"../Referal/ReferalAllocator" : @ReferalAllocator
|
||||
|
||||
|
||||
describe "syncSubscription", ->
|
||||
it "should update the subscription if the user already is admin of one", (done)->
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, @subscription)
|
||||
@SubscriptionUpdater._updateSubscription = sinon.stub().callsArgWith(2)
|
||||
@SubscriptionUpdater._createNewSubscription = sinon.stub()
|
||||
|
||||
@SubscriptionUpdater.syncSubscription @recurlySubscription, @adminUser._id, (err)=>
|
||||
@SubscriptionLocator.getUsersSubscription.calledWith(@adminUser._id).should.equal true
|
||||
@SubscriptionUpdater._updateSubscription.called.should.equal true
|
||||
|
@ -111,6 +113,11 @@ describe "Subscription Updater", ->
|
|||
assert.notEqual @subscription.groupPlan, true
|
||||
done()
|
||||
|
||||
it "should call assignBonus", (done)->
|
||||
@SubscriptionUpdater._updateSubscription @recurlySubscription, @subscription, (err)=>
|
||||
@ReferalAllocator.assignBonus.calledWith(@subscription.admin_id).should.equal true
|
||||
done()
|
||||
|
||||
describe "_createNewSubscription", ->
|
||||
it "should create a new subscription then update the subscription", (done)->
|
||||
@SubscriptionUpdater._createNewSubscription @adminUser._id, =>
|
||||
|
|
Loading…
Reference in a new issue