Skip to content

Commit

Permalink
rename useModuleFor -> useModuleInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
zburke committed Jan 16, 2025
1 parent 750799a commit 4bb8660
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export { getUserTenantsPermissions } from './src/queries';

/* Hooks */
export { useUserTenantPermissions } from './src/hooks';
export { useModuleFor } from './src/hooks';
export { useModuleInfo } from './src/hooks';

/* misc */
export { supportedLocales } from './src/loginServices';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as useUserTenantPermissions } from './useUserTenantPermissions';
export { default as useModuleFor } from './useModuleFor';
export { default as useModuleInfo } from './useModuleInfo';

6 changes: 3 additions & 3 deletions src/hooks/useModuleFor.js → src/hooks/useModuleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ const canonicalPath = (str) => {
};

/**
* useModuleFor
* useModuleInfo
* Given a path, retrieve information about the module that implements it
* by querying the discovery endpoint /_/proxy/tenants/${tenant}/modules.
*
* @param {string} path
* @returns object shaped like { isFetching, isFetched, isLoading, module }
*/
const useModuleFor = (path) => {
const useModuleInfo = (path) => {
const stripes = useStripes();
const ky = useOkapiKy();
const [namespace] = useNamespace({ key: `/_/proxy/tenants/${stripes.okapi.tenant}/modules` });
Expand Down Expand Up @@ -107,4 +107,4 @@ const useModuleFor = (path) => {
});
};

export default useModuleFor;
export default useModuleInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
QueryClientProvider,
} from 'react-query';

import useModuleFor from './useModuleFor';
import useModuleInfo from './useModuleInfo';
import useOkapiKy from '../useOkapiKy';

const response = [
Expand Down Expand Up @@ -155,7 +155,7 @@ const wrapper = ({ children }) => (
);


describe('useModuleFor', () => {
describe('useModuleInfo', () => {
beforeEach(() => {
useOkapiKy.get = () => ({
json: () => console.log({ response })
Expand All @@ -164,26 +164,26 @@ describe('useModuleFor', () => {

describe('returns the module-name that provides the interface containing a given path', () => {
it('handles paths with leading /', async () => {
const { result } = renderHook(() => useModuleFor('/users'), { wrapper });
const { result } = renderHook(() => useModuleInfo('/users'), { wrapper });
await waitFor(() => result.current.module.name);
expect(result.current.module.name).toEqual('mod-users');
});

it('handles paths without leading /', async () => {
const { result } = renderHook(() => useModuleFor('inventory-reports/items-in-transit'), { wrapper });
const { result } = renderHook(() => useModuleInfo('inventory-reports/items-in-transit'), { wrapper });
await waitFor(() => result.current.module.name);
expect(result.current.module.name).toEqual('mod-circulation');
});

it('ignores query string', async () => {
const { result } = renderHook(() => useModuleFor('/users?query=foo==bar'), { wrapper });
const { result } = renderHook(() => useModuleInfo('/users?query=foo==bar'), { wrapper });
await waitFor(() => result.current.module.name);
expect(result.current.module.name).toEqual('mod-users');
});
});

it('returns undefined given an unmatched path', async () => {
const { result } = renderHook(() => useModuleFor('/monkey-bagel'), { wrapper });
const { result } = renderHook(() => useModuleInfo('/monkey-bagel'), { wrapper });
await waitFor(() => result.current.module);
expect(result.current.module).toBeUndefined();
});
Expand Down

0 comments on commit 4bb8660

Please sign in to comment.