Skip to content

Commit 52909c8

Browse files
authored
fix: usesInvoice should hide change plan button on members page (#3782)
1 parent c3c615f commit 52909c8

File tree

7 files changed

+183
-143
lines changed

7 files changed

+183
-143
lines changed

src/pages/MembersPage/MembersActivation/Activation/Activation.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useAccountDetails } from 'services/account/useAccountDetails'
44
import { TrialStatuses, usePlanData } from 'services/account/usePlanData'
55
import A from 'ui/A/A'
66

7-
import ChangePlanLink from './ChangePlanLink'
7+
import ChangePlanLink from './ChangePlanLink/ChangePlanLink'
88

99
function Activation() {
1010
const { owner, provider } = useParams()

src/pages/MembersPage/MembersActivation/Activation/Activation.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BillingRate, Plans } from 'shared/utils/billing'
99

1010
import Activation from './Activation'
1111

12-
vi.mock('./ChangePlanLink', () => ({
12+
vi.mock('./ChangePlanLink/ChangePlanLink', () => ({
1313
default: vi.fn(() => 'ChangePlanLink'),
1414
}))
1515

src/pages/MembersPage/MembersActivation/Activation/ChangePlanLink/ChangePlanLink.jsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/pages/MembersPage/MembersActivation/Activation/ChangePlanLink/ChangePlanLink.test.jsx

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { render, screen, waitFor } from '@testing-library/react'
2+
import React from 'react'
3+
import { MemoryRouter, Route } from 'react-router-dom'
4+
import { z } from 'zod'
5+
6+
import config from 'config'
7+
8+
import { AccountDetailsSchema } from 'services/account/useAccountDetails'
9+
import { Plan } from 'services/account/usePlanData'
10+
11+
import ChangePlanLink from './ChangePlanLink'
12+
13+
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
14+
<MemoryRouter initialEntries={['/members/gh/critical-role']}>
15+
<Route path="/:provider/:owner/:repo">{children}</Route>
16+
</MemoryRouter>
17+
)
18+
19+
describe('Members ChangePlanLink', () => {
20+
describe('When user is non enterprise', () => {
21+
it('Renders change plan link', async () => {
22+
const mockedAccountDetailsNonEnterprise = {
23+
subscriptionDetail: {
24+
collectionMethod: 'paid',
25+
},
26+
} as z.infer<typeof AccountDetailsSchema>
27+
const mockedPlan = {
28+
isEnterprisePlan: false,
29+
} as Plan
30+
render(
31+
<ChangePlanLink
32+
accountDetails={mockedAccountDetailsNonEnterprise}
33+
plan={mockedPlan}
34+
/>,
35+
{ wrapper }
36+
)
37+
38+
const changePlanLink = await screen.findByRole('link', {
39+
name: 'change plan',
40+
})
41+
expect(changePlanLink).toBeInTheDocument()
42+
})
43+
})
44+
45+
describe('When config is self hosted', () => {
46+
beforeEach(() => {
47+
config.IS_SELF_HOSTED = true
48+
})
49+
50+
it('Does not render change plan link', async () => {
51+
const mockedAccountDetailsNonEnterprise = {
52+
subscriptionDetail: {
53+
collectionMethod: 'paid',
54+
},
55+
} as z.infer<typeof AccountDetailsSchema>
56+
const mockedPlan = {
57+
isEnterprisePlan: false,
58+
} as Plan
59+
60+
render(
61+
<ChangePlanLink
62+
accountDetails={mockedAccountDetailsNonEnterprise}
63+
plan={mockedPlan}
64+
/>,
65+
{ wrapper }
66+
)
67+
68+
await waitFor(() => {
69+
expect(screen.queryByText(/change plan/)).not.toBeInTheDocument()
70+
})
71+
})
72+
})
73+
74+
describe('When user has enterprise plan', () => {
75+
it('Does not render change plan link', async () => {
76+
const mockedAccountDetailsEnterprise = {
77+
subscriptionDetail: {
78+
collectionMethod: 'paid',
79+
},
80+
} as z.infer<typeof AccountDetailsSchema>
81+
const mockedPlan = {
82+
isEnterprisePlan: true,
83+
} as Plan
84+
85+
render(
86+
<ChangePlanLink
87+
accountDetails={mockedAccountDetailsEnterprise}
88+
plan={mockedPlan}
89+
/>,
90+
{ wrapper }
91+
)
92+
93+
await waitFor(() => {
94+
expect(screen.queryByText(/change plan/)).not.toBeInTheDocument()
95+
})
96+
})
97+
})
98+
99+
describe('When user is invoiced user', () => {
100+
it('Does not render change plan link when send_invoice', async () => {
101+
const mockedAccountDetailsInvoiceUser = {
102+
subscriptionDetail: {
103+
collectionMethod: 'send_invoice',
104+
},
105+
} as z.infer<typeof AccountDetailsSchema>
106+
const mockedPlan = {
107+
isEnterprisePlan: false,
108+
} as Plan
109+
110+
render(
111+
<ChangePlanLink
112+
accountDetails={mockedAccountDetailsInvoiceUser}
113+
plan={mockedPlan}
114+
/>,
115+
{ wrapper }
116+
)
117+
118+
await waitFor(() => {
119+
expect(screen.queryByText(/change plan/)).not.toBeInTheDocument()
120+
})
121+
})
122+
it('Does not render change plan link when usesInvoice', async () => {
123+
const mockedAccountDetailsInvoiceUser = {
124+
usesInvoice: true,
125+
} as z.infer<typeof AccountDetailsSchema>
126+
const mockedPlan = {
127+
isEnterprisePlan: false,
128+
} as Plan
129+
130+
render(
131+
<ChangePlanLink
132+
accountDetails={mockedAccountDetailsInvoiceUser}
133+
plan={mockedPlan}
134+
/>,
135+
{ wrapper }
136+
)
137+
138+
await waitFor(() => {
139+
expect(screen.queryByText(/change plan/)).not.toBeInTheDocument()
140+
})
141+
})
142+
})
143+
})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { z } from 'zod'
2+
3+
import config from 'config'
4+
5+
import { AccountDetailsSchema } from 'services/account/useAccountDetails'
6+
import { Plan } from 'services/account/usePlanData'
7+
import { CollectionMethods } from 'shared/utils/billing'
8+
import A from 'ui/A'
9+
10+
interface ChangePlanLinkProps {
11+
accountDetails: z.infer<typeof AccountDetailsSchema>
12+
plan: Plan
13+
}
14+
15+
function ChangePlanLink({ accountDetails, plan }: ChangePlanLinkProps) {
16+
const isInvoicedCustomer =
17+
accountDetails?.subscriptionDetail?.collectionMethod ===
18+
CollectionMethods.INVOICED_CUSTOMER_METHOD || accountDetails?.usesInvoice
19+
20+
if (config.IS_SELF_HOSTED || isInvoicedCustomer || plan?.isEnterprisePlan) {
21+
return null
22+
}
23+
24+
return (
25+
<span className="text-xs">
26+
<A
27+
to={{ pageName: 'upgradeOrgPlan' }}
28+
hook="change-plan-link"
29+
isExternal={false}
30+
variant="semibold"
31+
>
32+
change plan
33+
</A>
34+
</span>
35+
)
36+
}
37+
38+
export default ChangePlanLink

src/pages/MembersPage/MembersActivation/Activation/ChangePlanLink/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)