Skip to content

Commit

Permalink
chore: Shared/utils conversions Part 2 Part 1 (#3461)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry authored Nov 15, 2024
1 parent afbbc7b commit 848db44
Show file tree
Hide file tree
Showing 117 changed files with 751 additions and 679 deletions.
3 changes: 2 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { type Mock, vi } from 'vitest'
import config from 'config'

import { useLocationParams } from 'services/navigation'
import { Plans } from 'shared/utils/billing'

import App from './App'

Expand Down Expand Up @@ -85,7 +86,7 @@ const user = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/BaseLayout/BaseLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import config from 'config'
import { useImage } from 'services/image'
import { useImpersonate } from 'services/impersonate'
import { useInternalUser, useUser } from 'services/user'
import { Plans } from 'shared/utils/billing'

import BaseLayout from './BaseLayout'

Expand Down Expand Up @@ -73,7 +74,7 @@ const mockTrackingMetadata = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/BaseLayout/hooks/useUserAccessGate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MemoryRouter, Route } from 'react-router-dom'
import config from 'config'

import { User } from 'services/user'
import { Plans } from 'shared/utils/billing'

import { useUserAccessGate } from './useUserAccessGate'

Expand Down Expand Up @@ -73,7 +74,7 @@ const mockTrackingMetadata = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import config from 'config'

import { useImpersonate } from 'services/impersonate'
import { User } from 'services/user'
import { Plans } from 'shared/utils/billing'

import Header from './Header'

Expand Down Expand Up @@ -58,7 +59,7 @@ const mockUser = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/Header/components/Navigator/Navigator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useLayoutEffect } from 'react'
import { MemoryRouter, Route, useParams } from 'react-router-dom'

import { RepoBreadcrumbProvider, useCrumbs } from 'pages/RepoPage/context'
import { Plans } from 'shared/utils/billing'

import Navigator from './Navigator'

Expand Down Expand Up @@ -83,7 +84,7 @@ const mockUser = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { type Mock } from 'vitest'
import config from 'config'

import { useImage } from 'services/image'
import { Plans } from 'shared/utils/billing'

import UserDropdown from './UserDropdown'

Expand Down Expand Up @@ -36,7 +37,7 @@ const mockUser = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/Header/components/UserDropdown/UserDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { useHistory, useParams } from 'react-router-dom'
import config from 'config'

import { useUser } from 'services/user'
import { Provider } from 'shared/api/helpers'
import { providerToName } from 'shared/utils/provider'
import Avatar from 'ui/Avatar'
import Button from 'ui/Button'
import { Dropdown } from 'ui/Dropdown/Dropdown'

interface URLParams {
provider: string
provider: Provider
}

type DropdownItem = {
Expand Down
3 changes: 2 additions & 1 deletion src/mocks/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
flagsSelectHandler,
} from 'services/repo/mocks'
import { randomUsersHandler } from 'services/users/mocks'
import { Plans } from 'shared/utils/billing'

