From 49b99622dba631ad82c1f179737350fc487da465 Mon Sep 17 00:00:00 2001 From: Priyanka Terala Date: Tue, 17 Dec 2024 13:37:23 +0530 Subject: [PATCH] fix test failures and review comments --- .../RequestsFilters/RequestsFilters.test.js | 10 ++++---- .../routes/RequestsRoute/RequestsRoute.js | 2 +- .../RequestsRoute/RequestsRoute.test.js | 2 +- .../useRetrievalServicePoints.js | 10 ++------ .../useRetrievalServicePoints.test.js | 23 ++++++++----------- 5 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/deprecated/components/RequestsFilters/RequestsFilters.test.js b/src/deprecated/components/RequestsFilters/RequestsFilters.test.js index 35c526ea..58b0f8c9 100644 --- a/src/deprecated/components/RequestsFilters/RequestsFilters.test.js +++ b/src/deprecated/components/RequestsFilters/RequestsFilters.test.js @@ -13,17 +13,17 @@ import { } from '@folio/stripes/smart-components'; import RequestsFilters from './RequestsFilters'; -import { RequestLevelFilter } from './RequestLevelFilter'; -import { PickupServicePointFilter } from './PickupServicePointFilter'; +import { RequestLevelFilter } from '../../../components/RequestsFilters/RequestLevelFilter'; +import { PickupServicePointFilter } from '../../../components/RequestsFilters/PickupServicePointFilter'; import { requestFilterTypes, -} from '../../constants'; +} from '../../../constants'; -jest.mock('./RequestLevelFilter', () => ({ +jest.mock('../../../components/RequestsFilters/RequestLevelFilter', () => ({ RequestLevelFilter: jest.fn((props) => (
)), })); -jest.mock('./PickupServicePointFilter', () => ({ +jest.mock('../../../components/RequestsFilters/PickupServicePointFilter', () => ({ PickupServicePointFilter: jest.fn((props) => (
)), })); jest.mock('@folio/stripes/smart-components', () => ({ diff --git a/src/deprecated/routes/RequestsRoute/RequestsRoute.js b/src/deprecated/routes/RequestsRoute/RequestsRoute.js index e5a4f0a9..f53829f9 100644 --- a/src/deprecated/routes/RequestsRoute/RequestsRoute.js +++ b/src/deprecated/routes/RequestsRoute/RequestsRoute.js @@ -94,7 +94,7 @@ import { import { RequestsFilters, RequestsFiltersConfig, -} from '../../RequestsFilters'; +} from '../../components/RequestsFilters'; import RequestsRouteShortcutsWrapper from '../../../components/RequestsRouteShortcutsWrapper'; import { isReorderableRequest, diff --git a/src/deprecated/routes/RequestsRoute/RequestsRoute.test.js b/src/deprecated/routes/RequestsRoute/RequestsRoute.test.js index 249c442a..51834545 100644 --- a/src/deprecated/routes/RequestsRoute/RequestsRoute.test.js +++ b/src/deprecated/routes/RequestsRoute/RequestsRoute.test.js @@ -155,7 +155,7 @@ jest.mock('../../../components', () => ({ }), PrintContent: jest.fn(({ printContentTestId }) =>
PrintContent
) })); -jest.mock('../..//RequestsFilters/RequestsFilters', () => ({ onClear }) => { +jest.mock('../../components/RequestsFilters/RequestsFilters', () => ({ onClear }) => { return (
RequestsFilter diff --git a/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.js b/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.js index 55dd0d3a..822f476f 100644 --- a/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.js +++ b/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.js @@ -13,7 +13,6 @@ const MAX_RECORDS = 1000; const useRetrievalServicePoints = (params = {}, options = {}) => { const stripes = useStripes(); - const defaultTenantId = stripes.okapi?.tenant; const [namespace] = useNamespace('locations'); const { limit = stripes?.config?.maxUnpagedResourceCount || MAX_RECORDS, @@ -24,11 +23,6 @@ const useRetrievalServicePoints = (params = {}, options = {}) => { tenantId, } = options; const ky = useOkapiKy({ tenant: tenantId }); - const api = ky.extend({ - hooks: { - beforeRequest: [(req) => req.headers.set('X-Okapi-Tenant', tenantId || defaultTenantId)], - }, - }); const searchParams = { limit, query }; const { @@ -39,11 +33,11 @@ const useRetrievalServicePoints = (params = {}, options = {}) => { } = useQuery( [namespace], async ({ signal }) => { - const servicePointsData = await api.get(SERVICE_POINTS_API, { searchParams }) + const servicePointsData = await ky.get(SERVICE_POINTS_API, { searchParams }) .json() .then(({ servicepoints }) => servicepoints); - const locationsData = await api.get(LOCATIONS_API, { searchParams, signal }) + const locationsData = await ky.get(LOCATIONS_API, { searchParams, signal }) .json() .then(({ locations }) => locations); diff --git a/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.test.js b/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.test.js index 64c89d12..ffb1d322 100644 --- a/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.test.js +++ b/src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.test.js @@ -58,22 +58,17 @@ const kyResponseMap = { }; describe('useRetrievalServicePoints', () => { - const setHeaderMock = jest.fn(); - const kyMock = jest.fn(() => ({ - extend: jest.fn(({ hooks: { beforeRequest } }) => { - beforeRequest.forEach(handler => handler({ headers: { set: setHeaderMock } })); - - return { - get: (path) => ({ - json: () => Promise.resolve(kyResponseMap[path]), - }), - }; - }), - })); + const mockUseOkapiKyValue = { + get: jest.fn((path) => ({ + json: () => Promise.resolve(kyResponseMap[path]), + })), + }; + const mockUseOkapiKy = useOkapiKy; beforeEach(() => { - kyMock.mockClear(); - useOkapiKy.mockImplementation(kyMock); + mockUseOkapiKy.mockClear(); + mockUseOkapiKyValue.get.mockClear(); + mockUseOkapiKy.mockReturnValue(mockUseOkapiKyValue); }); it('should fetch retrieval service points', async () => {