Skip to content

Commit 627395d

Browse files
fix: Fix upgradeForm tests and cleanup
1 parent ada5ac8 commit 627395d

File tree

4 files changed

+53
-184
lines changed

4 files changed

+53
-184
lines changed

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/UpdateBlurb/UpdateBlurb.test.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,6 @@ describe('UpdateBlurb', () => {
142142
})
143143
})
144144

145-
// describe('when user has yearly -> monthly plan', () => {
146-
// it('renders immediate update blurb', async () => {
147-
// render(
148-
// <UpdateBlurb
149-
// newPlan={teamPlanYear}
150-
// currentPlan={{ ...teamPlanMonth, ...planChunk, planUserCount: 10 }}
151-
// nextBillingDate={'July 12th, 2024'}
152-
// seats={10}
153-
// />,
154-
// {
155-
// wrapper: wrapper(),
156-
// }
157-
// )
158-
159-
// const billingBlurb = await screen.findByText(
160-
// 'You are changing your billing cycle from Annual to [Monthly]'
161-
// )
162-
// const immediateUpdate = await screen.findByText(
163-
// /Your changes will take effect at the beginning of your next billing cycle on [July 12th, 2024]./
164-
// )
165-
// expect(billingBlurb).toBeInTheDocument()
166-
// expect(immediateUpdate).toBeInTheDocument()
167-
// })
168-
// })
169-
170145
describe('when user has increase in seats', () => {
171146
it('renders immediate update blurb', async () => {
172147
render(
@@ -219,7 +194,7 @@ describe('UpdateBlurb', () => {
219194
})
220195
describe('downgrades', () => {
221196
describe('when user change from annual to monthly', () => {
222-
it.only('renders next billing cycle blurb', async () => {
197+
it('renders next billing cycle blurb', async () => {
223198
render(
224199
<UpdateBlurb
225200
currentPlan={{ ...teamPlanYear, ...planChunk, planUserCount: 10 }}

src/pages/PlanPage/subRoutes/UpgradePlanPage/UpgradeForm/UpgradeForm.test.tsx

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,44 +1113,6 @@ describe('UpgradeForm', () => {
11131113
})
11141114
)
11151115
})
1116-
1117-
// it('renders success notification when upgrading seats with yearly plan', async () => {
1118-
// const { patchRequest, user } = setup({
1119-
// successfulPatchRequest: true,
1120-
// planValue: Plans.USERS_PR_INAPPM,
1121-
// })
1122-
// render(<UpgradeForm {...props} />, { wrapper: wrapper() })
1123-
1124-
// const input = await screen.findByRole('spinbutton')
1125-
// await user.type(input, '{backspace}{backspace}{backspace}')
1126-
// await user.type(input, '20')
1127-
1128-
// const optionBtn = await screen.findByTestId('radio-annual')
1129-
// await user.click(optionBtn)
1130-
1131-
// const update = await screen.findByRole('button', {
1132-
// name: /Update/,
1133-
// })
1134-
// await user.click(update)
1135-
1136-
// const confirmCheckoutCheckbox = await screen.findByTestId(
1137-
// 'upgrade-confirmation-checkbox'
1138-
// )
1139-
// await user.click(confirmCheckoutCheckbox)
1140-
1141-
// const confirmCheckoutButton =
1142-
// await screen.findByTestId('submit-upgrade')
1143-
// await user.click(confirmCheckoutButton)
1144-
1145-
// await waitFor(() =>
1146-
// expect(patchRequest).toHaveBeenCalledWith({
1147-
// plan: {
1148-
// quantity: 20,
1149-
// value: Plans.USERS_PR_INAPPY,
1150-
// },
1151-
// })
1152-
// )
1153-
// })
11541116
})
11551117

11561118
describe('when the mutation is unsuccessful', () => {
@@ -1773,43 +1735,6 @@ describe('UpgradeForm', () => {
17731735
})
17741736

17751737
describe('when the mutation is successful', () => {
1776-
// it('renders success notification when upgrading seats with an annual plan', async () => {
1777-
// const { patchRequest, user } = setup({
1778-
// successfulPatchRequest: true,
1779-
// hasSentryPlans: true,
1780-
// planValue: Plans.USERS_SENTRYY,
1781-
// monthlyPlan: false,
1782-
// })
1783-
// render(<UpgradeForm {...props} />, { wrapper: wrapper() })
1784-
1785-
// const input = await screen.findByRole('spinbutton')
1786-
// await user.type(input, '{backspace}{backspace}{backspace}')
1787-
// await user.type(input, '8')
1788-
1789-
// const update = await screen.findByRole('button', {
1790-
// name: /Update/,
1791-
// })
1792-
// await user.click(update)
1793-
1794-
// const confirmCheckoutCheckbox = await screen.findByTestId(
1795-
// 'upgrade-confirmation-checkbox'
1796-
// )
1797-
// await user.click(confirmCheckoutCheckbox)
1798-
1799-
// const confirmCheckoutButton =
1800-
// await screen.findByTestId('submit-upgrade')
1801-
// await user.click(confirmCheckoutButton)
1802-
1803-
// await waitFor(() =>
1804-
// expect(patchRequest).toHaveBeenCalledWith({
1805-
// plan: {
1806-
// quantity: 8,
1807-
// value: Plans.USERS_SENTRYY,
1808-
// },
1809-
// })
1810-
// )
1811-
// })
1812-
18131738
it('renders success notification when upgrading seats with a monthly plan', async () => {
18141739
const { patchRequest, user } = setup({
18151740
successfulPatchRequest: true,
@@ -2151,46 +2076,6 @@ describe('UpgradeForm', () => {
21512076
})
21522077

21532078
describe('when the mutation is successful', () => {
2154-
// it('renders success notification when upgrading seats with an annual plan', async () => {
2155-
// const { patchRequest, user } = setup({
2156-
// successfulPatchRequest: true,
2157-
// hasTeamPlans: true,
2158-
// planValue: Plans.USERS_TEAMY,
2159-
// monthlyPlan: false,
2160-
// })
2161-
// render(<UpgradeForm {...props} />, { wrapper: wrapper() })
2162-
2163-
// const input = await screen.findByRole('spinbutton')
2164-
// await user.type(input, '{backspace}{backspace}{backspace}')
2165-
// await user.type(input, '8')
2166-
2167-
// const teamOption = await screen.findByTestId('radio-team')
2168-
// await user.click(teamOption)
2169-
2170-
// const update = await screen.findByRole('button', {
2171-
// name: /Update/,
2172-
// })
2173-
// await user.click(update)
2174-
2175-
// const confirmCheckoutCheckbox = await screen.findByTestId(
2176-
// 'upgrade-confirmation-checkbox'
2177-
// )
2178-
// await user.click(confirmCheckoutCheckbox)
2179-
2180-
// const confirmCheckoutButton =
2181-
// await screen.findByTestId('submit-upgrade')
2182-
// await user.click(confirmCheckoutButton)
2183-
2184-
// await waitFor(() =>
2185-
// expect(patchRequest).toHaveBeenCalledWith({
2186-
// plan: {
2187-
// quantity: 8,
2188-
// value: Plans.USERS_TEAMY,
2189-
// },
2190-
// })
2191-
// )
2192-
// })
2193-
21942079
it('renders success notification when upgrading seats with a monthly plan', async () => {
21952080
const { patchRequest, user } = setup({
21962081
successfulPatchRequest: true,

src/shared/utils/upgradeForm.test.ts

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,34 @@ describe('calculatePriceTeamPlan', () => {
100100

101101
describe('getDefaultValuesUpgradeForm', () => {
102102
const accountDetails = {} as z.infer<typeof AccountDetailsSchema>
103-
const proPlanYear = { value: Plans.USERS_PR_INAPPY } as Plan
104-
const sentryPlanYear = { value: Plans.USERS_SENTRYY } as Plan
103+
const proPlanMonth = { value: Plans.USERS_PR_INAPPM } as Plan
104+
const sentryPlanMonth = { value: Plans.USERS_SENTRYM } as Plan
105105
const teamPlanMonth = { value: Plans.USERS_TEAMM } as Plan
106106

107107
describe('when current plan is basic', () => {
108-
it('returns pro year plan', () => {
108+
it('returns pro month plan', () => {
109109
const data = getDefaultValuesUpgradeForm({
110110
accountDetails,
111-
selectedPlan: proPlanYear,
112-
plans: [proPlanYear],
111+
selectedPlan: proPlanMonth,
112+
plans: [proPlanMonth],
113113
plan: {
114-
billingRate: BillingRate.ANNUALLY,
115-
value: Plans.USERS_PR_INAPPY,
114+
billingRate: BillingRate.MONTHLY,
115+
value: Plans.USERS_PR_INAPPM,
116116
planUserCount: 1,
117117
} as Plan,
118118
})
119119

120120
expect(data).toStrictEqual({
121-
newPlan: {
122-
billingRate: BillingRate.ANNUALLY,
123-
value: Plans.USERS_PR_INAPPY,
124-
planUserCount: 1,
125-
},
121+
newPlan: proPlanMonth,
126122
seats: 2,
127123
})
128124
})
129125

130-
it('returns sentry year plan if user is sentry upgrade', () => {
126+
it('returns sentry month plan if user is sentry upgrade', () => {
131127
const data = getDefaultValuesUpgradeForm({
132128
accountDetails,
133-
selectedPlan: proPlanYear,
134-
plans: [proPlanYear, sentryPlanYear],
129+
selectedPlan: proPlanMonth,
130+
plans: [proPlanMonth, sentryPlanMonth],
135131
plan: {
136132
billingRate: BillingRate.ANNUALLY,
137133
value: Plans.USERS_PR_INAPPY,
@@ -140,7 +136,7 @@ describe('getDefaultValuesUpgradeForm', () => {
140136
})
141137

142138
expect(data).toStrictEqual({
143-
newPlan: { value: Plans.USERS_SENTRYY },
139+
newPlan: { value: Plans.USERS_SENTRYM },
144140
seats: 5,
145141
})
146142
})
@@ -150,7 +146,7 @@ describe('getDefaultValuesUpgradeForm', () => {
150146
it('returns team monthly plan', () => {
151147
const data = getDefaultValuesUpgradeForm({
152148
accountDetails,
153-
selectedPlan: proPlanYear,
149+
selectedPlan: proPlanMonth,
154150
plans: [teamPlanMonth],
155151
plan: {
156152
billingRate: BillingRate.MONTHLY,
@@ -169,7 +165,7 @@ describe('getDefaultValuesUpgradeForm', () => {
169165
it('returns correct seats when free seats are present', () => {
170166
const data = getDefaultValuesUpgradeForm({
171167
accountDetails,
172-
selectedPlan: proPlanYear,
168+
selectedPlan: proPlanMonth,
173169
plans: [teamPlanMonth],
174170
plan: {
175171
billingRate: BillingRate.MONTHLY,
@@ -186,11 +182,11 @@ describe('getDefaultValuesUpgradeForm', () => {
186182
})
187183
})
188184

189-
it('returns pro sentry plan if user is sentry upgrade', () => {
185+
it('returns sentry month plan if user is sentry upgrade', () => {
190186
const data = getDefaultValuesUpgradeForm({
191187
accountDetails,
192-
selectedPlan: proPlanYear,
193-
plans: [proPlanYear, sentryPlanYear],
188+
selectedPlan: proPlanMonth,
189+
plans: [proPlanMonth, sentryPlanMonth],
194190
plan: {
195191
billingRate: BillingRate.MONTHLY,
196192
value: Plans.USERS_SENTRYY,
@@ -201,23 +197,37 @@ describe('getDefaultValuesUpgradeForm', () => {
201197
})
202198

203199
expect(data).toStrictEqual({
204-
newPlan: {
200+
newPlan: sentryPlanMonth,
201+
seats: 5,
202+
})
203+
})
204+
205+
it('returns sentry month plan if user is already on sentry plan', () => {
206+
const data = getDefaultValuesUpgradeForm({
207+
accountDetails,
208+
selectedPlan: proPlanMonth,
209+
plans: [proPlanMonth, sentryPlanMonth],
210+
plan: {
205211
billingRate: BillingRate.MONTHLY,
206212
value: Plans.USERS_SENTRYY,
207213
planUserCount: 1,
208214
isTeamPlan: false,
209215
isSentryPlan: true,
210-
},
216+
} as Plan,
217+
})
218+
219+
expect(data).toStrictEqual({
220+
newPlan: sentryPlanMonth,
211221
seats: 5,
212222
})
213223
})
214224
})
215225

216-
it('returns current plan if the user is on a paid plan', () => {
226+
it('returns pro month plan if the user is on a paid plan', () => {
217227
const data = getDefaultValuesUpgradeForm({
218228
accountDetails,
219-
selectedPlan: proPlanYear,
220-
plans: [proPlanYear],
229+
selectedPlan: proPlanMonth,
230+
plans: [proPlanMonth],
221231
plan: {
222232
billingRate: BillingRate.MONTHLY,
223233
value: Plans.USERS_PR_INAPPM,
@@ -226,11 +236,7 @@ describe('getDefaultValuesUpgradeForm', () => {
226236
})
227237

228238
expect(data).toStrictEqual({
229-
newPlan: {
230-
value: Plans.USERS_PR_INAPPM,
231-
billingRate: BillingRate.MONTHLY,
232-
planUserCount: 2,
233-
},
239+
newPlan: proPlanMonth,
234240
seats: 2,
235241
})
236242
})
@@ -239,8 +245,8 @@ describe('getDefaultValuesUpgradeForm', () => {
239245
it('handles case where freeSeatCount equals planUserCount', () => {
240246
const data = getDefaultValuesUpgradeForm({
241247
accountDetails,
242-
selectedPlan: proPlanYear,
243-
plans: [proPlanYear],
248+
selectedPlan: proPlanMonth,
249+
plans: [proPlanMonth],
244250
plan: {
245251
billingRate: BillingRate.MONTHLY,
246252
value: Plans.USERS_PR_INAPPM,
@@ -250,12 +256,7 @@ describe('getDefaultValuesUpgradeForm', () => {
250256
})
251257

252258
expect(data).toStrictEqual({
253-
newPlan: {
254-
value: Plans.USERS_PR_INAPPM,
255-
billingRate: BillingRate.MONTHLY,
256-
planUserCount: 3,
257-
freeSeatCount: 3,
258-
},
259+
newPlan: proPlanMonth,
259260
// extractSeats() will be passed quantity: 0, but returns min plan seats
260261
seats: 2,
261262
})
@@ -615,17 +616,19 @@ describe('shouldRenderCancelLink', () => {
615616
})
616617

617618
describe('user intended plan is Team', () => {
618-
it('sets new plan to team', () => {
619+
it('sets new plan to team monthly', () => {
619620
const accountDetails = {} as z.infer<typeof AccountDetailsSchema>
621+
const teamPlanMonth = { value: Plans.USERS_TEAMM } as Plan
620622
const plans = [
623+
teamPlanMonth,
621624
{ value: Plans.USERS_TEAMY } as Plan,
622625
{ value: Plans.USERS_PR_INAPPY } as Plan,
623626
]
624627

625628
const data = getDefaultValuesUpgradeForm({
626629
accountDetails,
627630
plans,
628-
selectedPlan: { value: Plans.USERS_TEAMY } as Plan,
631+
selectedPlan: { value: Plans.USERS_TEAMY, isTeamPlan: true } as Plan,
629632
plan: {
630633
billingRate: BillingRate.ANNUALLY,
631634
value: Plans.USERS_TEAMY,
@@ -636,7 +639,7 @@ describe('shouldRenderCancelLink', () => {
636639
})
637640

638641
expect(data).toStrictEqual({
639-
newPlan: { value: Plans.USERS_TEAMY },
642+
newPlan: teamPlanMonth,
640643
seats: 2,
641644
})
642645
})

src/shared/utils/upgradeForm.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,17 @@ export const getDefaultValuesUpgradeForm = ({
225225

226226
// Ensure we default to monthly plan regardless of current billing cycle
227227
let newPlan = proPlanMonth
228-
if ((isSentryUpgrade && !plan?.isSentryPlan) || selectedPlan?.isSentryPlan) {
228+
if (
229+
(isSentryUpgrade && !plan?.isSentryPlan) ||
230+
plan?.isSentryPlan ||
231+
selectedPlan?.isSentryPlan
232+
) {
229233
newPlan = sentryPlanMonth
230234
} else if (plan?.isTeamPlan || selectedPlan?.isTeamPlan) {
231235
newPlan = teamPlanMonth
232236
}
237+
// Fallback order: preferred monthly plan -> selectedPlan -> plan
238+
newPlan = newPlan ?? selectedPlan ?? plan ?? undefined
233239

234240
const seats = extractSeats({
235241
// free seats are included in planUserCount but we want to use the paid number

0 commit comments

Comments
 (0)