export const handlers = [
repoCoverageHandler,
Expand Down Expand Up @@ -42,7 +43,7 @@ graphql.query('CurrentUser', (info) => {
service: 'github',
ownerid: 3456556,
serviceId: '87824812',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: true,
hasYaml: false,
bot: null,
Expand Down
12 changes: 7 additions & 5 deletions src/pages/AccountSettings/AccountSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { MemoryRouter, Route } from 'react-router-dom'

import config from 'config'

import { Plans } from 'shared/utils/billing'

import AccountSettings from './AccountSettings'

vi.mock('config')
Expand All @@ -29,7 +31,7 @@ const mockPlanData = {
billingRate: 'monthly',
marketingName: 'Pro Team',
monthlyUploadLimit: 250,
value: 'free-plan',
value: Plans.USERS_BASIC,
trialStatus: 'NOT_STARTED',
trialStartDate: '',
trialEndDate: '',
Expand Down Expand Up @@ -63,7 +65,7 @@ const mockCurrentUser = (username) => ({
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down Expand Up @@ -129,14 +131,14 @@ describe('AccountSettings', () => {
username = 'codecov',
isAdmin = false,
hideAccessTab = true,
planValue = 'free-plan',
planValue = Plans.USERS_BASIC,
} = {
isSelfHosted: false,
owner: 'codecov',
username: 'codecov',
isAdmin: false,
hideAccessTab: true,
planValue: 'free-plan',
planValue: Plans.USERS_BASIC,
}
) {
config.IS_SELF_HOSTED = isSelfHosted
Expand Down Expand Up @@ -357,7 +359,7 @@ describe('AccountSettings', () => {
describe('on okta access route', () => {
it('renders okta access tab for enterprise users', async () => {
setup({
planValue: 'users-enterprisem',
planValue: Plans.USERS_ENTERPRISEM,
isSelfHosted: false,
})

Expand Down
16 changes: 9 additions & 7 deletions src/pages/AccountSettings/AccountSettingsSideMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { MemoryRouter, Route } from 'react-router-dom'

import config from 'config'

import { Plans } from 'shared/utils/billing'

import AccountSettingsSideMenu from './AccountSettingsSideMenu'

vi.mock('config')
Expand All @@ -17,7 +19,7 @@ const mockPlanData = {
billingRate: 'monthly',
marketingName: 'Pro Team',
monthlyUploadLimit: 250,
value: 'free-plan',
value: Plans.USERS_BASIC,
trialStatus: 'NOT_STARTED',
trialStartDate: '',
trialEndDate: '',
Expand Down Expand Up @@ -51,7 +53,7 @@ const mockCurrentUser = (username) => ({
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down Expand Up @@ -117,14 +119,14 @@ describe('AccountSettingsSideMenu', () => {
owner = 'codecov',
isSelfHosted = false,
hideAccessTab = false,
planValue = 'free-plan',
planValue = Plans.USERS_BASIC,
} = {
isAdmin: false,
username: 'codecov',
isSelfHosted: false,
owner: 'codecov',
hideAccessTab: false,
planValue: 'free-plan',
planValue: Plans.USERS_BASIC,
}
) {
config.IS_SELF_HOSTED = isSelfHosted
Expand Down Expand Up @@ -288,7 +290,7 @@ describe('AccountSettingsSideMenu', () => {

describe("okta access is displayed according to the user's plan", () => {
it('displays okta access tab if user is on enterprise', async () => {
setup({ isAdmin: true, planValue: 'users-enterprisem' })
setup({ isAdmin: true, planValue: Plans.USERS_ENTERPRISEM })

render(<AccountSettingsSideMenu />, {
wrapper: wrapper(),
Expand Down Expand Up @@ -339,7 +341,7 @@ describe('AccountSettingsSideMenu', () => {
setup({
isAdmin: true,
username: 'cool-new-user',
planValue: 'users-enterprisem',
planValue: Plans.USERS_ENTERPRISEM,
})

render(<AccountSettingsSideMenu />, {
Expand Down Expand Up @@ -411,7 +413,7 @@ describe('AccountSettingsSideMenu', () => {

describe("okta access is displayed according to the user's plan", () => {
it('displays okta access tab if user is on enterprise', async () => {
setup({ planValue: 'users-enterprisem' })
setup({ planValue: Plans.USERS_ENTERPRISEM })

render(<AccountSettingsSideMenu />, {
wrapper: wrapper(),
Expand Down
4 changes: 3 additions & 1 deletion src/pages/AccountSettings/tabs/Access/Access.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { setupServer } from 'msw/node'
import { Suspense } from 'react'
import { MemoryRouter, Route, useLocation } from 'react-router-dom'

import { Plans } from 'shared/utils/billing'

import Access from './Access'

window.confirm = vi.fn(() => true)
Expand Down Expand Up @@ -35,7 +37,7 @@ const mockSignedInUser = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/AccountSettings/tabs/Admin/Admin.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { Plans } from 'shared/utils/billing'

import Admin from './Admin'

vi.mock('./DetailsSection', () => ({ default: () => 'DetailsSection' }))
Expand Down Expand Up @@ -38,7 +40,7 @@ const user = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { MemoryRouter, Route } from 'react-router-dom'

import config from 'config'

import { Plans } from 'shared/utils/billing'

import GithubIntegrationSection from './GithubIntegrationSection'

const server = setupServer()
Expand Down Expand Up @@ -54,11 +56,11 @@ describe('GithubIntegrationSection', () => {
http.get(`/internal/gh/codecov/account-details/`, (info) => {
return HttpResponse.json({
plan: {
marketingName: 'users-basic',
marketingName: Plans.USERS_BASIC,
baseUnitPrice: 12,
benefits: ['Configurable # of users', 'Unlimited repos'],
quantity: 5,
value: 'users-inappm',
value: Plans.USERS_INAPPM,
},
activatedUserCount: 2,
inactiveUserCount: 1,
Expand Down
18 changes: 10 additions & 8 deletions src/pages/DefaultOrgSelector/DefaultOrgSelector.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import config from 'config'

import { SentryBugReporter } from 'sentry'

import { Plans } from 'shared/utils/billing'

import DefaultOrgSelector from './DefaultOrgSelector'

const mocks = vi.hoisted(() => ({
Expand Down Expand Up @@ -38,7 +40,7 @@ const mockTrialData = {
billingRate: 'monthly',
marketingName: 'Users Basic',
monthlyUploadLimit: 250,
value: 'users-basic',
value: Plans.USERS_BASIC,
trialStatus: 'ONGOING',
trialStartDate: '2023-01-01T08:55:25',
trialEndDate: '2023-01-10T08:55:25',
Expand Down Expand Up @@ -72,7 +74,7 @@ const mockUserData = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down Expand Up @@ -116,7 +118,7 @@ const mockBusinessUserData = {
service: 'github',
ownerid: 123,
serviceId: '123',
plan: 'users-basic',
plan: Plans.USERS_BASIC,
staff: false,
hasYaml: false,
bot: null,
Expand Down Expand Up @@ -177,7 +179,7 @@ describe('DefaultOrgSelector', () => {
useUserData,
isValidUser = true,
trialStatus = 'NOT_STARTED',
value = 'users-basic',
value = Plans.USERS_BASIC,
privateRepos = true,
} = {}) {
const mockMutationVariables = vi.fn()
Expand Down Expand Up @@ -218,7 +220,7 @@ describe('DefaultOrgSelector', () => {
billingRate: 'monthly',
marketingName: 'Users Basic',
monthlyUploadLimit: 250,
value: 'users-basic',
value: Plans.USERS_BASIC,
},
},
},
Expand Down Expand Up @@ -822,7 +824,7 @@ describe('DefaultOrgSelector', () => {
it('does not fire trial mutation', async () => {
const { user, mockTrialMutationVariables } = setup({
useUserData: mockUserData,
value: 'users-free',
value: Plans.USERS_FREE,
myOrganizationsData: {
me: {
myOrganizations: {
Expand Down Expand Up @@ -1063,7 +1065,7 @@ describe('DefaultOrgSelector', () => {
},
},
},
value: 'users-basic',
value: Plans.USERS_BASIC,
})

render(<DefaultOrgSelector />, { wrapper: wrapper() })
Expand Down Expand Up @@ -1126,7 +1128,7 @@ describe('DefaultOrgSelector', () => {
},
},
},
value: 'users-basic',
value: Plans.USERS_BASIC,
privateRepos: false,
})

Expand Down
Loading

0 comments on commit 848db44

Please sign in to comment.