Skip to content

Commit

Permalink
Use new URL
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonStoltz committed Oct 18, 2021
1 parent e9a0c3c commit 2b801a8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const MOCK_RESPONSE = {

describe('CurationSuggestionLogic', () => {
const { mount } = new LogicMounter(CurationSuggestionLogic);
const { flashAPIErrors } = mockFlashMessageHelpers;
const { flashAPIErrors, setQueuedErrorMessage } = mockFlashMessageHelpers;
const { navigateToUrl } = mockKibanaValues;

const mountLogic = (props: object = {}) => {
Expand Down Expand Up @@ -233,14 +233,14 @@ describe('CurationSuggestionLogic', () => {
});

it('should make API calls to fetch data and trigger onSuggestionLoaded', async () => {
http.post.mockReturnValueOnce(Promise.resolve(MOCK_RESPONSE));
http.get.mockReturnValueOnce(Promise.resolve(MOCK_RESPONSE));
mountLogic();
jest.spyOn(CurationSuggestionLogic.actions, 'onSuggestionLoaded');

CurationSuggestionLogic.actions.loadSuggestion();
await nextTick();

expect(http.post).toHaveBeenCalledWith(
expect(http.get).toHaveBeenCalledWith(
'/internal/app_search/engines/some-engine/search_relevance_suggestions/foo-query',
{
query: {
Expand All @@ -254,21 +254,24 @@ describe('CurationSuggestionLogic', () => {
});
});

it.todo('will redirect if the suggestion is not found');
// TODO
// This could happen if a user applies a suggestion and then navigates back to a detail page via
// the back button, etc. The suggestion still exists, it's just not in a "pending" state
// so we can show it.ga
// it('will redirect if the suggestion is not found', async () => {
// http.post.mockReturnValueOnce(Promise.resolve(set('results', [], MOCK_RESPONSE)));
// mountLogic();
// CurationSuggestionLogic.actions.loadSuggestion();
// await nextTick();
// expect(setQueuedErrorMessage).toHaveBeenCalled();
// expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
// });

itHandlesErrors(http.post, () => {
it('will redirect if the suggestion is not found', async () => {
http.get.mockReturnValueOnce(
Promise.reject({
response: { status: 404 },
})
);

mountLogic();
CurationSuggestionLogic.actions.loadSuggestion();
await nextTick();
expect(setQueuedErrorMessage).toHaveBeenCalled();
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
});

itHandlesErrors(http.get, () => {
CurationSuggestionLogic.actions.loadSuggestion();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { HttpSetup } from 'kibana/public';

import { i18n } from '@kbn/i18n';

import { flashAPIErrors, setQueuedSuccessMessage } from '../../../../../shared/flash_messages';
import {
flashAPIErrors,
setQueuedErrorMessage,
setQueuedSuccessMessage,
} from '../../../../../shared/flash_messages';
import { HttpLogic } from '../../../../../shared/http';
import { KibanaLogic } from '../../../../../shared/kibana';
import { ENGINE_CURATIONS_PATH, ENGINE_CURATION_PATH } from '../../../../routes';
Expand Down Expand Up @@ -75,7 +79,7 @@ export const CurationSuggestionLogic = kea<
const { engineName } = EngineLogic.values;

try {
const suggestionResponse = await http.post(
const suggestionResponse = await http.get(
`/internal/app_search/engines/${engineName}/search_relevance_suggestions/${props.query}`,
{
query: {
Expand All @@ -97,7 +101,19 @@ export const CurationSuggestionLogic = kea<
suggestion: suggestionData,
});
} catch (e) {
flashAPIErrors(e);
if (e.response?.status === 404) {
const message = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.curations.suggestedCuration.notFoundError',
{
defaultMessage:
'Could not find suggestion, it may have already been applied or rejected.',
}
);
setQueuedErrorMessage(message);
KibanaLogic.values.navigateToUrl(generateEnginePath(ENGINE_CURATIONS_PATH));
} else {
flashAPIErrors(e);
}
}
},
acceptSuggestion: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ describe('search relevance insights routes', () => {
});
});

describe('POST /internal/app_search/engines/{name}/search_relevance_suggestions/{query}', () => {
describe('GET /internal/app_search/engines/{engineName}/search_relevance_suggestions/{query}', () => {
const mockRouter = new MockRouter({
method: 'post',
method: 'get',
path: '/internal/app_search/engines/{engineName}/search_relevance_suggestions/{query}',
});

Expand All @@ -129,16 +129,15 @@ describe('search relevance insights routes', () => {
});
});

it.todo('creates a request to enterprise search');
// it('creates a request to enterprise search', () => {
// mockRouter.callRoute({
// params: { engineName: 'some-engine', query: 'foo' },
// query: { type: 'curation' },
// });

// expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
// path: '/as/engines/:engineName/search_relevance_suggestions/:query',
// });
// });
it('creates a request to enterprise search', () => {
mockRouter.callRoute({
params: { engineName: 'some-engine', query: 'foo' },
query: { type: 'curation' },
});

expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
path: '/as/engines/:engineName/search_relevance_suggestions/:query',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function registerSearchRelevanceSuggestionsRoutes({
})
);

router.post(
router.get(
{
path: '/internal/app_search/engines/{engineName}/search_relevance_suggestions/{query}',
validate: {
Expand All @@ -94,74 +94,8 @@ export function registerSearchRelevanceSuggestionsRoutes({
}),
},
},
// enterpriseSearchRequestHandler.createRequest({
// path: '/as/engines/:engineName/search_relevance_suggestions/:query',
// })
(_context, request, response) => {
return response.custom({
statusCode: 200,
body: {
query: 'foo',
status: 'pending',
updated_at: '2021-07-08T14:35:50Z',
operation: 'create',
suggestion: {
promoted: [
{
id: '1',
},
{
id: '2',
},
{
id: '3',
},
],
organic: [
{
id: {
raw: '1',
},
_meta: {
id: '1',
engine: 'some-engine',
},
},
{
id: {
raw: '2',
},
_meta: {
id: '2',
engine: 'some-engine',
},
},
],
},
curation: {
id: 'cur-6155e69c7a2f2e4f756303fd',
queries: ['foo'],
promoted: [
{
id: '5',
},
],
hidden: [],
last_updated: 'September 30, 2021 at 04:32PM',
organic: [
{
id: {
raw: '1',
},
_meta: {
id: '1',
engine: 'some-engine',
},
},
],
},
},
});
}
enterpriseSearchRequestHandler.createRequest({
path: '/as/engines/:engineName/search_relevance_suggestions/:query',
})
);
}

0 comments on commit 2b801a8

Please sign in to comment.