Skip to content

Commit

Permalink
Migrate to new mod-circulation-bff endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed Nov 5, 2024
1 parent 8aea1b7 commit 9019535
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 108 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* Review and cleanup Module Descriptor. Refs UIREQ-1156.
* Add `tlr.settings.get` permission. Refs UIREQ-1169.
* Add `mod-settings.global.read.circulation` permission. Refs UIREQ-1170.
* *BREAKING* Migrate to new `mod-circulation-bff` endpoints. Refs UIREQ-1134.

## [9.1.2] (https://github.com/folio-org/ui-requests/tree/v9.1.2) (2024-09-13)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v9.1.1...v9.1.2)
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"pick-slips": "0.1",
"search-slips": "0.1",
"automated-patron-blocks": "0.1",
"instance-items": "0.1"
"circulation-bff-requests": "1.0"
},
"permissionSets": [
{
Expand All @@ -58,7 +58,7 @@
"subPermissions": [
"circulation.requests.queue.collection.get",
"circulation.requests.queue.reorder.collection.post",
"circulation.requests.allowed-service-points.get",
"circulation-bff.requests.allowed-service-points.get",
"circulation.rules.request-policy.get"
]
},
Expand Down Expand Up @@ -121,18 +121,16 @@
"subPermissions": [
"ui-requests.view",
"automated-patron-blocks.collection.get",
"circulation.requests.item.post",
"circulation.requests.allowed-service-points.get",
"circulation-bff.requests.allowed-service-points.get",
"circulation-storage.requests.item.post",
"circulation-storage.request-preferences.collection.get",
"circulation-storage.staff-slips.collection.get",
"circulation.pick-slips.get",
"circulation.search-slips.get",
"circulation.print-events-entry.item.post",
"inventory-storage.locations.item.get",
"circulation.items-by-instance.get",
"tlr.ecs-tlr-allowed-service-points.get",
"tlr.ecs-tlr.post"
"circulation-bff.requests.search-instances.get",
"circulation-bff.requests.post"
],
"visible": true
},
Expand All @@ -144,7 +142,7 @@
"circulation.pick-slips.get",
"circulation.search-slips.get",
"circulation.requests.item.put",
"circulation.requests.allowed-service-points.get",
"circulation-bff.requests.allowed-service-points.get",
"circulation.print-events-entry.item.post",
"circulation-storage.staff-slips.collection.get",
"circulation-storage.requests.collection.delete",
Expand Down
2 changes: 1 addition & 1 deletion src/ItemsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ ItemsDialog.manifest = {
items: {
type: 'okapi',
records: 'items',
path: 'circulation/items-by-instance',
path: 'circulation-bff/requests/search-instances',
accumulate: true,
fetch: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/MoveRequestManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class MoveRequestManager extends React.Component {
token: stripes.store.getState().okapi.token,
})
};
const url = `${stripes.okapi.url}/circulation/requests/allowed-service-points?requestId=${request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`;
const url = `${stripes.okapi.url}/circulation-bff/requests/allowed-service-points?requestId=${request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`;

