-
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.
UIMARCAUTH-284: Number of links must not be taken from another tenant. (
#319)
- Loading branch information
1 parent
67a737b
commit 8a346b9
Showing
6 changed files
with
97 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useAuthorityExport'; | ||
export * from './useExportReport'; | ||
export * from './useAuthoritiesDelete'; | ||
export * from './useAuthorityLinksCount'; |
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 @@ | ||
export { default as useAuthorityLinksCount } from './useAuthorityLinksCount'; |
19 changes: 19 additions & 0 deletions
19
src/queries/useAuthorityLinksCount/useAuthorityLinksCount.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,19 @@ | ||
import { useMutation } from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
const useAuthorityLinksCount = () => { | ||
const ky = useOkapiKy(); | ||
|
||
const { data, mutateAsync, isLoading } = useMutation({ | ||
mutationFn: ids => ky.post('links/authorities/bulk/count', { json: { ids } }).json(), | ||
}); | ||
|
||
return { | ||
fetchLinksCount: mutateAsync, | ||
linksCount: data?.links?.[0]?.totalLinks, | ||
isLoading, | ||
}; | ||
}; | ||
|
||
export default useAuthorityLinksCount; |
44 changes: 44 additions & 0 deletions
44
src/queries/useAuthorityLinksCount/useAuthorityLinksCount.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,44 @@ | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
} from 'react-query'; | ||
import { renderHook } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import '../../../test/jest/__mock__'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import useAuthorityLinksCount from './useAuthorityLinksCount'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useLocation: jest.fn(), | ||
})); | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
const mockPost = jest.fn().mockReturnValue({ | ||
json: jest.fn().mockResolvedValue({ links: [] }), | ||
}); | ||
|
||
describe('Given useAuthorityLinksCount', () => { | ||
beforeEach(() => { | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
post: mockPost, | ||
}); | ||
}); | ||
|
||
it('should fetch links count', async () => { | ||
const { result } = renderHook(() => useAuthorityLinksCount(), { wrapper }); | ||
|
||
await result.current.fetchLinksCount(['fakeId']); | ||
|
||
expect(mockPost).toHaveBeenCalledWith('links/authorities/bulk/count', { json: { ids: ['fakeId'] } }); | ||
}); | ||
}); |
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