Skip to content

Commit

Permalink
fix test failures and review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed Dec 17, 2024
1 parent 4d48946 commit 49b9962
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (<div {...props} />)),
}));
jest.mock('./PickupServicePointFilter', () => ({
jest.mock('../../../components/RequestsFilters/PickupServicePointFilter', () => ({
PickupServicePointFilter: jest.fn((props) => (<div {...props} />)),
}));
jest.mock('@folio/stripes/smart-components', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/deprecated/routes/RequestsRoute/RequestsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import {
import {
RequestsFilters,
RequestsFiltersConfig,
} from '../../RequestsFilters';
} from '../../components/RequestsFilters';
import RequestsRouteShortcutsWrapper from '../../../components/RequestsRouteShortcutsWrapper';
import {
isReorderableRequest,
Expand Down
2 changes: 1 addition & 1 deletion src/deprecated/routes/RequestsRoute/RequestsRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jest.mock('../../../components', () => ({
}),
PrintContent: jest.fn(({ printContentTestId }) => <div data-testid={printContentTestId}>PrintContent</div>)
}));
jest.mock('../..//RequestsFilters/RequestsFilters', () => ({ onClear }) => {
jest.mock('../../components/RequestsFilters/RequestsFilters', () => ({ onClear }) => {
return (
<div>
<span>RequestsFilter</span>
Expand Down
10 changes: 2 additions & 8 deletions src/hooks/useRetrievalServicePoints/useRetrievalServicePoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 49b9962

Please sign in to comment.