-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: Convert useCommitErrors to TS and remove repositoryDeprecated (#…
…2847) * init conversion and remove deprecated, testing * fix tests for useCommitErrors * add additional spec * add dev stuff * update test coverage
- Loading branch information
1 parent
8a27276
commit e0b313b
Showing
9 changed files
with
318 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
import { graphql } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import React from 'react' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import { useCommitErrors } from './useCommitErrors' | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => ( | ||
<MemoryRouter initialEntries={['/gh/codecov/codecov-exe/commit/9']}> | ||
<Route path="/:provider/:owner/:repo/commit/:commit"> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
</Route> | ||
</MemoryRouter> | ||
) | ||
|
||
const dataReturned = { | ||
owner: { | ||
repository: { | ||
__typename: 'Repository', | ||
commit: { | ||
yamlErrors: { | ||
edges: [{ node: { errorCode: 'invalid_yaml' } }], | ||
}, | ||
botErrors: { | ||
edges: [{ node: { errorCode: 'repo_bot_invalid' } }], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const mockNotFoundError = { | ||
owner: { | ||
repository: { | ||
__typename: 'NotFoundError', | ||
message: 'commit not found', | ||
}, | ||
}, | ||
} | ||
|
||
const mockOwnerNotActivatedError = { | ||
owner: { | ||
repository: { | ||
__typename: 'OwnerNotActivatedError', | ||
message: 'owner not activated', | ||
}, | ||
}, | ||
} | ||
|
||
const mockUnsuccessfulParseError = {} | ||
|
||
const server = setupServer() | ||
|
||
beforeAll(() => server.listen()) | ||
beforeEach(() => { | ||
server.resetHandlers() | ||
queryClient.clear() | ||
}) | ||
afterAll(() => server.close()) | ||
|
||
describe('useCommitErrors', () => { | ||
function setup({ | ||
isNotFoundError = false, | ||
isOwnerNotActivatedError = false, | ||
isUnsuccessfulParseError = false, | ||
}) { | ||
server.use( | ||
graphql.query(`CommitErrors`, (req, res, ctx) => { | ||
if (isNotFoundError) { | ||
return res(ctx.status(200), ctx.data(mockNotFoundError)) | ||
} else if (isOwnerNotActivatedError) { | ||
return res(ctx.status(200), ctx.data(mockOwnerNotActivatedError)) | ||
} else if (isUnsuccessfulParseError) { | ||
return res(ctx.status(200), ctx.data(mockUnsuccessfulParseError)) | ||
} else { | ||
return res(ctx.status(200), ctx.data(dataReturned)) | ||
} | ||
}) | ||
) | ||
} | ||
|
||
describe('when called and user is authenticated', () => { | ||
beforeEach(() => { | ||
setup({}) | ||
}) | ||
|
||
it('returns commit info', async () => { | ||
const { result } = renderHook(() => useCommitErrors(), { | ||
wrapper, | ||
}) | ||
|
||
await waitFor(() => result.current.isSuccess) | ||
|
||
await waitFor(() => | ||
expect(result.current.data).toEqual({ | ||
botErrors: [{ errorCode: 'repo_bot_invalid' }], | ||
yamlErrors: [{ errorCode: 'invalid_yaml' }], | ||
}) | ||
) | ||
}) | ||
}) | ||
describe('when called but repository errors', () => { | ||
it('can return unsuccessful parse error', async () => { | ||
setup({ isUnsuccessfulParseError: true }) | ||
const { result } = renderHook(() => useCommitErrors(), { | ||
wrapper, | ||
}) | ||
|
||
await waitFor(() => expect(result.current.isError).toBeTruthy()) | ||
await waitFor(() => | ||
expect(result.current.error).toEqual( | ||
expect.objectContaining({ | ||
status: 404, | ||
}) | ||
) | ||
) | ||
}) | ||
it('can return not found error', async () => { | ||
setup({ isNotFoundError: true }) | ||
const { result } = renderHook(() => useCommitErrors(), { | ||
wrapper, | ||
}) | ||
|
||
await waitFor(() => expect(result.current.isError).toBeTruthy()) | ||
await waitFor(() => | ||
expect(result.current.error).toEqual( | ||
expect.objectContaining({ | ||
status: 404, | ||
}) | ||
) | ||
) | ||
}) | ||
it('can return owner not activated error', async () => { | ||
setup({ isOwnerNotActivatedError: true }) | ||
const { result } = renderHook(() => useCommitErrors(), { | ||
wrapper, | ||
}) | ||
|
||
await waitFor(() => expect(result.current.isError).toBeTruthy()) | ||
await waitFor(() => | ||
expect(result.current.error).toEqual( | ||
expect.objectContaining({ | ||
status: 403, | ||
}) | ||
) | ||
) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.