Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPimSearchStatus: () =>
dispatch(
// TODO this should be sdkActions.head()
// and then we should check whether the response code is
// - 200 meaning the project is indexed
// - 404 meaning the project is not indexed
//
// But there is a problem in tne node-sdk client as it tries to
// .json()-parse the response to HEAD requests which results in an
// error, so we send a regular request for now and limit to no results
// instead to keep the payload minimal
sdkActions.post({
uri: `/${ownProps.applicationContext.project.key}/search/products`,
mcApiProxyTarget: MC_API_PROXY_TARGETS.PIM_SEARCH,
payload: {
query: {
fullText: {
field: 'name',
language: ownProps.applicationContext.dataLocale,
value: 'availability-check',
},
},
limit: 0,
offset: 0,
},
})
).then(
() => pimIndexerStates.INDEXED,
// project is not using pim-indexer when response error code is 404,
// but we treat all errors as non-indexed as a safe guard, so we're
const createPimAvailabilityCheckSdkMock = (projectDataLocale = 'en') => ({
action: {
type: 'SDK',
payload: {
method: 'POST',
uri: '/test-with-big-data/search/products',
mcApiProxyTarget: MC_API_PROXY_TARGETS.PIM_SEARCH,
payload: {
query: {
fullText: {
field: 'name',
language: projectDataLocale,
value: 'availability-check',
},
},
limit: 0,
offset: 0,
},
},
},
response: {},
});
},
},
},
];
const rendered = renderAppWithRedux(, {
permissions: managePermissions,
mocks,
sdkMocks: [
createPimAvailabilityCheckSdkMock(),
{
action: {
type: 'SDK',
payload: {
method: 'POST',
uri: '/test-with-big-data/search/products',
mcApiProxyTarget: MC_API_PROXY_TARGETS.PIM_SEARCH,
payload: {
query: {
fullText: {
field: 'name',
language: 'en',
value: searchText,
},
},
sort: [{ field: 'name', language: 'en', order: 'desc' }],
limit: 9,
offset: 0,
},
},
},
response: {
total: 1,
pimSearchProductIds: searchText =>
dispatch(
sdkActions.post({
uri: `/${ownProps.applicationContext.project.key}/search/products`,
mcApiProxyTarget: MC_API_PROXY_TARGETS.PIM_SEARCH,
payload: {
query: {
fullText: {
field: 'name',
language: ownProps.applicationContext.dataLocale,
value: searchText,
},
},
sort: [
{
field: 'name',
language: ownProps.applicationContext.dataLocale,
order: 'desc',
},
],
limit: 9,