From 407e3a1842698474f532f77c62f9121acef3084d Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Tue, 31 Oct 2023 20:07:25 +0500 Subject: [PATCH] tests: add test coverage and Changelog.md --- CHANGELOG.md | 1 + .../useFetchDonors/useFetchDonors.test.js | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 lib/DonorsList/hooks/useFetchDonors/useFetchDonors.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e1c706..abaf8ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Sort the list of countries based on the current locale. Refs UISACQCOMP-164. * Add `inputType` prop to ``. Refs UISACQCOMP-165. +* View the list of donors. Refs UISACQCOMP-166. ## [5.0.0](https://github.com/folio-org/stripes-acq-components/tree/v5.0.0) (2023-10-12) [Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v4.0.2...v5.0.0) diff --git a/lib/DonorsList/hooks/useFetchDonors/useFetchDonors.test.js b/lib/DonorsList/hooks/useFetchDonors/useFetchDonors.test.js new file mode 100644 index 00000000..c3494842 --- /dev/null +++ b/lib/DonorsList/hooks/useFetchDonors/useFetchDonors.test.js @@ -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 }) => ( + + {children} + +); + +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' } }, + ); + }); +});