Merge pull request #23547 from overleaf/ii-flexible-group-licensing-error-assist-2

[web] Hide flexible licensing buttons for pending plans (fix)

GitOrigin-RevId: ce5b4ce4138ed7a029b840a87c5498227e3204f4
This commit is contained in:
ilkin-overleaf
2025-02-13 09:04:57 +00:00
committed by Copybot
parent 9f438f0805
commit bebc32b11d
9 changed files with 85 additions and 12 deletions
@@ -58,6 +58,7 @@ describe('SubscriptionGroupController', function () {
ensureFlexibleLicensingEnabled: sinon.stub().resolves(),
ensureSubscriptionIsActive: sinon.stub().resolves(),
ensureSubscriptionCollectionMethodIsNotManual: sinon.stub().resolves(),
ensureSubscriptionHasNoPendingChanges: sinon.stub().resolves(),
getGroupPlanUpgradePreview: sinon
.stub()
.resolves(this.previewSubscriptionChangeData),
@@ -125,6 +126,7 @@ describe('SubscriptionGroupController', function () {
this.Errors = {
MissingBillingInfoError: class MissingBillingInfoError extends Error {},
ManuallyCollectedError: class ManuallyCollectedError extends Error {},
PendingChangeError: class PendingChangeError extends Error {},
}
this.Controller = await esmock.strict(modulePath, {
@@ -427,6 +429,20 @@ describe('SubscriptionGroupController', function () {
this.Controller.addSeatsToGroupSubscription(this.req, res)
})
it('should redirect to subscription page when there is a pending change', function (done) {
this.SubscriptionGroupHandler.promises.ensureSubscriptionHasNoPendingChanges =
sinon.stub().throws(new this.Errors.PendingChangeError())
const res = {
redirect: url => {
url.should.equal('/user/subscription')
done()
},
}
this.Controller.addSeatsToGroupSubscription(this.req, res)
})
it('should redirect to subscription page when subscription is not active', function (done) {
this.SubscriptionGroupHandler.promises.ensureSubscriptionIsActive = sinon
.stub()
@@ -629,6 +629,22 @@ describe('SubscriptionGroupHandler', function () {
})
})
describe('ensureSubscriptionHasNoPendingChanges', function () {
it('should throw if the subscription has pending change', async function () {
await expect(
this.Handler.promises.ensureSubscriptionHasNoPendingChanges({
pendingChange: {},
})
).to.be.rejectedWith('This subscription has a pending change')
})
it('should not throw if the subscription has no pending change', async function () {
await expect(
this.Handler.promises.ensureSubscriptionHasNoPendingChanges({})
).to.not.be.rejected
})
})
describe('upgradeGroupPlan', function () {
it('should upgrade the subscription for flexible licensing group plans', async function () {
this.SubscriptionLocator.promises.getUsersSubscription = sinon
@@ -81,6 +81,11 @@ describe('UserMembershipController', function () {
},
getAssignment: sinon.stub().yields(null, { variant: 'default' }),
}
this.RecurlyClient = {
promises: {
getSubscription: sinon.stub().resolves({}),
},
}
this.UserMembershipController = await esmock.strict(modulePath, {
'../../../../app/src/Features/UserMembership/UserMembershipErrors': {
UserIsManagerError,
@@ -93,6 +98,8 @@ describe('UserMembershipController', function () {
this.SplitTestHandler,
'../../../../app/src/Features/UserMembership/UserMembershipHandler':
this.UserMembershipHandler,
'../../../../app/src/Features/Subscription/RecurlyClient':
this.RecurlyClient,
'@overleaf/settings': this.Settings,
'../../../../app/src/models/SSOConfig': { SSOConfig: this.SSOConfig },
})