From fae7d431f480774d311a3c3908ab7a134f388923 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 5 Oct 2015 16:33:13 +0100 Subject: [PATCH] after subscription is updated always check bonus --- .../Features/Subscription/SubscriptionUpdater.coffee | 4 +++- .../Subscription/SubscriptionUpdaterTests.coffee | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee index 403a58b67b..7440657c7c 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee @@ -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 diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee index 592098e9be..3fab075c30 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionUpdaterTests.coffee @@ -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, =>