diff --git a/services/web/app/src/Features/Subscription/SubscriptionHandler.js b/services/web/app/src/Features/Subscription/SubscriptionHandler.js index 5d328c9c59..ecf05695da 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHandler.js +++ b/services/web/app/src/Features/Subscription/SubscriptionHandler.js @@ -123,8 +123,9 @@ async function cancelPendingSubscriptionChange(user) { await LimitationsManager.promises.userHasSubscription(user) if (hasSubscription && subscription != null) { - await RecurlyClient.promises.removeSubscriptionChangeByUuid( - subscription.recurlySubscription_id + await Modules.promises.hooks.fire( + 'cancelPendingPaidSubscriptionChange', + subscription ) } } diff --git a/services/web/test/unit/src/Subscription/SubscriptionHandlerTests.js b/services/web/test/unit/src/Subscription/SubscriptionHandlerTests.js index 7814cc560d..ed5ed2f6d1 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionHandlerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionHandlerTests.js @@ -319,6 +319,48 @@ describe('SubscriptionHandler', function () { }) }) + describe('cancelPendingSubscriptionChange', function () { + beforeEach(function () { + this.user.id = this.activeRecurlySubscription.account.account_code + this.User.findById = (userId, projection) => ({ + exec: () => { + userId.should.equal(this.user.id) + return Promise.resolve(this.user) + }, + }) + }) + + it('should not fire cancelPendingPaidSubscriptionChange hook if user has no subscription', async function () { + this.LimitationsManager.promises.userHasSubscription.resolves({ + hasSubscription: false, + subscription: null, + }) + await this.SubscriptionHandler.promises.cancelPendingSubscriptionChange( + this.user, + this.plan_code + ) + expect(this.Modules.promises.hooks.fire).to.not.have.been.calledWith( + 'cancelPendingPaidSubscriptionChange', + sinon.match.any + ) + }) + + it('should fire cancelPendingPaidSubscriptionChange to update a valid subscription', async function () { + this.LimitationsManager.promises.userHasSubscription.resolves({ + hasSubscription: true, + subscription: this.subscription, + }) + await this.SubscriptionHandler.promises.cancelPendingSubscriptionChange( + this.user, + this.plan_code + ) + expect(this.Modules.promises.hooks.fire).to.have.been.calledWith( + 'cancelPendingPaidSubscriptionChange', + this.subscription + ) + }) + }) + describe('cancelSubscription', function () { describe('with a user without a subscription', function () { beforeEach(async function () {