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

feat: Only show auto-activate toggle for admins when on enterprise cloud plan #3690

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
18 changes: 13 additions & 5 deletions src/pages/MembersPage/MembersActivation/MembersActivation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@ import PropTypes from 'prop-types'
import { useParams } from 'react-router-dom'

import { TrialStatuses, useAccountDetails, usePlanData } from 'services/account'
import { useOwner } from 'services/user'

import Activation from './Activation'
import AutoActivate from './AutoActivate'

function MemberActivation() {
const { owner, provider } = useParams()
const { data: accountDetails } = useAccountDetails({ owner, provider })
const { data: ownerData } = useOwner({ username: owner })

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

const planAutoActivate = accountDetails?.planAutoActivate

const showAutoActivate =
!isUndefined(planAutoActivate) &&
const planAutoActivateIsDefined = !isUndefined(
accountDetails?.planAutoActivate
)
const isNotTrialing =
!planData?.plan?.isTrialPlan &&
planData?.plan?.trialStatus !== TrialStatuses.ONGOING
const isNotAnEnterpriseDeveloper = !(
planData?.plan?.isEnterprisePlan && !ownerData.isAdmin
) // only show for admins on enterprise cloud plans

const showAutoActivate =
planAutoActivateIsDefined && isNotTrialing && isNotAnEnterpriseDeveloper

return (
<div className="border-2 border-ds-gray-primary">
Expand All @@ -30,7 +38,7 @@ function MemberActivation() {
<>
{/* TODO: have this be created dynamically w/ a better parent component */}
<hr className="mx-4" />
<AutoActivate planAutoActivate={planAutoActivate} />
<AutoActivate planAutoActivate={accountDetails?.planAutoActivate} />
</>
)}
</div>
Expand Down
102 changes: 101 additions & 1 deletion src/pages/MembersPage/MembersActivation/MembersActivation.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ describe('Members Activation', () => {
function setup(
accountDetails = mockedAccountDetails,
trialStatus = TrialStatuses.NOT_STARTED,
planValue = mockedAccountDetails.plan.value
planValue = mockedAccountDetails.plan.value,
isEnterprisePlan = false,
isAdmin = true
) {
server.use(
http.get('/internal/:provider/:owner/account-details/', () => {
return HttpResponse.json(accountDetails)
}),
graphql.query('DetailOwner', () => {
return HttpResponse.json({
data: {
owner: {
ownerid: 123,
username: 'codecov',
avatarUrl: null,
isCurrentUserPartOfOrg: true,
isAdmin,
},
},
})
}),
graphql.query('GetPlanData', () => {
return HttpResponse.json({
data: {
Expand All @@ -93,6 +108,7 @@ describe('Members Activation', () => {
...mockPlanData,
trialStatus,
value: planValue,
isEnterprisePlan,
},
},
},
Expand Down Expand Up @@ -180,6 +196,90 @@ describe('Members Activation', () => {
expect(AutoActivate).not.toBeInTheDocument()
})
})

describe('user is in an enterprise org', () => {
describe('and they are not an admin', () => {
it('does not render auto activate component', async () => {
setup(
{ ...mockedAccountDetails, planAutoActivate: true },
TrialStatuses.NOT_STARTED,
Plans.USERS_ENTERPRISEY,
true,
false
)

render(<MembersActivation />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)

const AutoActivate = screen.queryByText(/AutoActivate/)
expect(AutoActivate).not.toBeInTheDocument()
})
})

describe.only('and they are an admin', () => {
it('renders auto activate component', async () => {
setup(
{ ...mockedAccountDetails, planAutoActivate: true },
TrialStatuses.NOT_STARTED,
Plans.USERS_ENTERPRISEY,
true,
true
)

render(<MembersActivation />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)

const AutoActivate = await screen.findByText(/AutoActivate/)
expect(AutoActivate).toBeInTheDocument()
})
})
})

describe('user is not in an enterprise org', () => {
describe('and they are not an admin', () => {
it('renders auto activate component', async () => {
setup(
{ ...mockedAccountDetails, planAutoActivate: true },
TrialStatuses.NOT_STARTED,
Plans.USERS_PR_INAPPM,
false,
false
)

render(<MembersActivation />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)

const AutoActivate = await screen.findByText(/AutoActivate/)
expect(AutoActivate).toBeInTheDocument()
})
})

describe('and they are an admin', () => {
it('renders auto activate component', async () => {
setup(
{ ...mockedAccountDetails, planAutoActivate: true },
TrialStatuses.NOT_STARTED,
Plans.USERS_PR_INAPPM,
false,
true
)

render(<MembersActivation />, { wrapper })

await waitFor(() => queryClient.isFetching)
await waitFor(() => !queryClient.isFetching)

const AutoActivate = await screen.findByText(/AutoActivate/)
expect(AutoActivate).toBeInTheDocument()
})
})
})
})
})
})
Loading