Skip to content

Commit 4021528

Browse files
authored
ref: Migrate off "Plan" object from accountDetails REST endpoint to GQL Plan (#3597)
1 parent 73a32da commit 4021528

File tree

7 files changed

+50
-166
lines changed

7 files changed

+50
-166
lines changed

src/pages/PlanPage/subRoutes/CancelPlanPage/CancelPlanPage.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ describe('CancelPlanPage', () => {
153153
hasPrivateRepos: true,
154154
plan: {
155155
...mockPlanData,
156+
billingRate,
156157
trialStatus,
157158
value: planValue,
158159
isEnterprisePlan: planValue === Plans.USERS_ENTERPRISEM,

src/pages/PlanPage/subRoutes/CancelPlanPage/CancelPlanPage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ function CancelPlanPage() {
4949
return <Redirect to={`/plan/${provider}/${owner}`} />
5050
}
5151

52-
const isMonthlyPlan =
53-
accountDetailsData?.plan?.billingRate === BillingRate.MONTHLY
52+
const isMonthlyPlan = planData?.plan?.billingRate === BillingRate.MONTHLY
5453

5554
const discountNotApplied =
5655
!accountDetailsData?.subscriptionDetail?.customer?.discount
5756
const showSpecialOffer = discountNotApplied && isMonthlyPlan
5857
const showTeamSpecialOffer =
59-
shouldDisplayTeamCard({ plans }) &&
60-
isProPlan(accountDetailsData?.plan?.value)
58+
shouldDisplayTeamCard({ plans }) && isProPlan(planData?.plan?.value)
6159
const showCancelPage = showSpecialOffer || showTeamSpecialOffer
6260

6361
let redirectTo = `/plan/${provider}/${owner}/cancel/downgrade`

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.test.tsx

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { MemoryRouter, Route } from 'react-router-dom'
1212
import { z } from 'zod'
1313

1414
import { PlanUpdatedPlanNotificationContext } from 'pages/PlanPage/context'
15-
import { AccountDetailsSchema } from 'services/account'
15+
import { AccountDetailsSchema, TrialStatuses } from 'services/account'
1616
import { BillingRate, Plans } from 'shared/utils/billing'
1717
import { AlertOptions, type AlertOptionsType } from 'ui/Alert'
1818

@@ -27,9 +27,6 @@ vi.mock('./AccountOrgs', () => ({ default: () => 'AccountOrgs' }))
2727
const mockedAccountDetails = {
2828
planProvider: 'github',
2929
rootOrganization: {},
30-
plan: {
31-
value: Plans.USERS_FREE,
32-
},
3330
usesInvoice: false,
3431
} as z.infer<typeof AccountDetailsSchema>
3532

@@ -39,6 +36,24 @@ const mockNoEnterpriseAccount = {
3936
},
4037
}
4138

39+
const mockPlanDataResponse = {
40+
baseUnitPrice: 10,
41+
benefits: [],
42+
billingRate: BillingRate.MONTHLY,
43+
marketingName: 'some-name',
44+
monthlyUploadLimit: 123,
45+
value: Plans.USERS_PR_INAPPM,
46+
trialStatus: TrialStatuses.NOT_STARTED,
47+
trialStartDate: '',
48+
trialEndDate: '',
49+
trialTotalDays: 0,
50+
pretrialUsersCount: 0,
51+
planUserCount: 1,
52+
hasSeatsLeft: true,
53+
isEnterprisePlan: false,
54+
isFreePlan: false,
55+
}
56+
4257
const mockEnterpriseAccountDetailsNinetyPercent = {
4358
owner: {
4459
account: {
@@ -151,6 +166,13 @@ describe('CurrentOrgPlan', () => {
151166
graphql.query('EnterpriseAccountDetails', () => {
152167
return HttpResponse.json({ data: enterpriseAccountDetails })
153168
}),
169+
graphql.query('GetPlanData', () => {
170+
return HttpResponse.json({
171+
data: {
172+
owner: { hasPrivateRepos: true, plan: { ...mockPlanDataResponse } },
173+
},
174+
})
175+
}),
154176
http.get('/internal/:provider/:owner/account-details', () => {
155177
return HttpResponse.json(accountDetails)
156178
})
@@ -184,15 +206,7 @@ describe('CurrentOrgPlan', () => {
184206
describe('when plan update success banner should be shown', () => {
185207
it('renders banner for plan successfully updated', async () => {
186208
setup({
187-
accountDetails: {
188-
plan: {
189-
baseUnitPrice: 12,
190-
billingRate: BillingRate.MONTHLY,
191-
marketingName: 'Pro',
192-
quantity: 39,
193-
value: Plans.USERS_PR_INAPPM,
194-
},
195-
} as z.infer<typeof AccountDetailsSchema>,
209+
accountDetails: {} as z.infer<typeof AccountDetailsSchema>,
196210
})
197211

198212
render(<CurrentOrgPlan />, { wrapper })
@@ -203,13 +217,6 @@ describe('CurrentOrgPlan', () => {
203217
it('renders banner for plan successfully updated with scheduled details', async () => {
204218
setup({
205219
accountDetails: {
206-
plan: {
207-
baseUnitPrice: 12,
208-
billingRate: BillingRate.MONTHLY,
209-
marketingName: 'Pro',
210-
quantity: 39,
211-
value: Plans.USERS_PR_INAPPM,
212-
},
213220
scheduleDetail: {
214221
scheduledPhase: {
215222
quantity: 34,
@@ -229,15 +236,7 @@ describe('CurrentOrgPlan', () => {
229236

230237
it('does not render banner when no recent update made', async () => {
231238
setup({
232-
accountDetails: {
233-
plan: {
234-
baseUnitPrice: 12,
235-
billingRate: BillingRate.MONTHLY,
236-
marketingName: 'Pro',
237-
quantity: 39,
238-
value: Plans.USERS_PR_INAPPM,
239-
},
240-
} as z.infer<typeof AccountDetailsSchema>,
239+
accountDetails: {} as z.infer<typeof AccountDetailsSchema>,
241240
})
242241
render(<CurrentOrgPlan />, { wrapper: noUpdatedPlanWrapper })
243242
const currentPlanCard = await screen.findByText(/CurrentPlanCard/i)
@@ -253,13 +252,6 @@ describe('CurrentOrgPlan', () => {
253252
it('renders when subscription detail data is available', async () => {
254253
setup({
255254
accountDetails: {
256-
plan: {
257-
baseUnitPrice: 12,
258-
billingRate: BillingRate.MONTHLY,
259-
marketingName: 'Pro',
260-
quantity: 39,
261-
value: Plans.USERS_PR_INAPPM,
262-
},
263255
subscriptionDetail: {
264256
cancelAtPeriodEnd: true,
265257
currentPeriodEnd: 1722631954,
@@ -282,13 +274,6 @@ describe('CurrentOrgPlan', () => {
282274
accountDetails: {
283275
planProvider: 'gitlab',
284276
rootOrganization: null,
285-
plan: {
286-
value: Plans.USERS_FREE,
287-
baseUnitPrice: 12,
288-
benefits: ['a', 'b'],
289-
billingRate: null,
290-
marketingName: 'bob',
291-
},
292277
usesInvoice: false,
293278
} as z.infer<typeof AccountDetailsSchema>,
294279
})
@@ -318,13 +303,6 @@ describe('CurrentOrgPlan', () => {
318303
accountDetails: {
319304
planProvider: 'github',
320305
rootOrganization: {},
321-
plan: {
322-
value: Plans.USERS_FREE,
323-
baseUnitPrice: 12,
324-
benefits: ['a', 'b'],
325-
billingRate: null,
326-
marketingName: 'bob',
327-
},
328306
usesInvoice: true,
329307
} as z.infer<typeof AccountDetailsSchema>,
330308
})
@@ -353,7 +331,7 @@ describe('CurrentOrgPlan', () => {
353331
describe('when plan value is not provided', () => {
354332
beforeEach(() => {
355333
setup({
356-
accountDetails: { ...mockedAccountDetails, plan: null },
334+
accountDetails: { ...mockedAccountDetails },
357335
})
358336
})
359337

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
22
import { useParams } from 'react-router-dom'
33

44
import { usePlanUpdatedNotification } from 'pages/PlanPage/context'
5-
import { useAccountDetails } from 'services/account'
5+
import { useAccountDetails, usePlanData } from 'services/account'
66
import { getScheduleStart } from 'shared/plan/ScheduledPlanDetails/ScheduledPlanDetails'
77
import A from 'ui/A'
88
import { Alert } from 'ui/Alert'
@@ -26,6 +26,12 @@ function CurrentOrgPlan() {
2626
provider,
2727
owner,
2828
})
29+
30+
const { data: planData } = usePlanData({
31+
provider,
32+
owner,
33+
})
34+
2935
const { data: enterpriseDetails } = useSuspenseQueryV5(
3036
EnterpriseAccountDetailsQueryOpts({
3137
provider,
@@ -57,7 +63,7 @@ function CurrentOrgPlan() {
5763
) : null}
5864
<InfoMessageStripeCallback />
5965
{isDelinquent ? <DelinquentAlert /> : null}
60-
{accountDetails?.plan ? (
66+
{planData?.plan ? (
6167
<div className="flex flex-col gap-4 sm:mr-4 sm:flex-initial md:w-2/3 lg:w-3/4">
6268
{planUpdatedNotification.alertOption &&
6369
!planUpdatedNotification.isCancellation ? (

src/services/account/mocks.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BillingRate, Plans } from 'shared/utils/billing'
1+
import { Plans } from 'shared/utils/billing'
22

33
/* eslint-disable camelcase */
44
export const invoiceObject = {
@@ -39,20 +39,6 @@ export const accountDetailsObject = {
3939
activated_user_count: 19,
4040
inactive_user_count: 5,
4141
plan_auto_activate: true,
42-
plan: {
43-
marketing_name: 'Pro Team',
44-
value: Plans.USERS_PR_INAPPM,
45-
billing_rate: 'monthly',
46-
base_unit_price: 12,
47-
benefits: [
48-
'Configurable # of users',
49-
'Unlimited public repositories',
50-
'Unlimited private repositories',
51-
'Priority Support',
52-
],
53-
quantity: 20,
54-
monthlyUploadLimit: null,
55-
},
5642
subscription_detail: {
5743
latest_invoice: {
5844
id: 'in_1JnNyfGlVGuVgOrkkdkCYayW',
@@ -154,20 +140,6 @@ export const accountDetailsParsedObj = {
154140
activatedUserCount: 19,
155141
inactiveUserCount: 5,
156142
planAutoActivate: true,
157-
plan: {
158-
marketingName: 'Pro Team',
159-
value: Plans.USERS_PR_INAPPM,
160-
billingRate: BillingRate.MONTHLY,
161-
baseUnitPrice: 12,
162-
benefits: [
163-
'Configurable # of users',
164-
'Unlimited public repositories',
165-
'Unlimited private repositories',
166-
'Priority Support',
167-
],
168-
quantity: 20,
169-
monthlyUploadLimit: null,
170-
},
171143
subscriptionDetail: {
172144
latestInvoice: {
173145
id: 'in_1JnNyfGlVGuVgOrkkdkCYayW',

src/services/account/useAccountDetails.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { z } from 'zod'
33

44
import Api from 'shared/api'
55
import { NetworkErrorObject } from 'shared/api/helpers'
6-
import { BillingRate, Plans } from 'shared/utils/billing'
76

87
const InvoiceSchema = z
98
.object({
@@ -113,19 +112,6 @@ export const SubscriptionDetailSchema = z
113112
})
114113
.nullable()
115114

116-
export const PlanSchema = z
117-
.object({
118-
baseUnitPrice: z.number(),
119-
benefits: z.array(z.string()),
120-
billingRate: z.nativeEnum(BillingRate).nullish(),
121-
marketingName: z.string(),
122-
monthlyUploadLimit: z.number().nullish(),
123-
quantity: z.number().nullish(),
124-
value: z.nativeEnum(Plans),
125-
trialDays: z.number().nullish(),
126-
})
127-
.nullable()
128-
129115
export const AccountDetailsSchema = z.object({
130116
activatedStudentCount: z.number(),
131117
activatedUserCount: z.number(),
@@ -136,13 +122,12 @@ export const AccountDetailsSchema = z.object({
136122
integrationId: z.number().nullable(),
137123
name: z.string().nullable(),
138124
nbActivePrivateRepos: z.number().nullable(),
139-
plan: PlanSchema,
140125
planAutoActivate: z.boolean().nullable(),
141126
planProvider: z.string().nullable(),
142127
repoTotalCredits: z.number(),
143128
rootOrganization: z
144129
.object({
145-
plan: PlanSchema,
130+
username: z.string().nullish(),
146131
})
147132
.nullable(),
148133
scheduleDetail: z

0 commit comments

Comments
 (0)