Skip to content
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

UIU-3279 supply tenantId in all useUserTenantRoles queries #2809

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [11.1.0] In progress
* Update permissions for mod-patron. Ref UIU-3259
* `useUserTenantRoles` supplies `tenantId` in all its queries. Refs UIU-3279.

* Leverage API supported sorting of columns on pre-registrations records list. Refs UIU-3249.

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useUserTenantRoles/useUserTenantRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const useUserTenantRoles = (
ids,
queryEnabled: isSuccess,
reduceFunction: chunkedRolesReducer,
tenantId,
});

return {
Expand Down
80 changes: 9 additions & 71 deletions src/hooks/useUserTenantRoles/useUserTenantRoles.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryClient, QueryClientProvider } from 'react-query';
import { act, renderHook } from '@folio/jest-config-stripes/testing-library/react';

import { renderHook } from '@folio/jest-config-stripes/testing-library/react';
import { act } from 'react';
import {
useChunkedCQLFetch,
useOkapiKy,
Expand Down Expand Up @@ -73,11 +73,17 @@ describe('useUserTenantRoles', () => {
});

it('fetches roles assigned to a user', async () => {
const { result } = renderHook(() => useUserTenantRoles({ userId: 'u', tenantId: 't' }), { wrapper });
const props = { userId: 'u', tenantId: 't' };
const { result } = renderHook(() => useUserTenantRoles(props), { wrapper });
await act(() => !result.current.isFetching);

expect(result.current.isLoading).toBe(false);
expect(result.current.userRoles).toEqual(roleData);
expect(useChunkedCQLFetch).toHaveBeenCalledWith(expect.objectContaining({
tenantId: props.tenantId,
ids: expect.any(Array),
reduceFunction: expect.any(Function),
}));
});
});

Expand All @@ -92,71 +98,3 @@ describe('chunkedRolesReducer', () => {
expect(result.length).toBe(6);
});
});



// import { renderHook, waitFor } from '@folio/jest-config-stripes/testing-library/react';
// import {
// QueryClient,
// QueryClientProvider,
// } from 'react-query';

// import { useOkapiKy, useStripes } from '@folio/stripes/core';

// import roles from 'fixtures/roles';
// import useUserTenantRoles from './useUserTenantRoles';

// const queryClient = new QueryClient();

// // eslint-disable-next-line react/prop-types
// const wrapper = ({ children }) => (
// <QueryClientProvider client={queryClient}>
// {children}
// </QueryClientProvider>
// );

// const response = {
// roles,
// totalRecords: roles.length,
// };

// describe('useUserTenantRoles', () => {
// const getMock = jest.fn(() => ({
// json: () => Promise.resolve(response),
// }));
// const setHeaderMock = jest.fn();
// const kyMock = {
// extend: jest.fn(({ hooks: { beforeRequest } }) => {
// beforeRequest.forEach(handler => handler({ headers: { set: setHeaderMock } }));

// return {
// get: getMock,
// };
// }),
// };

// beforeEach(() => {
// getMock.mockClear();

// useStripes.mockClear().mockReturnValue({
// okapi: {},
// config: {
// maxUnpagedResourceCount: 1000,
// }
// });
// useOkapiKy.mockClear().mockReturnValue(kyMock);
// });

// it('should fetch user roles for specified tenant', async () => {
// const options = {
// userId: 'userId',
// tenantId: 'tenantId',
// };
// const { result } = renderHook(() => useUserTenantRoles(options), { wrapper });

// await waitFor(() => !result.current.isLoading);

// expect(setHeaderMock).toHaveBeenCalledWith('X-Okapi-Tenant', options.tenantId);
// expect(getMock).toHaveBeenCalledWith('roles/users', expect.objectContaining({}));
// });
// });
Loading