-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test coverage and Changelog.md
- Loading branch information
1 parent
cb5be47
commit 407e3a1
Showing
2 changed files
with
50 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
lib/DonorsList/hooks/useFetchDonors/useFetchDonors.test.js
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,49 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { useFetchDonors } from './useFetchDonors'; | ||
|
||
jest.mock('@folio/stripes/core', () => ({ | ||
...jest.requireActual('@folio/stripes/core'), | ||
useOkapiKy: jest.fn(), | ||
})); | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
const org = { id: 'orgId', name: 'VENDOR' }; | ||
|
||
const getMock = jest.fn().mockReturnValue({ | ||
json: () => Promise.resolve(({ organizations: [org], totalRecords: 1 })), | ||
}); | ||
|
||
describe('useDonors', () => { | ||
beforeEach(() => { | ||
getMock.mockClear(); | ||
|
||
useOkapiKy | ||
.mockClear() | ||
.mockReturnValue({ | ||
get: getMock, | ||
}); | ||
}); | ||
|
||
it('should make a get a request with default search params', async () => { | ||
const { result, waitFor } = renderHook(() => useFetchDonors(), { wrapper }); | ||
|
||
await result.current.fetchDonorsMutation({ donorOrganizationIds: ['orgId'] }); | ||
await waitFor(() => !result.current.isLoading); | ||
|
||
expect(getMock).toHaveBeenCalledWith( | ||
'organizations/organizations', | ||
{ 'searchParams': { 'limit': 1000, 'query': 'id==orgId' } }, | ||
); | ||
}); | ||
}); |