this.setState({
isRequestTypesLoading: true,
Expand Down
2 changes: 1 addition & 1 deletion src/MoveRequestManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('MoveRequestManager', () => {
});

it('should trigger fetch with correct argument', () => {
const expectedUrl = `${basicProps.stripes.okapi.url}/circulation/requests/allowed-service-points?requestId=${basicProps.request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`;
const expectedUrl = `${basicProps.stripes.okapi.url}/circulation-bff/requests/allowed-service-points?requestId=${basicProps.request.id}&itemId=${selectedItem.id}&operation=${REQUEST_OPERATIONS.MOVE}`;

expect(global.fetch).toHaveBeenCalledWith(expectedUrl, {});
});
Expand Down
15 changes: 0 additions & 15 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,3 @@ export const SETTINGS_SCOPES = {
export const SETTINGS_KEYS = {
GENERAL_TLR: 'generalTlr',
};

export const REQUEST_ACTION_NAMES = {
CREATE_REQUEST: 'CREATE_REQUEST',
GET_SERVICE_POINTS: 'GET_SERVICE_POINTS',
};

export const SINGLE_TENANT_URLS = {
[REQUEST_ACTION_NAMES.CREATE_REQUEST]: 'circulation/requests',
[REQUEST_ACTION_NAMES.GET_SERVICE_POINTS]: 'circulation/requests/allowed-service-points',
};

export const CENTRAL_TENANT_URLS = {
[REQUEST_ACTION_NAMES.CREATE_REQUEST]: 'tlr/ecs-tlr',
[REQUEST_ACTION_NAMES.GET_SERVICE_POINTS]: 'tlr/allowed-service-points',
};
34 changes: 9 additions & 25 deletions src/routes/RequestsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
isEmpty,
isArray,
size,
unset,
cloneDeep,
} from 'lodash';
import React from 'react';
Expand Down Expand Up @@ -70,8 +69,6 @@ import {
SETTINGS_SCOPES,
SETTINGS_KEYS,
ITEM_QUERIES,
REQUEST_ACTION_NAMES,
CENTRAL_TENANT_URLS,
PRINT_DETAILS_COLUMNS,
RESOURCE_TYPES,
requestFilterTypes,
Expand All @@ -89,7 +86,6 @@ import {
getSelectedSlipDataMulti,
selectedRowsNonPrintable,
getNextSelectedRowsState,
getRequestUrl,
isMultiDataTenant,
} from '../utils';
import packageInfo from '../../package';
Expand Down Expand Up @@ -167,12 +163,12 @@ export const urls = {

query = stringify({ query });

return `circulation/items-by-instance?${query}`;
return `circulation-bff/requests/search-instances?${query}`;
},
instance: (value) => {
const query = stringify({ query: getInstanceQueryString(value) });

return `circulation/items-by-instance?${query}`;
return `circulation-bff/requests/search-instances?${query}`;
},
loan: (value) => {
const query = stringify({ query: `(itemId=="${value}") and status.name==Open` });
Expand Down Expand Up @@ -208,14 +204,12 @@ export const urls = {
instanceId,
requestId,
operation,
}, idType, stripes) => {
const url = getRequestUrl(REQUEST_ACTION_NAMES.GET_SERVICE_POINTS, stripes);

}) => {
if (requestId) {
return `${url}?operation=${operation}&requestId=${requestId}`;
return `circulation-bff/requests/allowed-service-points?operation=${operation}&requestId=${requestId}`;
}

let requestUrl = `${url}?requesterId=${requesterId}&operation=${operation}`;
let requestUrl = `circulation-bff/requests/allowed-service-points?requesterId=${requesterId}&operation=${operation}`;

if (itemId) {
requestUrl = `${requestUrl}&itemId=${itemId}`;
Expand Down Expand Up @@ -369,9 +363,9 @@ class RequestsRoute extends React.Component {
staticFallback: { params: {} },
},
},
ecsTlrRecords: {
circulationRequests: {
type: 'okapi',
path: CENTRAL_TENANT_URLS[REQUEST_ACTION_NAMES.CREATE_REQUEST],
path: 'circulation-bff/requests',
fetch: false,
throwErrors: false,
},
Expand Down Expand Up @@ -514,7 +508,7 @@ class RequestsRoute extends React.Component {
GET: PropTypes.func,
POST: PropTypes.func,
}),
ecsTlrRecords: PropTypes.shape({
circulationRequests: PropTypes.shape({
POST: PropTypes.func,
}),
reportRecords: PropTypes.shape({
Expand Down Expand Up @@ -1109,21 +1103,11 @@ class RequestsRoute extends React.Component {
};

create = (requestData) => {
const { stripes } = this.props;
const userPersonalData = cloneDeep(requestData?.requester?.personal);
let mutator = this.props.mutator.records;

if (isMultiDataTenant(stripes) && checkIfUserInCentralTenant(stripes)) {
unset(requestData, 'item');
unset(requestData, 'requester');

mutator = this.props.mutator.ecsTlrRecords;
}

const query = new URLSearchParams(this.props.location.search);
const mode = query.get('mode');

return mutator.POST(requestData)
return this.props.mutator.circulationRequests.POST(requestData)
.then((res) => {
const {
match: {
Expand Down
22 changes: 11 additions & 11 deletions src/routes/RequestsRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ const testIds = {
rowCheckbox: 'rowCheckbox',
selectRequestCheckbox: 'selectRequestCheckbox',
};
const requestUrl = 'url';

const intlCache = createIntlCache();
const intl = createIntl(
{
Expand Down Expand Up @@ -117,7 +115,6 @@ jest.mock('../utils', () => ({
extractPickSlipRequestIds: jest.fn(),
isMultiDataTenant: jest.fn(),
generateUserName: jest.fn(),
getRequestUrl: jest.fn(() => requestUrl),
}));
jest.mock('./utils', () => ({
...jest.requireActual('./utils'),
Expand Down Expand Up @@ -444,6 +441,9 @@ describe('RequestsRoute', () => {
GET: jest.fn(),
POST: jest.fn().mockResolvedValue(),
},
circulationRequests: {
POST: jest.fn().mockResolvedValue(),
},
reportRecords: {
GET: jest.fn().mockReturnValueOnce(mockRecordValues).mockRejectedValue(),
reset: jest.fn(),
Expand Down Expand Up @@ -704,8 +704,7 @@ describe('RequestsRoute', () => {
...defaultProps,
mutator: {
...defaultProps.mutator,
records: {
...defaultProps.mutator.records,
circulationRequests: {
POST: jest.fn().mockResolvedValue(response),
},
},
Expand All @@ -721,7 +720,7 @@ describe('RequestsRoute', () => {

fireEvent.click(createRequestButton);

expect(props.mutator.records.POST).toHaveBeenCalledWith(userData);
expect(props.mutator.circulationRequests.POST).toHaveBeenCalledWith(userData);
});

it('should redirect to details page', async () => {
Expand Down Expand Up @@ -756,7 +755,7 @@ describe('RequestsRoute', () => {
...defaultProps,
mutator: {
...defaultProps.mutator,
ecsTlrRecords: {
circulationRequests: {
POST: jest.fn().mockResolvedValue(response),
},
},
Expand Down Expand Up @@ -801,7 +800,7 @@ describe('RequestsRoute', () => {

fireEvent.click(createRequestButton);

expect(props.mutator.ecsTlrRecords.POST).toHaveBeenCalledWith(userData);
expect(props.mutator.circulationRequests.POST).toHaveBeenCalledWith(userData);
});
});

Expand Down Expand Up @@ -1662,7 +1661,7 @@ describe('RequestsRoute', () => {
});

it('should return correct url', () => {
const expectedResult = `circulation/items-by-instance?${mockedQueryValue}`;
const expectedResult = `circulation-bff/requests/search-instances?${mockedQueryValue}`;

expect(queryString).toBe(expectedResult);
});
Expand All @@ -1685,7 +1684,7 @@ describe('RequestsRoute', () => {
});

it('should return correct url', () => {
const expectedResult = `circulation/items-by-instance?${mockedQueryValue}`;
const expectedResult = `circulation-bff/requests/search-instances?${mockedQueryValue}`;

expect(queryString).toBe(expectedResult);
});
Expand Down Expand Up @@ -1715,7 +1714,7 @@ describe('RequestsRoute', () => {
});

it('should return correct url', () => {
const expectedResult = `circulation/items-by-instance?${mockedQueryValue}`;
const expectedResult = `circulation-bff/requests/search-instances?${mockedQueryValue}`;

expect(queryString).toBe(expectedResult);
});
Expand Down Expand Up @@ -1832,6 +1831,7 @@ describe('RequestsRoute', () => {
const operation = REQUEST_OPERATIONS.CREATE;
const itemId = 'itemIdUrl';
const instanceId = 'instanceIdUrl';
const requestUrl = 'circulation-bff/requests/allowed-service-points';

it('should return url with "itemId"', () => {
const expectedResult = `${requestUrl}?requesterId=${requesterId}&operation=${operation}&itemId=${itemId}`;
Expand Down
14 changes: 0 additions & 14 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
Row,
NoValue,
} from '@folio/stripes/components';
import { checkIfUserInCentralTenant } from '@folio/stripes/core';

import {
requestTypeOptionMap,
Expand All @@ -38,8 +37,6 @@ import {
DCB_USER,
SLIPS_TYPE,
REQUEST_ERROR_MESSAGE_TRANSLATION_KEYS,
CENTRAL_TENANT_URLS,
SINGLE_TENANT_URLS,
} from './constants';

import css from './requests.css';
Expand Down Expand Up @@ -531,14 +528,3 @@ export const getRequester = (proxy, selectedUser) => {

return selectedUser;
};

export const getRequestUrl = (actionName, stripes) => {
const isMultiTenant = isMultiDataTenant(stripes);
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

if (isMultiTenant && isUserInCentralTenant) {
return CENTRAL_TENANT_URLS[actionName];
}

return SINGLE_TENANT_URLS[actionName];
};
32 changes: 0 additions & 32 deletions src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
noop,
} from 'lodash';

import { checkIfUserInCentralTenant } from '@folio/stripes/core';

import {
buildTemplate,
createUserHighlightBoxLink,
Expand Down Expand Up @@ -37,7 +35,6 @@ import {
isPrintable,
getNextSelectedRowsState,
isMultiDataTenant,
getRequestUrl,
getRequester,
getFullName,
} from './utils';
Expand Down Expand Up @@ -1130,35 +1127,6 @@ describe('isMultiDataTenant', () => {
});
});

describe('getRequestUrl', () => {
describe('When central tenant is selected', () => {
const stripes = {
hasInterface: () => true,
};

checkIfUserInCentralTenant.mockReturnValueOnce(true);

it('should return url for central tenant env', () => {
const url = getRequestUrl(REQUEST_ACTION_NAMES.CREATE_REQUEST, stripes);

expect(url).toEqual(CENTRAL_TENANT_URLS[REQUEST_ACTION_NAMES.CREATE_REQUEST]);
});
});

describe('When single tenant env', () => {
const stripes = {
hasInterface: () => false,
};
checkIfUserInCentralTenant.mockReturnValueOnce(false);

it('should return url for multi tenant env', () => {
const url = getRequestUrl(REQUEST_ACTION_NAMES.CREATE_REQUEST, stripes);

expect(url).toEqual(SINGLE_TENANT_URLS[REQUEST_ACTION_NAMES.CREATE_REQUEST]);
});
});
});

describe('getRequester', () => {
const selectedUser = {
id: 'selectedUserId',
Expand Down

0 comments on commit 9019535

Please sign in to comment.