Skip to content

Commit d7146ac

Browse files
fix: Start upgrade form seat count at paid number
1 parent 42c80f6 commit d7146ac

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/shared/utils/upgradeForm.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ describe('getDefaultValuesUpgradeForm', () => {
166166
})
167167
})
168168

169+
it('returns correct seats when free seats are present', () => {
170+
const data = getDefaultValuesUpgradeForm({
171+
accountDetails,
172+
selectedPlan: proPlanYear,
173+
plans: [teamPlanMonth],
174+
plan: {
175+
billingRate: BillingRate.MONTHLY,
176+
value: Plans.USERS_TEAMM,
177+
planUserCount: 5,
178+
freeSeatCount: 2,
179+
isTeamPlan: true,
180+
} as Plan,
181+
})
182+
183+
expect(data).toStrictEqual({
184+
newPlan: { value: Plans.USERS_TEAMM },
185+
seats: 3,
186+
})
187+
})
188+
169189
it('returns pro sentry plan if user is sentry upgrade', () => {
170190
const data = getDefaultValuesUpgradeForm({
171191
accountDetails,
@@ -214,6 +234,56 @@ describe('getDefaultValuesUpgradeForm', () => {
214234
seats: 2,
215235
})
216236
})
237+
238+
describe('quantity calculation edge cases', () => {
239+
it('returns 0 when planUserCount is null', () => {
240+
const data = getDefaultValuesUpgradeForm({
241+
accountDetails,
242+
selectedPlan: proPlanYear,
243+
plans: [proPlanYear],
244+
plan: {
245+
billingRate: BillingRate.MONTHLY,
246+
value: Plans.USERS_PR_INAPPM,
247+
planUserCount: null,
248+
} as unknown as Plan,
249+
})
250+
251+
expect(data).toStrictEqual({
252+
newPlan: {
253+
value: Plans.USERS_PR_INAPPM,
254+
billingRate: BillingRate.MONTHLY,
255+
planUserCount: null,
256+
},
257+
// extractSeats() will be passed quantity: 0, but returns min plan seats
258+
seats: 2,
259+
})
260+
})
261+
262+
it('handles case where freeSeatCount equals planUserCount', () => {
263+
const data = getDefaultValuesUpgradeForm({
264+
accountDetails,
265+
selectedPlan: proPlanYear,
266+
plans: [proPlanYear],
267+
plan: {
268+
billingRate: BillingRate.MONTHLY,
269+
value: Plans.USERS_PR_INAPPM,
270+
planUserCount: 3,
271+
freeSeatCount: 3,
272+
} as Plan,
273+
})
274+
275+
expect(data).toStrictEqual({
276+
newPlan: {
277+
value: Plans.USERS_PR_INAPPM,
278+
billingRate: BillingRate.MONTHLY,
279+
planUserCount: 3,
280+
freeSeatCount: 3,
281+
},
282+
// extractSeats() will be passed quantity: 0, but returns min plan seats
283+
seats: 2,
284+
})
285+
})
286+
})
217287
})
218288

219289
describe('getSchema', () => {

src/shared/utils/upgradeForm.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ export const getDefaultValuesUpgradeForm = ({
235235
}
236236

237237
const seats = extractSeats({
238-
quantity: plan?.planUserCount ?? 0,
238+
// free seats are included in planUserCount but we want to use the paid number
239+
quantity: plan?.planUserCount
240+
? plan?.planUserCount - (plan?.freeSeatCount ?? 0)
241+
: 0,
239242
activatedUserCount,
240243
inactiveUserCount,
241244
trialStatus,

0 commit comments

Comments
 (0)