Skip to content

Commit

Permalink
chore: Remove multipleTiers FF calls throughout app (#3153)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry authored Aug 29, 2024
1 parent bcc1419 commit 8e7daaa
Show file tree
Hide file tree
Showing 36 changed files with 296 additions and 825 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ import { useParams } from 'react-router-dom'
import { useCommit } from 'services/commit'
import { useRepoOverview } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import { extractUploads } from 'shared/utils/extractUploads'

export function useUploads() {
const { provider, owner, repo, commit } = useParams()
const { data: overview } = useRepoOverview({ provider, owner, repo })
const { multipleTiers } = useFlags({
multipleTiers: false,
})
const { data: tierData } = useTier({ provider, owner })

// TODO: We need backend functionality to properly manage access to carryforward flags for team tier members
const isTeamPlan =
multipleTiers && tierData === TierNames.TEAM && overview?.private
const isTeamPlan = tierData === TierNames.TEAM && overview?.private

const { data } = useCommit({
provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import {
compareTotalsEmpty,
} from 'services/commit/mocks'
import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import { useUploads } from './useUploads'

jest.mock('shared/featureFlags')

const mockOverview = {
owner: {
isCurrentUserActivated: true,
Expand Down Expand Up @@ -63,10 +60,6 @@ describe('useUploads', () => {
function setup(query, tierValue = TierNames.PRO) {
server.use(query, compareTotalsEmpty)

useFlags.mockReturnValue({
multipleTiers: true,
})

server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
return res(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import FilesChangedTab from './FilesChangedTab'

jest.mock('./FilesChangedTable', () => () => 'FilesChangedTable')
jest.mock('./FilesChangedTableTeam', () => () => 'FilesChangedTableTeam')

jest.mock('shared/featureFlags')
const mockedUseFlags = useFlags as jest.Mock<{ multipleTiers: boolean }>

const mockTeamTier = {
owner: {
plan: {
Expand Down Expand Up @@ -75,16 +71,11 @@ afterAll(() => {

interface SetupArgs {
planValue: 'team' | 'pro'
flagValue: boolean
isPrivate?: boolean
}

describe('FilesChangedTab', () => {
function setup({ planValue, flagValue, isPrivate = false }: SetupArgs) {
mockedUseFlags.mockReturnValue({
multipleTiers: flagValue,
})

function setup({ planValue, isPrivate = false }: SetupArgs) {
server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
if (planValue === 'team') {
Expand All @@ -101,7 +92,7 @@ describe('FilesChangedTab', () => {

describe('user has pro tier', () => {
it('renders files changed table', async () => {
setup({ planValue: TierNames.PRO, flagValue: false })
setup({ planValue: TierNames.PRO })
render(<FilesChangedTab />, { wrapper })

const table = await screen.findByText('FilesChangedTable')
Expand All @@ -112,7 +103,7 @@ describe('FilesChangedTab', () => {
describe('user has team tier', () => {
describe('repo is private', () => {
it('renders team files changed table', async () => {
setup({ planValue: TierNames.TEAM, flagValue: true, isPrivate: true })
setup({ planValue: TierNames.TEAM, isPrivate: true })

render(<FilesChangedTab />, { wrapper })

Expand All @@ -123,7 +114,7 @@ describe('FilesChangedTab', () => {

describe('repo is public', () => {
it('renders files changed table', async () => {
setup({ planValue: TierNames.TEAM, flagValue: false, isPrivate: false })
setup({ planValue: TierNames.TEAM, isPrivate: false })
render(<FilesChangedTab />, { wrapper })

const table = await screen.findByText('FilesChangedTable')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useParams } from 'react-router-dom'
import ToggleHeader from 'pages/CommitDetailPage/Header/ToggleHeader/ToggleHeader'
import { useRepoSettingsTeam } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import Spinner from 'ui/Spinner'

const FilesChangedTable = lazy(() => import('./FilesChangedTable'))
Expand All @@ -25,17 +24,9 @@ function FilesChanged() {
const { provider, owner } = useParams<URLParams>()
const { data: repoSettings } = useRepoSettingsTeam()

const { multipleTiers } = useFlags({
multipleTiers: false,
})

const { data: tierData } = useTier({ provider, owner })

if (
tierData === TierNames.TEAM &&
!!repoSettings?.repository?.private &&
multipleTiers
) {
if (tierData === TierNames.TEAM && !!repoSettings?.repository?.private) {
return (
<Suspense fallback={<Loader />}>
<ToggleHeader />
Expand Down
20 changes: 6 additions & 14 deletions src/pages/CommitDetailPage/Header/Header.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { TierNames } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import Header from './Header'

jest.mock('./HeaderDefault', () => () => 'Default Header')
jest.mock('./HeaderTeam', () => () => 'Team Header')
jest.mock('shared/featureFlags')

const mockedUseFlags = useFlags as jest.Mock<{ multipleTiers: boolean }>

const mockRepoSettings = (isPrivate = false) => ({
owner: {
Expand Down Expand Up @@ -53,19 +49,15 @@ afterEach(() => {
})
afterAll(() => server.close())
interface SetupArgs {
multipleTiers: boolean
teamPlan: boolean
isPrivate?: boolean
}

describe('Header', () => {
function setup({ multipleTiers = false, isPrivate = false }: SetupArgs) {
mockedUseFlags.mockReturnValue({
multipleTiers,
})

function setup({ teamPlan = false, isPrivate = false }: SetupArgs) {
server.use(
graphql.query('OwnerTier', (req, res, ctx) => {
if (multipleTiers) {
if (teamPlan) {
return res(
ctx.status(200),
ctx.data({ owner: { plan: { tierName: TierNames.TEAM } } })
Expand All @@ -84,7 +76,7 @@ describe('Header', () => {

describe('when rendered and customer is not team tier', () => {
beforeEach(() => {
setup({ multipleTiers: false })
setup({ teamPlan: false })
})

it('renders the default header component', async () => {
Expand All @@ -101,7 +93,7 @@ describe('Header', () => {
describe('when rendered and customer has team tier', () => {
describe('when the repository is private', () => {
beforeEach(() => {
setup({ multipleTiers: true, isPrivate: true })
setup({ teamPlan: true, isPrivate: true })
})

it('renders the team header component', async () => {
Expand All @@ -117,7 +109,7 @@ describe('Header', () => {

describe('when the repository is public', () => {
beforeEach(() => {
setup({ multipleTiers: true, isPrivate: false })
setup({ teamPlan: true, isPrivate: false })
})

it('renders the default team component', async () => {
Expand Down
10 changes: 1 addition & 9 deletions src/pages/CommitDetailPage/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useParams } from 'react-router-dom'

import { useRepoSettingsTeam } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'

import HeaderDefault from './HeaderDefault'
import HeaderTeam from './HeaderTeam'
Expand All @@ -15,16 +14,9 @@ interface URLParams {
function Header() {
const { provider, owner } = useParams<URLParams>()
const { data: tierData } = useTier({ provider, owner })
const { multipleTiers } = useFlags({
multipleTiers: false,
})
const { data: repoSettingsTeam } = useRepoSettingsTeam()

if (
repoSettingsTeam?.repository?.private &&
multipleTiers &&
tierData === TierNames.TEAM
) {
if (repoSettingsTeam?.repository?.private && tierData === TierNames.TEAM) {
return <HeaderTeam />
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useParams } from 'react-router-dom'
import ComponentsSelector from 'pages/CommitDetailPage/CommitCoverage/routes/ComponentsSelector'
import { useRepoOverview } from 'services/repo'
import { TierNames, useTier } from 'services/tier'
import { useFlags } from 'shared/featureFlags'
import { LINE_STATE } from 'shared/utils/fileviewer'
import {
TitleCoverage,
Expand All @@ -22,13 +21,9 @@ function ToggleHeader({ showHitCount = true, noBottomBorder = false }) {
const { provider, owner, repo } = useParams<URLParams>()

const { data: overview } = useRepoOverview({ provider, owner, repo })
const { multipleTiers } = useFlags({
multipleTiers: false,
})

const { data: tierData } = useTier({ provider, owner })
const isTeamPlan =
multipleTiers && tierData === TierNames.TEAM && overview?.private
const isTeamPlan = tierData === TierNames.TEAM && overview?.private

const containerClasses = cs(
'flex w-full flex-1 flex-wrap items-start gap-2 bg-white sm:flex-row sm:items-center md:mb-1 lg:w-auto lg:flex-none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import { TrialStatuses } from 'services/account'
import { useFlags } from 'shared/featureFlags'
import { Plans } from 'shared/utils/billing'

import CancelPlanPage from './CancelPlanPage'
Expand All @@ -17,8 +16,6 @@ jest.mock(
'./subRoutes/TeamPlanSpecialOffer',
() => () => 'TeamPlanSpecialOffer'
)
jest.mock('shared/featureFlags')
const mockedUseFlags = useFlags as jest.Mock<{ multipleTiers: boolean }>

const teamPlans = [
{
Expand Down Expand Up @@ -129,7 +126,6 @@ interface SetupProps {
hasDiscount?: boolean
planValue?: string
trialStatus?: string
multipleTiers?: boolean
hasTeamPlans?: boolean
}

Expand All @@ -138,11 +134,8 @@ describe('CancelPlanPage', () => {
hasDiscount = false,
planValue = Plans.USERS_PR_INAPPM,
trialStatus = TrialStatuses.NOT_STARTED,
multipleTiers = false,
hasTeamPlans = false,
}: SetupProps = {}) {
mockedUseFlags.mockReturnValue({ multipleTiers })

server.use(
rest.get('internal/gh/codecov/account-details/', (req, res, ctx) =>
res(
Expand Down Expand Up @@ -347,7 +340,7 @@ describe('CancelPlanPage', () => {
})

describe('user has team plans in available plans', () => {
beforeEach(() => setup({ hasTeamPlans: true, multipleTiers: true }))
beforeEach(() => setup({ hasTeamPlans: true }))

it('renders team plan special offer', async () => {
render(<CancelPlanPage />, {
Expand All @@ -360,7 +353,7 @@ describe('CancelPlanPage', () => {
})

describe('user does not have team plans in available plans', () => {
beforeEach(() => setup({ hasTeamPlans: false, multipleTiers: true }))
beforeEach(() => setup({ hasTeamPlans: false }))

it('renders special offer', async () => {
render(<CancelPlanPage />, {
Expand All @@ -376,7 +369,6 @@ describe('CancelPlanPage', () => {
beforeEach(() =>
setup({
planValue: Plans.USERS_TEAMM,
multipleTiers: true,
hasTeamPlans: true,
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useAvailablePlans,
usePlanData,
} from 'services/account'
import { useFlags } from 'shared/featureFlags'
import {
isEnterprisePlan,
isMonthlyPlan,
Expand Down Expand Up @@ -41,9 +40,6 @@ function CancelPlanPage() {
provider,
owner,
})
const { multipleTiers } = useFlags({
multipleTiers: false,
})

const isOnTrial =
isTrialPlan(planData?.plan?.value) &&
Expand All @@ -59,7 +55,6 @@ function CancelPlanPage() {
const showSpecialOffer =
discountNotApplied && isMonthlyPlan(accountDetailsData?.plan?.value)
const showTeamSpecialOffer =
multipleTiers &&
shouldDisplayTeamCard({ plans }) &&
isProPlan(accountDetailsData?.plan?.value)
const showCancelPage = showSpecialOffer || showTeamSpecialOffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ afterAll(() => {

describe('SpecialOffer', () => {
function setup(
{ unsuccessfulReq = false, multipleTiers } = {
{ unsuccessfulReq = false } = {
unsuccessfulReq: false,
multipleTiers: false,
}
) {
const user = userEvent.setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useAvailablePlans,
usePlanData,
} from 'services/account'
import { useFlags } from 'shared/featureFlags'
import BenefitList from 'shared/plan/BenefitList'
import ScheduledPlanDetails from 'shared/plan/ScheduledPlanDetails'
import {
Expand All @@ -32,9 +31,6 @@ function FreePlanCard({ plan, scheduledPhase }) {
owner,
})
const { data: plans } = useAvailablePlans({ provider, owner })
const { multipleTiers } = useFlags({
multipleTiers: false,
})

const uploadsNumber = ownerData?.numberOfUploads
const trialOngoing =
Expand Down Expand Up @@ -92,7 +88,7 @@ function FreePlanCard({ plan, scheduledPhase }) {
</div>
</div>
</div>
{shouldDisplayTeamCard({ plans }) && multipleTiers && <PlanUpgradeTeam />}
{shouldDisplayTeamCard({ plans }) && <PlanUpgradeTeam />}
<PlanUpgradePro
isSentryUpgrade={canApplySentryUpgrade({ plan, plans })}
plans={plans}
Expand Down
Loading

0 comments on commit 8e7daaa

Please sign in to comment.