-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8aeb8e7
commit 765ea64
Showing
13 changed files
with
235 additions
and
88 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
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,42 @@ | ||
import React from 'react' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
import { MembershipShow, useMembership } from '../useMembership' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { AuthProvider } from 'src/utils/AuthContext' | ||
import { asMock, buildMembershipShow, userIsSignedIn } from 'src/testHelpers' | ||
import { AuthedFetch, useAuthedFetch } from '../../useAuthedFetch' | ||
|
||
jest.mock('../../useAuthedFetch') | ||
|
||
describe('useMembership', () => { | ||
let mockAuthedFetch: AuthedFetch | ||
|
||
beforeEach(() => { | ||
userIsSignedIn() | ||
mockAuthedFetch = jest.fn() | ||
asMock(useAuthedFetch).mockReturnValue(mockAuthedFetch) | ||
}) | ||
|
||
it('queries for the group with the given id', async () => { | ||
const client = new QueryClient() | ||
const membership: MembershipShow = buildMembershipShow() | ||
asMock(mockAuthedFetch).mockResolvedValue({ statusCode: 200, json: { membership } }) | ||
|
||
const { result } = renderHook(() => useMembership(membership.id), { | ||
wrapper: ({ children }) => { | ||
return ( | ||
<QueryClientProvider client={client}> | ||
<AuthProvider>{children}</AuthProvider> | ||
</QueryClientProvider> | ||
) | ||
}, | ||
}) | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toEqual(true)) | ||
expect(mockAuthedFetch).toHaveBeenCalledWith({ | ||
path: `/membership/${membership.id}`, | ||
method: 'GET', | ||
}) | ||
expect(result.current.data).toEqual(membership) | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
src/network/memberships/__tests__/useUserMemberships.test.tsx
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,48 @@ | ||
import React from 'react' | ||
import { renderHook, waitFor } from '@testing-library/react' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { useUserMemberships } from '../useUserMemberships' | ||
import { AuthProvider } from 'src/utils/AuthContext' | ||
import { | ||
asMock, | ||
buildMembershipShow, | ||
buildUserMembershipIndex, | ||
userIsSignedIn, | ||
} from 'src/testHelpers' | ||
import { AuthedFetch, useAuthedFetch } from '../../useAuthedFetch' | ||
|
||
jest.mock('../../useAuthedFetch') | ||
|
||
describe('useMemberships', () => { | ||
let mockAuthedFetch: AuthedFetch | ||
|
||
beforeEach(() => { | ||
userIsSignedIn() | ||
mockAuthedFetch = jest.fn() | ||
asMock(useAuthedFetch).mockReturnValue(mockAuthedFetch) | ||
}) | ||
|
||
it('queries for user memberships', async () => { | ||
const client = new QueryClient() | ||
const membership = buildMembershipShow() | ||
const users = [buildUserMembershipIndex(), buildUserMembershipIndex()] | ||
asMock(mockAuthedFetch).mockResolvedValue({ statusCode: 200, json: { users } }) | ||
|
||
const { result } = renderHook(() => useUserMemberships(membership.id), { | ||
wrapper: ({ children }) => { | ||
return ( | ||
<QueryClientProvider client={client}> | ||
<AuthProvider>{children}</AuthProvider> | ||
</QueryClientProvider> | ||
) | ||
}, | ||
}) | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toEqual(true)) | ||
expect(mockAuthedFetch).toHaveBeenCalledWith({ | ||
path: `/groups/${membership.id}/memberships`, | ||
method: 'GET', | ||
}) | ||
expect(result.current.data).toEqual(users) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './useMemberships' | ||
export * from './useMembership' | ||
export * from './useGroupMemberships' | ||
export * from './useUserMemberships' | ||
export * from './useCreateMembership' | ||
export * from './useDestroyMembership' |
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
Oops, something went wrong.