-
Notifications
You must be signed in to change notification settings - Fork 17
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
ref: Move useReposBackfilled off Repo Deprecated #2862
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | |
import { renderHook, waitFor } from '@testing-library/react' | ||
import { graphql, rest } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
import React from 'react' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import { | ||
|
@@ -16,7 +17,7 @@ const queryClient = new QueryClient({ | |
}) | ||
|
||
const wrapper = | ||
(initialEntries = '/gh/codecov/test') => | ||
(initialEntries = '/gh/codecov/test'): React.FC<React.PropsWithChildren> => | ||
({ children }) => | ||
( | ||
<MemoryRouter initialEntries={[initialEntries]}> | ||
|
@@ -31,15 +32,20 @@ const wrapper = | |
const server = setupServer() | ||
|
||
beforeAll(() => server.listen()) | ||
afterEach(() => server.resetHandlers()) | ||
afterEach(() => { | ||
queryClient.clear() | ||
server.resetHandlers() | ||
}) | ||
afterAll(() => server.close()) | ||
|
||
console.error = () => {} | ||
|
||
const provider = 'gh' | ||
const owner = 'RulaKhaled' | ||
const repo = 'test' | ||
const owner = 'cool-guy' | ||
const repo = 'cool-repo' | ||
|
||
describe('useRepo', () => { | ||
function setup(apiData) { | ||
function setup(apiData: any) { | ||
server.use( | ||
graphql.query('GetRepo', (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.data(apiData)) | ||
|
@@ -137,7 +143,7 @@ describe('useEraseRepoContent', () => { | |
rest.patch( | ||
`internal/github/codecov/repos/test/erase/`, | ||
(req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json()) | ||
return res(ctx.status(200), ctx.json({})) | ||
} | ||
) | ||
) | ||
|
@@ -154,7 +160,7 @@ describe('useEraseRepoContent', () => { | |
wrapper: wrapper(), | ||
}) | ||
|
||
result.current.mutate(null) | ||
result.current.mutate() | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBeTruthy()) | ||
}) | ||
|
@@ -212,6 +218,7 @@ describe('useUpdateRepo', () => { | |
wrapper: wrapper(), | ||
}) | ||
|
||
// @ts-expect-error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interested as to what's going on here? is it just that the current hook that returns the mutation hasn't been uploaded to TS yet? |
||
result.current.mutate({}) | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBeTruthy()) | ||
|
@@ -224,40 +231,69 @@ describe('useRepoBackfilled', () => { | |
const dataReturned = { | ||
owner: { | ||
repository: { | ||
__typename: 'Repository', | ||
flagsMeasurementsActive: true, | ||
flagsMeasurementsBackfilled: true, | ||
}, | ||
}, | ||
} | ||
|
||
function setup() { | ||
const mockUnsuccessfulParseError = {} | ||
|
||
const mockRepoNotFound = { | ||
owner: { | ||
repository: { | ||
__typename: 'NotFoundError', | ||
message: 'Repository not found', | ||
}, | ||
}, | ||
} | ||
|
||
const mockOwnerNotActivated = { | ||
owner: { | ||
repository: { | ||
__typename: 'OwnerNotActivatedError', | ||
message: 'Owner not activated', | ||
}, | ||
}, | ||
} | ||
|
||
interface SetupArgs { | ||
isNotFoundError?: boolean | ||
isOwnerNotActivatedError?: boolean | ||
isUnsuccessfulParseError?: boolean | ||
} | ||
|
||
function setup({ | ||
isNotFoundError = false, | ||
isOwnerNotActivatedError = false, | ||
isUnsuccessfulParseError = false, | ||
}: SetupArgs) { | ||
server.use( | ||
graphql.query('BackfillFlagMemberships', (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.data(dataReturned)) | ||
if (isNotFoundError) { | ||
return res(ctx.status(200), ctx.data(mockRepoNotFound)) | ||
} else if (isOwnerNotActivatedError) { | ||
return res(ctx.status(200), ctx.data(mockOwnerNotActivated)) | ||
} else if (isUnsuccessfulParseError) { | ||
return res(ctx.status(200), ctx.data(mockUnsuccessfulParseError)) | ||
} else { | ||
return res(ctx.status(200), ctx.data(dataReturned)) | ||
} | ||
}) | ||
) | ||
} | ||
|
||
describe('when called', () => { | ||
beforeEach(() => { | ||
setup() | ||
}) | ||
|
||
describe('when data is loaded', () => { | ||
it('returns the data', async () => { | ||
const { result } = renderHook( | ||
() => | ||
useRepoBackfilled({ | ||
provider: 'gh', | ||
owner: 'owner', | ||
repo: 'another-test', | ||
}), | ||
{ | ||
wrapper: wrapper(), | ||
} | ||
) | ||
setup({}) | ||
const { result } = renderHook(() => useRepoBackfilled(), { | ||
wrapper: wrapper(), | ||
}) | ||
|
||
const expectedResponse = { | ||
__typename: 'Repository', | ||
flagsMeasurementsActive: true, | ||
flagsMeasurementsBackfilled: true, | ||
} | ||
|
@@ -266,5 +302,53 @@ describe('useRepoBackfilled', () => { | |
) | ||
}) | ||
}) | ||
|
||
describe('can throw errors', () => { | ||
it('can return unsuccessful parse error', async () => { | ||
setup({ isUnsuccessfulParseError: true }) | ||
const { result } = renderHook(() => useRepoBackfilled(), { | ||
wrapper: 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(() => useRepoBackfilled(), { | ||
wrapper: 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(() => useRepoBackfilled(), { | ||
wrapper: wrapper(), | ||
}) | ||
|
||
await waitFor(() => expect(result.current.isError).toBeTruthy()) | ||
await waitFor(() => | ||
expect(result.current.error).toEqual( | ||
expect.objectContaining({ | ||
status: 403, | ||
}) | ||
) | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mock this console in a setup, but also reset it after the test is finished, just to ensure that the console is back and running normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep yep! Fixed in 5ef5686