Merge pull request #25372 from overleaf/kh-support-canceling-pending-stripe-change

[web] cancel pending Stripe subscription change

GitOrigin-RevId: c1d21a7d1c3962c20d589b1dd10f6c2a4c8e4be4
This commit is contained in:
M Fahru
2025-05-08 09:28:05 -07:00
committed by Copybot
parent 391fca9e83
commit c50bd6af89
2 changed files with 45 additions and 2 deletions
@@ -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
)
}
}
@@ -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 () {