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-3284-R-bugfix #2812

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
UIU-3279 supply tenantId in all useUserTenantRoles queries (#2809)
Supply the `tenantId` argument in all queries. It was present in the
query for a user's roles, but missing from the follow-up join-query that
retrieved those roles' details, and thus returned an empty list unless
the selected-tenant matched that of the currently-authenticated user.

Refs UIU-3279
  • Loading branch information
zburke authored and Terala-Priyanka committed Nov 28, 2024
commit dd892af9090ec8bbe8400b6d7c6d59ae3ae4ef47
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

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

return {
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,
@@ -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),
}));
});
});

@@ -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