Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Migrate off "Plan" object from accountDetails REST endpoint to GQL Plan #3597

Merged
merged 23 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbd9444
beginning to clean up references of helpers, added const and migrated…
ajay-sentry Dec 16, 2024
b4aa950
update storybook
ajay-sentry Dec 16, 2024
8f10d52
Revert "update storybook"
ajay-sentry Dec 16, 2024
36ea27f
update storybook
ajay-sentry Dec 16, 2024
b30ca5c
Merge branch 'main' of https://github.com/codecov/gazebo
ajay-sentry Dec 16, 2024
a325e49
Merge branch 'main' into Ajay/migrate-billing-rate-stuff-to-gql
ajay-sentry Dec 16, 2024
fca709e
remove usages of helpers including in tests, make a lot of planNames …
ajay-sentry Dec 16, 2024
8243f44
fix tests, clean up some weirdness with the zod schema for upgrade fo…
ajay-sentry Dec 17, 2024
dc5ad9a
tsc fixes
ajay-sentry Dec 17, 2024
f340a63
Merge branch 'main' into Ajay/migrate-billing-rate-stuff-to-gql
ajay-sentry Dec 17, 2024
9dae7f4
update plan types
ajay-sentry Dec 17, 2024
9e71cc4
update accountdetails mocks
ajay-sentry Dec 17, 2024
a4c7a08
Merge branch 'main' into Ajay/migrate-billing-rate-stuff-to-gql
ajay-sentry Dec 18, 2024
41a2b7f
Merge branch 'main' into Ajay/migrate-billing-rate-stuff-to-gql
ajay-sentry Dec 18, 2024
c68f0df
update to individualPlan type, fix some tests
ajay-sentry Dec 18, 2024
18c0349
fix rest of tests
ajay-sentry Dec 18, 2024
598e2fe
tsc and some tests
ajay-sentry Dec 18, 2024
0642ed6
fix tests
ajay-sentry Dec 18, 2024
5b0e949
change this back to nullish bc of broken memebers page
ajay-sentry Dec 18, 2024
c17625a
Merge branch 'Ajay/migrate-billing-rate-stuff-to-gql' into Ajay/migra…
ajay-sentry Dec 18, 2024
2c11aa9
fix tests and tsc
ajay-sentry Dec 18, 2024
f065b32
Merge branch 'main' into Ajay/migrate-off-account-details-plan
ajay-sentry Dec 19, 2024
91efa0a
clean up usages of accountDetails
ajay-sentry Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ describe('CancelPlanPage', () => {
hasPrivateRepos: true,
plan: {
...mockPlanData,
billingRate,
trialStatus,
value: planValue,
isEnterprisePlan: planValue === Plans.USERS_ENTERPRISEM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ function CancelPlanPage() {
return <Redirect to={`/plan/${provider}/${owner}`} />
}

const isMonthlyPlan =
accountDetailsData?.plan?.billingRate === BillingRate.MONTHLY
const isMonthlyPlan = planData?.plan?.billingRate === BillingRate.MONTHLY

const discountNotApplied =
!accountDetailsData?.subscriptionDetail?.customer?.discount
const showSpecialOffer = discountNotApplied && isMonthlyPlan
const showTeamSpecialOffer =
shouldDisplayTeamCard({ plans }) &&
isProPlan(accountDetailsData?.plan?.value)
shouldDisplayTeamCard({ plans }) && isProPlan(planData?.plan?.value)
const showCancelPage = showSpecialOffer || showTeamSpecialOffer

let redirectTo = `/plan/${provider}/${owner}/cancel/downgrade`
Expand Down
80 changes: 29 additions & 51 deletions src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MemoryRouter, Route } from 'react-router-dom'
import { z } from 'zod'

import { PlanUpdatedPlanNotificationContext } from 'pages/PlanPage/context'
import { AccountDetailsSchema } from 'services/account'
import { AccountDetailsSchema, TrialStatuses } from 'services/account'
import { BillingRate, Plans } from 'shared/utils/billing'
import { AlertOptions, type AlertOptionsType } from 'ui/Alert'

Expand All @@ -27,9 +27,6 @@ vi.mock('./AccountOrgs', () => ({ default: () => 'AccountOrgs' }))
const mockedAccountDetails = {
planProvider: 'github',
rootOrganization: {},
plan: {
value: Plans.USERS_FREE,
},
usesInvoice: false,
} as z.infer<typeof AccountDetailsSchema>

Expand All @@ -39,6 +36,24 @@ const mockNoEnterpriseAccount = {
},
}

const mockPlanDataResponse = {
baseUnitPrice: 10,
benefits: [],
billingRate: BillingRate.MONTHLY,
marketingName: 'some-name',
monthlyUploadLimit: 123,
value: Plans.USERS_PR_INAPPM,
trialStatus: TrialStatuses.NOT_STARTED,
trialStartDate: '',
trialEndDate: '',
trialTotalDays: 0,
pretrialUsersCount: 0,
planUserCount: 1,
hasSeatsLeft: true,
isEnterprisePlan: false,
isFreePlan: false,
}

const mockEnterpriseAccountDetailsNinetyPercent = {
owner: {
account: {
Expand Down Expand Up @@ -151,6 +166,13 @@ describe('CurrentOrgPlan', () => {
graphql.query('EnterpriseAccountDetails', () => {
return HttpResponse.json({ data: enterpriseAccountDetails })
}),
graphql.query('GetPlanData', () => {
return HttpResponse.json({
data: {
owner: { hasPrivateRepos: true, plan: { ...mockPlanDataResponse } },
},
})
}),
http.get('/internal/:provider/:owner/account-details', () => {
return HttpResponse.json(accountDetails)
})
Expand Down Expand Up @@ -184,15 +206,7 @@ describe('CurrentOrgPlan', () => {
describe('when plan update success banner should be shown', () => {
it('renders banner for plan successfully updated', async () => {
setup({
accountDetails: {
plan: {
baseUnitPrice: 12,
billingRate: BillingRate.MONTHLY,
marketingName: 'Pro',
quantity: 39,
value: Plans.USERS_PR_INAPPM,
},
} as z.infer<typeof AccountDetailsSchema>,
accountDetails: {} as z.infer<typeof AccountDetailsSchema>,
})

render(<CurrentOrgPlan />, { wrapper })
Expand All @@ -203,13 +217,6 @@ describe('CurrentOrgPlan', () => {
it('renders banner for plan successfully updated with scheduled details', async () => {
setup({
accountDetails: {
plan: {
baseUnitPrice: 12,
billingRate: BillingRate.MONTHLY,
marketingName: 'Pro',
quantity: 39,
value: Plans.USERS_PR_INAPPM,
},
scheduleDetail: {
scheduledPhase: {
quantity: 34,
Expand All @@ -229,15 +236,7 @@ describe('CurrentOrgPlan', () => {

it('does not render banner when no recent update made', async () => {
setup({
accountDetails: {
plan: {
baseUnitPrice: 12,
billingRate: BillingRate.MONTHLY,
marketingName: 'Pro',
quantity: 39,
value: Plans.USERS_PR_INAPPM,
},
} as z.infer<typeof AccountDetailsSchema>,
accountDetails: {} as z.infer<typeof AccountDetailsSchema>,
})
render(<CurrentOrgPlan />, { wrapper: noUpdatedPlanWrapper })
const currentPlanCard = await screen.findByText(/CurrentPlanCard/i)
Expand All @@ -253,13 +252,6 @@ describe('CurrentOrgPlan', () => {
it('renders when subscription detail data is available', async () => {
setup({
accountDetails: {
plan: {
baseUnitPrice: 12,
billingRate: BillingRate.MONTHLY,
marketingName: 'Pro',
quantity: 39,
value: Plans.USERS_PR_INAPPM,
},
subscriptionDetail: {
cancelAtPeriodEnd: true,
currentPeriodEnd: 1722631954,
Expand All @@ -282,13 +274,6 @@ describe('CurrentOrgPlan', () => {
accountDetails: {
planProvider: 'gitlab',
rootOrganization: null,
plan: {
value: Plans.USERS_FREE,
baseUnitPrice: 12,
benefits: ['a', 'b'],
billingRate: null,
marketingName: 'bob',
},
usesInvoice: false,
} as z.infer<typeof AccountDetailsSchema>,
})
Expand Down Expand Up @@ -318,13 +303,6 @@ describe('CurrentOrgPlan', () => {
accountDetails: {
planProvider: 'github',
rootOrganization: {},
plan: {
value: Plans.USERS_FREE,
baseUnitPrice: 12,
benefits: ['a', 'b'],
billingRate: null,
marketingName: 'bob',
},
usesInvoice: true,
} as z.infer<typeof AccountDetailsSchema>,
})
Expand Down Expand Up @@ -353,7 +331,7 @@ describe('CurrentOrgPlan', () => {
describe('when plan value is not provided', () => {
beforeEach(() => {
setup({
accountDetails: { ...mockedAccountDetails, plan: null },
accountDetails: { ...mockedAccountDetails },
})
})

Expand Down
10 changes: 8 additions & 2 deletions src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
import { useParams } from 'react-router-dom'

import { usePlanUpdatedNotification } from 'pages/PlanPage/context'
import { useAccountDetails } from 'services/account'
import { useAccountDetails, usePlanData } from 'services/account'
import { getScheduleStart } from 'shared/plan/ScheduledPlanDetails/ScheduledPlanDetails'
import A from 'ui/A'
import { Alert } from 'ui/Alert'
Expand All @@ -26,6 +26,12 @@ function CurrentOrgPlan() {
provider,
owner,
})

const { data: planData } = usePlanData({
provider,
owner,
})

const { data: enterpriseDetails } = useSuspenseQueryV5(
EnterpriseAccountDetailsQueryOpts({
provider,
Expand Down Expand Up @@ -57,7 +63,7 @@ function CurrentOrgPlan() {
) : null}
<InfoMessageStripeCallback />
{isDelinquent ? <DelinquentAlert /> : null}
{accountDetails?.plan ? (
{planData?.plan ? (
<div className="flex flex-col gap-4 sm:mr-4 sm:flex-initial md:w-2/3 lg:w-3/4">
{planUpdatedNotification.alertOption &&
!planUpdatedNotification.isCancellation ? (
Expand Down
30 changes: 1 addition & 29 deletions src/services/account/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BillingRate, Plans } from 'shared/utils/billing'
import { Plans } from 'shared/utils/billing'

/* eslint-disable camelcase */
export const invoiceObject = {
Expand Down Expand Up @@ -39,20 +39,6 @@ export const accountDetailsObject = {
activated_user_count: 19,
inactive_user_count: 5,
plan_auto_activate: true,
plan: {
marketing_name: 'Pro Team',
value: Plans.USERS_PR_INAPPM,
billing_rate: 'monthly',
base_unit_price: 12,
benefits: [
'Configurable # of users',
'Unlimited public repositories',
'Unlimited private repositories',
'Priority Support',
],
quantity: 20,
monthlyUploadLimit: null,
},
subscription_detail: {
latest_invoice: {
id: 'in_1JnNyfGlVGuVgOrkkdkCYayW',
Expand Down Expand Up @@ -154,20 +140,6 @@ export const accountDetailsParsedObj = {
activatedUserCount: 19,
inactiveUserCount: 5,
planAutoActivate: true,
plan: {
marketingName: 'Pro Team',
value: Plans.USERS_PR_INAPPM,
billingRate: BillingRate.MONTHLY,
baseUnitPrice: 12,
benefits: [
'Configurable # of users',
'Unlimited public repositories',
'Unlimited private repositories',
'Priority Support',
],
quantity: 20,
monthlyUploadLimit: null,
},
subscriptionDetail: {
latestInvoice: {
id: 'in_1JnNyfGlVGuVgOrkkdkCYayW',
Expand Down
17 changes: 1 addition & 16 deletions src/services/account/useAccountDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { z } from 'zod'

import Api from 'shared/api'
import { NetworkErrorObject } from 'shared/api/helpers'
import { BillingRate, Plans } from 'shared/utils/billing'

const InvoiceSchema = z
.object({
Expand Down Expand Up @@ -113,19 +112,6 @@ export const SubscriptionDetailSchema = z
})
.nullable()

export const PlanSchema = z
.object({
baseUnitPrice: z.number(),
benefits: z.array(z.string()),
billingRate: z.nativeEnum(BillingRate).nullish(),
marketingName: z.string(),
monthlyUploadLimit: z.number().nullish(),
quantity: z.number().nullish(),
value: z.nativeEnum(Plans),
trialDays: z.number().nullish(),
})
.nullable()

export const AccountDetailsSchema = z.object({
activatedStudentCount: z.number(),
activatedUserCount: z.number(),
Expand All @@ -136,13 +122,12 @@ export const AccountDetailsSchema = z.object({
integrationId: z.number().nullable(),
name: z.string().nullable(),
nbActivePrivateRepos: z.number().nullable(),
plan: PlanSchema,
planAutoActivate: z.boolean().nullable(),
planProvider: z.string().nullable(),
repoTotalCredits: z.number(),
rootOrganization: z
.object({
plan: PlanSchema,
username: z.string().nullish(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
.nullable(),
scheduleDetail: z
Expand Down
Loading
Loading