From 44c289d8dd28f5b1d7756524968cf413c71ddd1b Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 4 Dec 2017 15:34:46 +0000 Subject: [PATCH] Fix unit tests for SubscriptionUpdater --- .../Subscription/SubscriptionUpdaterTests.coffee | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee b/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee index 87ff474a0a..3f25465ae0 100644 --- a/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee +++ b/services/web/test/unit/coffee/Subscription/SubscriptionUpdaterTests.coffee @@ -57,6 +57,7 @@ describe "SubscriptionUpdater", -> @ReferalAllocator = assignBonus:sinon.stub().callsArgWith(1) @ReferalAllocator.cock = true + @Modules = {hooks: {fire: sinon.stub().callsArgWith(2, null, null)}} @SubscriptionUpdater = SandboxedModule.require modulePath, requires: '../../models/Subscription': Subscription:@SubscriptionModel './UserFeaturesUpdater': @UserFeaturesUpdater @@ -65,6 +66,7 @@ describe "SubscriptionUpdater", -> "logger-sharelatex": log:-> 'settings-sharelatex': @Settings "../Referal/ReferalAllocator" : @ReferalAllocator + '../../infrastructure/Modules': @Modules describe "syncSubscription", -> @@ -204,10 +206,22 @@ describe "SubscriptionUpdater", -> assert.equal args[1], @groupSubscription.planCode done() + it "should call updateFeatures with the overleaf subscription if set", (done)-> + @SubscriptionLocator.getUsersSubscription.callsArgWith(1, null) + @SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null, null) + @Modules.hooks.fire = sinon.stub().callsArgWith(2, null, 'ol_pro') + + @SubscriptionUpdater._setUsersMinimumFeatures @adminUser._id, (err)=> + args = @UserFeaturesUpdater.updateFeatures.args[0] + assert.equal args[0], @adminUser._id + assert.equal args[1], 'ol_pro' + 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) + @Modules.hooks.fire = sinon.stub().callsArgWith(2, null, null) @SubscriptionUpdater._setUsersMinimumFeatures @adminuser_id, (err)=> args = @UserFeaturesUpdater.updateFeatures.args[0] assert.equal args[0], @adminUser._id @@ -218,6 +232,7 @@ describe "SubscriptionUpdater", -> it "should call updateFeatures with default if there are no subscriptions for user", (done)-> @SubscriptionLocator.getUsersSubscription.callsArgWith(1, null) @SubscriptionLocator.getGroupSubscriptionMemberOf.callsArgWith(1, null) + @Modules.hooks.fire = sinon.stub().callsArgWith(2, null, null) @SubscriptionUpdater._setUsersMinimumFeatures @adminuser_id, (err)=> args = @UserFeaturesUpdater.updateFeatures.args[0] assert.equal args[0], @adminUser._id