diff --git a/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/index.ts b/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/index.ts deleted file mode 100644 index eaebac66b2..0000000000 --- a/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './useCommitHeaderDataTeam' diff --git a/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/useCommitHeaderDataTeam.test.tsx b/src/pages/CommitDetailPage/Header/HeaderTeam/queries/CommitHeaderDataTeamQueryOpts.test.tsx similarity index 81% rename from src/pages/CommitDetailPage/Header/HeaderTeam/hooks/useCommitHeaderDataTeam.test.tsx rename to src/pages/CommitDetailPage/Header/HeaderTeam/queries/CommitHeaderDataTeamQueryOpts.test.tsx index e9c697e24c..1a703daf80 100644 --- a/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/useCommitHeaderDataTeam.test.tsx +++ b/src/pages/CommitDetailPage/Header/HeaderTeam/queries/CommitHeaderDataTeamQueryOpts.test.tsx @@ -1,9 +1,13 @@ -import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { + QueryClientProvider as QueryClientProviderV5, + QueryClient as QueryClientV5, + useQuery as useQueryV5, +} from '@tanstack/react-queryV5' import { renderHook, waitFor } from '@testing-library/react' import { graphql, HttpResponse } from 'msw' import { setupServer } from 'msw/node' -import { useCommitHeaderDataTeam } from './useCommitHeaderDataTeam' +import { CommitHeaderDataTeamQueryOpts } from './CommitHeaderDataTeamQueryOpts' const mockRepository = { owner: { @@ -54,13 +58,15 @@ const mockNullOwner = { const mockUnsuccessfulParseError = {} -const queryClient = new QueryClient({ - defaultOptions: { queries: { retry: false, useErrorBoundary: false } }, -}) const server = setupServer() +const queryClientV5 = new QueryClientV5({ + defaultOptions: { queries: { retry: false } }, +}) const wrapper: React.FC = ({ children }) => ( - {children} + + {children} + ) beforeAll(() => { @@ -68,7 +74,7 @@ beforeAll(() => { }) afterEach(() => { - queryClient.clear() + queryClientV5.clear() server.resetHandlers() }) @@ -83,7 +89,7 @@ interface SetupArgs { isNullOwner?: boolean } -describe('useCommitHeaderDataTeam', () => { +describe('CommitHeaderDataTeamQueryOpts', () => { function setup({ isNotFoundError = false, isOwnerNotActivatedError = false, @@ -115,12 +121,14 @@ describe('useCommitHeaderDataTeam', () => { const { result } = renderHook( () => - useCommitHeaderDataTeam({ - provider: 'gh', - owner: 'codecov', - repo: 'test-repo', - commitId: 'id-1', - }), + useQueryV5( + CommitHeaderDataTeamQueryOpts({ + provider: 'gh', + owner: 'codecov', + repo: 'test-repo', + commitId: 'id-1', + }) + ), { wrapper } ) @@ -158,12 +166,14 @@ describe('useCommitHeaderDataTeam', () => { const { result } = renderHook( () => - useCommitHeaderDataTeam({ - provider: 'gh', - owner: 'codecov', - repo: 'test-repo', - commitId: 'id-1', - }), + useQueryV5( + CommitHeaderDataTeamQueryOpts({ + provider: 'gh', + owner: 'codecov', + repo: 'test-repo', + commitId: 'id-1', + }) + ), { wrapper } ) @@ -197,12 +207,14 @@ describe('useCommitHeaderDataTeam', () => { const { result } = renderHook( () => - useCommitHeaderDataTeam({ - provider: 'gh', - owner: 'codecov', - repo: 'test-repo', - commitId: 'id-1', - }), + useQueryV5( + CommitHeaderDataTeamQueryOpts({ + provider: 'gh', + owner: 'codecov', + repo: 'test-repo', + commitId: 'id-1', + }) + ), { wrapper } ) @@ -233,12 +245,14 @@ describe('useCommitHeaderDataTeam', () => { const { result } = renderHook( () => - useCommitHeaderDataTeam({ - provider: 'gh', - owner: 'codecov', - repo: 'test-repo', - commitId: 'id-1', - }), + useQueryV5( + CommitHeaderDataTeamQueryOpts({ + provider: 'gh', + owner: 'codecov', + repo: 'test-repo', + commitId: 'id-1', + }) + ), { wrapper } ) @@ -269,12 +283,14 @@ describe('useCommitHeaderDataTeam', () => { const { result } = renderHook( () => - useCommitHeaderDataTeam({ - provider: 'gh', - owner: 'codecov', - repo: 'test-repo', - commitId: 'id-1', - }), + useQueryV5( + CommitHeaderDataTeamQueryOpts({ + provider: 'gh', + owner: 'codecov', + repo: 'test-repo', + commitId: 'id-1', + }) + ), { wrapper } ) diff --git a/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/useCommitHeaderDataTeam.tsx b/src/pages/CommitDetailPage/Header/HeaderTeam/queries/CommitHeaderDataTeamQueryOpts.tsx similarity index 87% rename from src/pages/CommitDetailPage/Header/HeaderTeam/hooks/useCommitHeaderDataTeam.tsx rename to src/pages/CommitDetailPage/Header/HeaderTeam/queries/CommitHeaderDataTeamQueryOpts.tsx index 3a87d968aa..4539d01cc6 100644 --- a/src/pages/CommitDetailPage/Header/HeaderTeam/hooks/useCommitHeaderDataTeam.tsx +++ b/src/pages/CommitDetailPage/Header/HeaderTeam/queries/CommitHeaderDataTeamQueryOpts.tsx @@ -1,4 +1,4 @@ -import { useQuery } from '@tanstack/react-query' +import { queryOptions as queryOptionsV5 } from '@tanstack/react-queryV5' import { z } from 'zod' import { @@ -14,6 +14,7 @@ import { RepoOwnerNotActivatedErrorSchema, } from 'services/repo' import Api from 'shared/api' +import { rejectNetworkError } from 'shared/api/helpers' import A from 'ui/A' const CoverageObjSchema = z.object({ @@ -130,20 +131,20 @@ const query = ` } ` -interface UseCommitHeaderDataTeamArgs { +interface CommitHeaderDataTeamQueryArgs { provider: string owner: string repo: string commitId: string } -export const useCommitHeaderDataTeam = ({ +export const CommitHeaderDataTeamQueryOpts = ({ provider, owner, repo, commitId, -}: UseCommitHeaderDataTeamArgs) => - useQuery({ +}: CommitHeaderDataTeamQueryArgs) => + queryOptionsV5({ queryKey: [ 'CommitPageHeaderDataTeam', provider, @@ -167,23 +168,26 @@ export const useCommitHeaderDataTeam = ({ const parsedData = CommitHeaderDataTeamSchema.safeParse(res?.data) if (!parsedData.success) { - return Promise.reject({ + return rejectNetworkError({ status: 404, data: {}, + dev: 'CommitHeaderDataTeamQueryOpts - 404 Failed to parse schema', + error: parsedData.error, }) } const data = parsedData.data if (data?.owner?.repository?.__typename === 'NotFoundError') { - return Promise.reject({ + return rejectNetworkError({ status: 404, data: {}, + dev: 'CommitHeaderDataTeamQueryOpts - 404 Not Found', }) } if (data?.owner?.repository?.__typename === 'OwnerNotActivatedError') { - return Promise.reject({ + return rejectNetworkError({ status: 403, data: { detail: ( @@ -195,6 +199,7 @@ export const useCommitHeaderDataTeam = ({

), }, + dev: 'CommitHeaderDataTeamQueryOpts - 403 Owner Not Activated', }) }