Implement checks for user eligibility when switching plans (#24276)

* Convert updateSubscription controller to async/await

* Move updateSubscription to subscription module

* Validate if user is eligible to change plan

GitOrigin-RevId: ce538429cd5a3b93acabdc046f1a8b164ac02301
This commit is contained in:
Thomas Mees
2025-03-14 09:05:19 +00:00
committed by Copybot
parent e6371ec197
commit 84996ea88c
6 changed files with 36 additions and 63 deletions
@@ -175,9 +175,9 @@ describe('SubscriptionController', function () {
recordEventForSession: sinon.stub(),
setUserPropertyForUser: sinon.stub(),
}),
'../../infrastructure/Modules': {
'../../infrastructure/Modules': (this.Modules = {
promises: { hooks: { fire: sinon.stub().resolves() } },
},
}),
'../../infrastructure/Features': this.Features,
'../../util/currency': (this.currency = {
formatCurrency: sinon.stub(),
@@ -293,32 +293,6 @@ describe('SubscriptionController', function () {
})
})
describe('updateSubscription via post', function () {
beforeEach(function (done) {
this.res = {
redirect() {
done()
},
}
sinon.spy(this.res, 'redirect')
this.plan_code = '1234'
this.req.body.plan_code = this.plan_code
this.SubscriptionController.updateSubscription(this.req, this.res)
})
it('should send the user and subscriptionId to the handler', function (done) {
this.SubscriptionHandler.updateSubscription
.calledWith(this.user, this.plan_code)
.should.equal(true)
done()
})
it('should redurect to the subscription page', function (done) {
this.res.redirect.calledWith('/user/subscription').should.equal(true)
done()
})
})
describe('updateAccountEmailAddress via put', function () {
it('should send the user and subscriptionId to RecurlyWrapper', function () {
this.res.sendStatus = sinon.spy()