mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[Enterprise Search] Added a test helper #117948
This commit is contained in:
parent
6f5faf93f0
commit
bde802fed6
36 changed files with 185 additions and 579 deletions
|
@ -5,12 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockKibanaValues,
|
||||
mockHttpValues,
|
||||
mockFlashMessageHelpers,
|
||||
} from '../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockKibanaValues, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
|
||||
jest.mock('../engine', () => ({
|
||||
EngineLogic: { values: { engineName: 'test-engine' } },
|
||||
|
@ -18,6 +13,8 @@ jest.mock('../engine', () => ({
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { DEFAULT_START_DATE, DEFAULT_END_DATE } from './constants';
|
||||
|
||||
import { AnalyticsLogic } from './';
|
||||
|
@ -26,7 +23,6 @@ describe('AnalyticsLogic', () => {
|
|||
const { mount } = new LogicMounter(AnalyticsLogic);
|
||||
const { history } = mockKibanaValues;
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
dataLoading: true,
|
||||
|
@ -197,14 +193,9 @@ describe('AnalyticsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
AnalyticsLogic.actions.loadAnalyticsData();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -259,14 +250,9 @@ describe('AnalyticsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
AnalyticsLogic.actions.loadQueryData('some-query');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,12 +17,14 @@ import { nextTick } from '@kbn/test/jest';
|
|||
|
||||
import { DEFAULT_META } from '../../../shared/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { ApiLogsLogic } from './';
|
||||
|
||||
describe('ApiLogsLogic', () => {
|
||||
const { mount, unmount } = new LogicMounter(ApiLogsLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors, flashErrorToast } = mockFlashMessageHelpers;
|
||||
const { flashErrorToast } = mockFlashMessageHelpers;
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
dataLoading: true,
|
||||
|
@ -176,14 +178,9 @@ describe('ApiLogsLogic', () => {
|
|||
expect(ApiLogsLogic.actions.updateView).toHaveBeenCalledWith(MOCK_API_RESPONSE);
|
||||
});
|
||||
|
||||
it('handles API errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
ApiLogsLogic.actions.fetchApiLogs();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ import { Meta } from '../../../../../common/types';
|
|||
|
||||
import { DEFAULT_META } from '../../../shared/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers/error_handling';
|
||||
|
||||
import { CrawlerDomainsLogic, CrawlerDomainsValues } from './crawler_domains_logic';
|
||||
import { CrawlerDataFromServer, CrawlerDomain, CrawlerDomainFromServer } from './types';
|
||||
import { crawlerDataServerToClient } from './utils';
|
||||
|
@ -193,13 +195,8 @@ describe('CrawlerDomainsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('calls flashApiErrors when there is an error', async () => {
|
||||
http.delete.mockReturnValue(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
CrawlerDomainsLogic.actions.deleteDomain({ id: '1234' } as CrawlerDomain);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,6 +14,8 @@ import '../../__mocks__/engine_logic.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { CrawlerDomainsLogic } from './crawler_domains_logic';
|
||||
import { CrawlerLogic, CrawlerValues } from './crawler_logic';
|
||||
import {
|
||||
|
@ -280,15 +282,8 @@ describe('CrawlerLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('on failure', () => {
|
||||
it('flashes an error message', async () => {
|
||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
CrawlerLogic.actions.startCrawl();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
CrawlerLogic.actions.startCrawl();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -308,16 +303,8 @@ describe('CrawlerLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('on failure', () => {
|
||||
it('flashes an error message', async () => {
|
||||
jest.spyOn(CrawlerLogic.actions, 'fetchCrawlerData');
|
||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
CrawlerLogic.actions.stopCrawl();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
CrawlerLogic.actions.stopCrawl();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ jest.mock('./crawler_logic', () => ({
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { CrawlerLogic } from './crawler_logic';
|
||||
import { CrawlerSingleDomainLogic, CrawlerSingleDomainValues } from './crawler_single_domain_logic';
|
||||
import { CrawlerDomain, CrawlerPolicies, CrawlerRules } from './types';
|
||||
|
@ -35,7 +37,7 @@ const DEFAULT_VALUES: CrawlerSingleDomainValues = {
|
|||
describe('CrawlerSingleDomainLogic', () => {
|
||||
const { mount } = new LogicMounter(CrawlerSingleDomainLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { flashSuccessToast } = mockFlashMessageHelpers;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
@ -176,13 +178,8 @@ describe('CrawlerSingleDomainLogic', () => {
|
|||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/crawler');
|
||||
});
|
||||
|
||||
it('calls flashApiErrors when there is an error', async () => {
|
||||
http.delete.mockReturnValue(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
CrawlerSingleDomainLogic.actions.deleteDomain({ id: '1234' } as CrawlerDomain);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -218,13 +215,8 @@ describe('CrawlerSingleDomainLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('displays any errors to the user', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
CrawlerSingleDomainLogic.actions.fetchDomainData('507f1f77bcf86cd799439011');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -272,16 +264,11 @@ describe('CrawlerSingleDomainLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('displays any errors to the user', async () => {
|
||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
CrawlerSingleDomainLogic.actions.submitDeduplicationUpdate(
|
||||
{ id: '507f1f77bcf86cd799439011' } as CrawlerDomain,
|
||||
{ fields: ['title'], enabled: true }
|
||||
);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@ jest.mock('../../app_logic', () => ({
|
|||
selectors: { myRole: jest.fn(() => ({})) },
|
||||
},
|
||||
}));
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
import { AppLogic } from '../../app_logic';
|
||||
|
||||
import { EngineTypes } from '../engine/types';
|
||||
|
@ -31,7 +32,7 @@ import { CredentialsLogic } from './credentials_logic';
|
|||
describe('CredentialsLogic', () => {
|
||||
const { mount } = new LogicMounter(CredentialsLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { clearFlashMessages, flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;
|
||||
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
activeApiToken: {
|
||||
|
@ -1059,14 +1060,9 @@ describe('CredentialsLogic', () => {
|
|||
expect(CredentialsLogic.actions.setCredentialsData).toHaveBeenCalledWith(meta, results);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
http.get.mockReturnValue(Promise.reject('An error occured'));
|
||||
|
||||
CredentialsLogic.actions.fetchCredentials();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1086,14 +1082,9 @@ describe('CredentialsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
http.get.mockReturnValue(Promise.reject('An error occured'));
|
||||
|
||||
CredentialsLogic.actions.fetchDetails();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1113,14 +1104,9 @@ describe('CredentialsLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
mount();
|
||||
http.delete.mockReturnValue(Promise.reject('An error occured'));
|
||||
|
||||
CredentialsLogic.actions.deleteApiKey(tokenName);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1172,14 +1158,9 @@ describe('CredentialsLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
mount();
|
||||
http.post.mockReturnValue(Promise.reject('An error occured'));
|
||||
|
||||
CredentialsLogic.actions.onApiTokenChange();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
||||
});
|
||||
|
||||
describe('token type data', () => {
|
||||
|
|
|
@ -5,17 +5,15 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockFlashMessageHelpers,
|
||||
mockHttpValues,
|
||||
} from '../../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockHttpValues } from '../../../../__mocks__/kea_logic';
|
||||
import '../../../__mocks__/engine_logic.mock';
|
||||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { DEFAULT_META } from '../../../../shared/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../test_helpers';
|
||||
|
||||
import { SuggestionsAPIResponse, SuggestionsLogic } from './suggestions_logic';
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
|
@ -52,7 +50,6 @@ const MOCK_RESPONSE: SuggestionsAPIResponse = {
|
|||
|
||||
describe('SuggestionsLogic', () => {
|
||||
const { mount } = new LogicMounter(SuggestionsLogic);
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
const { http } = mockHttpValues;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -140,14 +137,9 @@ describe('SuggestionsLogic', () => {
|
|||
expect(SuggestionsLogic.actions.onSuggestionsLoaded).toHaveBeenCalledWith(MOCK_RESPONSE);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
mount();
|
||||
|
||||
SuggestionsLogic.actions.loadSuggestions();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,6 +15,8 @@ import '../../../__mocks__/engine_logic.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../test_helpers';
|
||||
|
||||
import { CurationLogic } from './';
|
||||
|
||||
describe('CurationLogic', () => {
|
||||
|
@ -309,14 +311,8 @@ describe('CurationLogic', () => {
|
|||
expect(CurationLogic.actions.loadCuration).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('flashes any error messages', async () => {
|
||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
||||
mount({ activeQuery: 'some query' });
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
CurationLogic.actions.convertToManual();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -336,14 +332,9 @@ describe('CurationLogic', () => {
|
|||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||
});
|
||||
|
||||
it('flashes any errors', async () => {
|
||||
http.delete.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
mount({}, { curationId: 'cur-404' });
|
||||
|
||||
CurationLogic.actions.deleteCuration();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ import { nextTick } from '@kbn/test/jest';
|
|||
|
||||
import { DEFAULT_META } from '../../../shared/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { CurationsLogic } from './';
|
||||
|
||||
describe('CurationsLogic', () => {
|
||||
|
@ -130,14 +132,9 @@ describe('CurationsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
CurationsLogic.actions.loadCurations();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import '../../../../__mocks__/engine_logic.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||
import { HydratedCurationSuggestion } from '../../types';
|
||||
|
||||
import { CurationSuggestionLogic } from './curation_suggestion_logic';
|
||||
|
@ -180,20 +181,6 @@ describe('CurationSuggestionLogic', () => {
|
|||
});
|
||||
};
|
||||
|
||||
const itHandlesErrors = (httpMethod: any, callback: () => void) => {
|
||||
it('handles errors', async () => {
|
||||
httpMethod.mockReturnValueOnce(Promise.reject('error'));
|
||||
mountLogic({
|
||||
suggestion,
|
||||
});
|
||||
|
||||
callback();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
@ -271,7 +258,7 @@ describe('CurationSuggestionLogic', () => {
|
|||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||
});
|
||||
|
||||
itHandlesErrors(http.get, () => {
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
CurationSuggestionLogic.actions.loadSuggestion();
|
||||
});
|
||||
});
|
||||
|
@ -350,7 +337,8 @@ describe('CurationSuggestionLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
itHandlesErrors(http.put, () => {
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
jest.spyOn(global, 'confirm').mockReturnValueOnce(true);
|
||||
CurationSuggestionLogic.actions.acceptSuggestion();
|
||||
});
|
||||
|
||||
|
@ -433,7 +421,8 @@ describe('CurationSuggestionLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
itHandlesErrors(http.put, () => {
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
jest.spyOn(global, 'confirm').mockReturnValueOnce(true);
|
||||
CurationSuggestionLogic.actions.acceptAndAutomateSuggestion();
|
||||
});
|
||||
|
||||
|
@ -478,7 +467,7 @@ describe('CurationSuggestionLogic', () => {
|
|||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||
});
|
||||
|
||||
itHandlesErrors(http.put, () => {
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
CurationSuggestionLogic.actions.rejectSuggestion();
|
||||
});
|
||||
|
||||
|
@ -523,7 +512,7 @@ describe('CurationSuggestionLogic', () => {
|
|||
expect(navigateToUrl).toHaveBeenCalledWith('/engines/some-engine/curations');
|
||||
});
|
||||
|
||||
itHandlesErrors(http.put, () => {
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
CurationSuggestionLogic.actions.rejectAndDisableSuggestion();
|
||||
});
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@ import {
|
|||
mockHttpValues,
|
||||
} from '../../../../../../../__mocks__/kea_logic';
|
||||
import '../../../../../../__mocks__/engine_logic.mock';
|
||||
import { DEFAULT_META } from '../../../../../../../shared/constants';
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../../../test_helpers';
|
||||
|
||||
// I don't know why eslint is saying this line is out of order
|
||||
// eslint-disable-next-line import/order
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { DEFAULT_META } from '../../../../../../../shared/constants';
|
||||
|
||||
import { IgnoredQueriesLogic } from './ignored_queries_logic';
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
|
@ -142,13 +142,9 @@ describe('IgnoredQueriesLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
mount();
|
||||
IgnoredQueriesLogic.actions.loadIgnoredQueries();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -185,13 +181,9 @@ describe('IgnoredQueriesLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalledWith(expect.any(String));
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
mount();
|
||||
IgnoredQueriesLogic.actions.allowIgnoredQuery('test query');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
|
||||
it('handles inline errors', async () => {
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockHttpValues,
|
||||
mockFlashMessageHelpers,
|
||||
} from '../../../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockHttpValues } from '../../../../../__mocks__/kea_logic';
|
||||
import '../../../../__mocks__/engine_logic.mock';
|
||||
|
||||
jest.mock('../../curations_logic', () => ({
|
||||
|
@ -24,6 +20,7 @@ jest.mock('../../curations_logic', () => ({
|
|||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { CurationsLogic } from '../..';
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||
import { EngineLogic } from '../../../engine';
|
||||
|
||||
import { CurationsSettingsLogic } from './curations_settings_logic';
|
||||
|
@ -39,7 +36,6 @@ const DEFAULT_VALUES = {
|
|||
describe('CurationsSettingsLogic', () => {
|
||||
const { mount } = new LogicMounter(CurationsSettingsLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
@ -105,14 +101,8 @@ describe('CurationsSettingsLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('presents any API errors to the user', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
mount();
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
CurationsSettingsLogic.actions.loadCurationsSettings();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -223,14 +213,8 @@ describe('CurationsSettingsLogic', () => {
|
|||
expect(CurationsLogic.actions.loadCurations).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('presents any API errors to the user', async () => {
|
||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
||||
mount();
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
CurationsSettingsLogic.actions.updateCurationsSetting({});
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,6 +17,8 @@ import { nextTick } from '@kbn/test/jest';
|
|||
|
||||
import { InternalSchemaType } from '../../../shared/schema/types';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { DocumentDetailLogic } from './document_detail_logic';
|
||||
|
||||
describe('DocumentDetailLogic', () => {
|
||||
|
@ -117,14 +119,9 @@ describe('DocumentDetailLogic', () => {
|
|||
await nextTick();
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
mount();
|
||||
http.delete.mockReturnValue(Promise.reject('An error occured'));
|
||||
|
||||
DocumentDetailLogic.actions.deleteDocument('1');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockHttpValues,
|
||||
mockFlashMessageHelpers,
|
||||
} from '../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
|
||||
jest.mock('../engine', () => ({
|
||||
EngineLogic: { values: { engineName: 'some-engine' } },
|
||||
|
@ -17,12 +13,13 @@ jest.mock('../engine', () => ({
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { EngineOverviewLogic } from './';
|
||||
|
||||
describe('EngineOverviewLogic', () => {
|
||||
const { mount } = new LogicMounter(EngineOverviewLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
|
||||
const mockEngineMetrics = {
|
||||
documentCount: 10,
|
||||
|
@ -83,14 +80,9 @@ describe('EngineOverviewLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
http.get.mockReturnValue(Promise.reject('An error occurred'));
|
||||
|
||||
EngineOverviewLogic.actions.loadOverviewMetrics();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occurred');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ import { nextTick } from '@kbn/test/jest';
|
|||
|
||||
import { DEFAULT_META } from '../../../shared/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
import { EngineDetails, EngineTypes } from '../engine/types';
|
||||
|
||||
import { EnginesLogic } from './';
|
||||
|
@ -171,14 +172,9 @@ describe('EnginesLogic', () => {
|
|||
expect(EnginesLogic.actions.onEnginesLoad).toHaveBeenCalledWith(MOCK_ENGINES_API_RESPONSE);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
EnginesLogic.actions.loadEngines();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -203,14 +199,9 @@ describe('EnginesLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
EnginesLogic.actions.loadMetaEngines();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ import { mockEngineValues, mockEngineActions } from '../../__mocks__';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { Boost, BoostOperation, BoostType, FunctionalBoostFunction } from './types';
|
||||
|
||||
import { RelevanceTuningLogic } from './';
|
||||
|
@ -319,14 +321,9 @@ describe('RelevanceTuningLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
RelevanceTuningLogic.actions.initializeRelevanceTuning();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockFlashMessageHelpers,
|
||||
mockHttpValues,
|
||||
} from '../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
import { mockEngineValues } from '../../__mocks__';
|
||||
|
||||
import { omit } from 'lodash';
|
||||
|
@ -18,6 +14,8 @@ import { nextTick } from '@kbn/test/jest';
|
|||
|
||||
import { Schema, SchemaConflicts, SchemaType } from '../../../shared/schema/types';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { ServerFieldResultSettingObject } from './types';
|
||||
|
||||
import { ResultSettingsLogic } from '.';
|
||||
|
@ -508,7 +506,6 @@ describe('ResultSettingsLogic', () => {
|
|||
|
||||
describe('listeners', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
let confirmSpy: jest.SpyInstance;
|
||||
|
||||
beforeAll(() => {
|
||||
|
@ -844,14 +841,9 @@ describe('ResultSettingsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
ResultSettingsLogic.actions.initializeResultSettingsData();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -923,14 +915,9 @@ describe('ResultSettingsLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
mount();
|
||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
ResultSettingsLogic.actions.saveResultSettings();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
|
||||
it('does nothing if the user does not confirm', async () => {
|
||||
|
|
|
@ -23,13 +23,15 @@ import {
|
|||
} from '../../../shared/role_mapping/__mocks__/roles';
|
||||
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { RoleMappingsLogic } from './role_mappings_logic';
|
||||
|
||||
const emptyUser = { username: '', email: '' };
|
||||
|
||||
describe('RoleMappingsLogic', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { mount } = new LogicMounter(RoleMappingsLogic);
|
||||
const DEFAULT_VALUES = {
|
||||
attributes: [],
|
||||
|
@ -391,12 +393,8 @@ describe('RoleMappingsLogic', () => {
|
|||
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
RoleMappingsLogic.actions.enableRoleBasedAccess();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -411,12 +409,8 @@ describe('RoleMappingsLogic', () => {
|
|||
expect(setRoleMappingsDataSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
RoleMappingsLogic.actions.initializeRoleMappings();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
|
||||
it('resets roleMapping state', () => {
|
||||
|
@ -691,13 +685,9 @@ describe('RoleMappingsLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
mount(mappingsServerProps);
|
||||
http.delete.mockReturnValue(Promise.reject('this is an error'));
|
||||
RoleMappingsLogic.actions.handleDeleteMapping(roleMappingId);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -5,23 +5,20 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockFlashMessageHelpers,
|
||||
mockHttpValues,
|
||||
} from '../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
import '../../__mocks__/engine_logic.mock';
|
||||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { SchemaType } from '../../../shared/schema/types';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { SchemaBaseLogic } from './schema_base_logic';
|
||||
|
||||
describe('SchemaBaseLogic', () => {
|
||||
const { mount } = new LogicMounter(SchemaBaseLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
|
||||
const MOCK_SCHEMA = {
|
||||
some_text_field: SchemaType.Text,
|
||||
|
@ -99,14 +96,9 @@ describe('SchemaBaseLogic', () => {
|
|||
expect(SchemaBaseLogic.actions.onSchemaLoad).toHaveBeenCalledWith(MOCK_RESPONSE);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
SchemaBaseLogic.actions.loadSchema();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,6 +14,8 @@ import { mockEngineValues } from '../../__mocks__';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { ActiveField } from './types';
|
||||
|
||||
import { SearchUILogic } from './';
|
||||
|
@ -21,7 +23,7 @@ import { SearchUILogic } from './';
|
|||
describe('SearchUILogic', () => {
|
||||
const { mount } = new LogicMounter(SearchUILogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors, setErrorMessage } = mockFlashMessageHelpers;
|
||||
const { setErrorMessage } = mockFlashMessageHelpers;
|
||||
|
||||
const DEFAULT_VALUES = {
|
||||
dataLoading: true,
|
||||
|
@ -182,14 +184,9 @@ describe('SearchUILogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
SearchUILogic.actions.loadFieldData();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,6 +14,8 @@ import '../../__mocks__/engine_logic.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { SYNONYMS_PAGE_META } from './constants';
|
||||
|
||||
import { SynonymsLogic } from './';
|
||||
|
@ -146,14 +148,9 @@ describe('SynonymsLogic', () => {
|
|||
expect(SynonymsLogic.actions.onSynonymsLoad).toHaveBeenCalledWith(MOCK_SYNONYMS_RESPONSE);
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
mount();
|
||||
|
||||
SynonymsLogic.actions.loadSynonyms();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -5,15 +5,16 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockFlashMessageHelpers, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
import { mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { recursivelyFetchEngines } from './';
|
||||
|
||||
describe('recursivelyFetchEngines', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
|
||||
const MOCK_PAGE_1 = {
|
||||
meta: {
|
||||
|
@ -100,12 +101,7 @@ describe('recursivelyFetchEngines', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.get.mockReturnValueOnce(Promise.reject('error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
recursivelyFetchEngines({ endpoint: '/error', onComplete: MOCK_CALLBACK });
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,6 +13,8 @@ import {
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { GenericEndpointInlineEditableTableLogic } from './generic_endpoint_inline_editable_table_logic';
|
||||
|
||||
describe('GenericEndpointInlineEditableTableLogic', () => {
|
||||
|
@ -119,14 +121,9 @@ describe('GenericEndpointInlineEditableTableLogic', () => {
|
|||
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.post.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
const logic = mountLogic();
|
||||
|
||||
logic.actions.addItem(item, onSuccess);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -167,14 +164,9 @@ describe('GenericEndpointInlineEditableTableLogic', () => {
|
|||
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.delete.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
const logic = mountLogic();
|
||||
|
||||
logic.actions.deleteItem(item, onSuccess);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -221,14 +213,9 @@ describe('GenericEndpointInlineEditableTableLogic', () => {
|
|||
expect(logic.actions.clearLoading).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles errors', async () => {
|
||||
http.put.mockReturnValueOnce(Promise.reject('error'));
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
const logic = mountLogic();
|
||||
|
||||
logic.actions.updateItem(item, onSuccess);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockFlashMessageHelpers } from '../__mocks__/kea_logic';
|
||||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
import { HttpHandler } from 'src/core/public';
|
||||
|
||||
export const itShowsServerErrorAsFlashMessage = (httpMethod: HttpHandler, callback: () => void) => {
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
it('shows any server errors as flash messages', async () => {
|
||||
(httpMethod as jest.Mock).mockReturnValueOnce(Promise.reject('error'));
|
||||
callback();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('error');
|
||||
});
|
||||
};
|
|
@ -21,3 +21,4 @@ export {
|
|||
|
||||
// Misc
|
||||
export { expectedAsyncError } from './expected_async_error';
|
||||
export { itShowsServerErrorAsFlashMessage } from './error_handling';
|
||||
|
|
|
@ -15,6 +15,8 @@ import { sourceConfigData } from '../../../../__mocks__/content_sources.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||
|
||||
jest.mock('../../../../app_logic', () => ({
|
||||
AppLogic: { values: { isOrganization: true } },
|
||||
}));
|
||||
|
@ -413,13 +415,8 @@ describe('AddSourceLogic', () => {
|
|||
expect(setSourceConfigDataSpy).toHaveBeenCalledWith(sourceConfigData);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
AddSourceLogic.actions.getSourceConfigData('github');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -474,13 +471,8 @@ describe('AddSourceLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
AddSourceLogic.actions.getSourceConnectData('github', successCallback);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -506,13 +498,8 @@ describe('AddSourceLogic', () => {
|
|||
expect(setSourceConnectDataSpy).toHaveBeenCalledWith(sourceConnectData);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
AddSourceLogic.actions.getSourceReConnectData('github');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -532,13 +519,8 @@ describe('AddSourceLogic', () => {
|
|||
expect(setPreContentSourceConfigDataSpy).toHaveBeenCalledWith(config);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
AddSourceLogic.actions.getPreContentSourceConfigData();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -601,13 +583,8 @@ describe('AddSourceLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
AddSourceLogic.actions.saveSourceConfig(true);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import { exampleResult } from '../../../../__mocks__/content_sources.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||
|
||||
const contentSource = { id: 'source123' };
|
||||
jest.mock('../../source_logic', () => ({
|
||||
SourceLogic: { values: { contentSource } },
|
||||
|
@ -31,7 +33,7 @@ import { DisplaySettingsLogic, defaultSearchResultConfig } from './display_setti
|
|||
describe('DisplaySettingsLogic', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { navigateToUrl } = mockKibanaValues;
|
||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { mount } = new LogicMounter(DisplaySettingsLogic);
|
||||
|
||||
const { searchResultConfig, exampleDocuments } = exampleResult;
|
||||
|
@ -406,12 +408,8 @@ describe('DisplaySettingsLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
DisplaySettingsLogic.actions.initializeDisplaySettings();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -434,12 +432,8 @@ describe('DisplaySettingsLogic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
DisplaySettingsLogic.actions.setServerData();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ Object.defineProperty(global.window, 'scrollTo', { value: spyScrollTo });
|
|||
import { ADD, UPDATE } from '../../../../../shared/constants/operations';
|
||||
import { defaultErrorMessage } from '../../../../../shared/flash_messages/handle_api_errors';
|
||||
import { SchemaType } from '../../../../../shared/schema/types';
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||
import { AppLogic } from '../../../../app_logic';
|
||||
|
||||
import {
|
||||
|
@ -40,8 +41,7 @@ import { SchemaLogic, dataTypeOptions } from './schema_logic';
|
|||
|
||||
describe('SchemaLogic', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast, setErrorMessage } =
|
||||
mockFlashMessageHelpers;
|
||||
const { clearFlashMessages, flashSuccessToast, setErrorMessage } = mockFlashMessageHelpers;
|
||||
const { mount } = new LogicMounter(SchemaLogic);
|
||||
|
||||
const defaultValues = {
|
||||
|
@ -224,12 +224,8 @@ describe('SchemaLogic', () => {
|
|||
expect(onInitializeSchemaSpy).toHaveBeenCalledWith(serverResponse);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
SchemaLogic.actions.initializeSchema();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -447,12 +443,8 @@ describe('SchemaLogic', () => {
|
|||
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
SchemaLogic.actions.setServerField(schema, UPDATE);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ import { fullContentSources } from '../../../../__mocks__/content_sources.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { expectedAsyncError } from '../../../../../test_helpers';
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../../../test_helpers';
|
||||
|
||||
jest.mock('../../source_logic', () => ({
|
||||
SourceLogic: { actions: { setContentSource: jest.fn() } },
|
||||
|
@ -34,7 +34,7 @@ import {
|
|||
|
||||
describe('SynchronizationLogic', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { navigateToUrl } = mockKibanaValues;
|
||||
const { mount } = new LogicMounter(SynchronizationLogic);
|
||||
const contentSource = fullContentSources[0];
|
||||
|
@ -328,19 +328,8 @@ describe('SynchronizationLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalledWith('Source synchronization settings updated.');
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.patch.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.patch, () => {
|
||||
SynchronizationLogic.actions.updateServerSettings(body);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@ import { expectedAsyncError } from '../../../test_helpers';
|
|||
jest.mock('../../app_logic', () => ({
|
||||
AppLogic: { values: { isOrganization: true } },
|
||||
}));
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
import { AppLogic } from '../../app_logic';
|
||||
|
||||
import { SourceLogic } from './source_logic';
|
||||
|
@ -235,19 +236,8 @@ describe('SourceLogic', () => {
|
|||
expect(onUpdateSummarySpy).toHaveBeenCalledWith(contentSource.summary);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.get.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
SourceLogic.actions.initializeFederatedSummary(contentSource.id);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -295,20 +285,8 @@ describe('SourceLogic', () => {
|
|||
expect(actions.setSearchResults).toHaveBeenCalledWith(searchServerResponse);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.post.mockReturnValue(promise);
|
||||
|
||||
await searchContentSourceDocuments({ sourceId: contentSource.id }, mockBreakpoint);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
searchContentSourceDocuments({ sourceId: contentSource.id }, mockBreakpoint);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -367,19 +345,8 @@ describe('SourceLogic', () => {
|
|||
expect(onUpdateSourceNameSpy).toHaveBeenCalledWith(contentSource.name);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.patch.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.patch, () => {
|
||||
SourceLogic.actions.updateContentSource(contentSource.id, contentSource);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -413,19 +380,8 @@ describe('SourceLogic', () => {
|
|||
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.delete.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
SourceLogic.actions.removeContentSource(contentSource.id);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -441,19 +397,8 @@ describe('SourceLogic', () => {
|
|||
expect(initializeSourceSpy).toHaveBeenCalledWith(contentSource.id);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.post.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
SourceLogic.actions.initializeSourceSynchronization(contentSource.id);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,11 +12,10 @@ import {
|
|||
} from '../../../__mocks__/kea_logic';
|
||||
import { configuredSources, contentSources } from '../../__mocks__/content_sources.mock';
|
||||
|
||||
import { expectedAsyncError } from '../../../test_helpers';
|
||||
|
||||
jest.mock('../../app_logic', () => ({
|
||||
AppLogic: { values: { isOrganization: true } },
|
||||
}));
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
import { AppLogic } from '../../app_logic';
|
||||
|
||||
import { SourcesLogic, fetchSourceStatuses, POLLING_INTERVAL } from './sources_logic';
|
||||
|
@ -185,19 +184,8 @@ describe('SourcesLogic', () => {
|
|||
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/account/sources');
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.get.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
SourcesLogic.actions.initializeSources();
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
|
||||
it('handles early logic unmount gracefully in org context', async () => {
|
||||
|
@ -259,19 +247,8 @@ describe('SourcesLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.put.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
SourcesLogic.actions.setSourceSearchability(id, true);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -367,19 +344,8 @@ describe('SourcesLogic', () => {
|
|||
expect(http.get).toHaveBeenCalledWith('/internal/workplace_search/account/sources/status');
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
const error = {
|
||||
response: {
|
||||
error: 'this is an error',
|
||||
status: 400,
|
||||
},
|
||||
};
|
||||
const promise = Promise.reject(error);
|
||||
http.get.mockReturnValue(promise);
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
fetchSourceStatuses(true, mockBreakpoint);
|
||||
await expectedAsyncError(promise);
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ import { mockGroupValues } from './__mocks__/group_logic.mock';
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
import { GROUPS_PATH } from '../../routes';
|
||||
|
||||
import { GroupLogic } from './group_logic';
|
||||
|
@ -24,8 +25,7 @@ describe('GroupLogic', () => {
|
|||
const { mount } = new LogicMounter(GroupLogic);
|
||||
const { http } = mockHttpValues;
|
||||
const { navigateToUrl } = mockKibanaValues;
|
||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast, setQueuedErrorMessage } =
|
||||
mockFlashMessageHelpers;
|
||||
const { clearFlashMessages, flashSuccessToast, setQueuedErrorMessage } = mockFlashMessageHelpers;
|
||||
|
||||
const group = groups[0];
|
||||
const sourceIds = ['123', '124'];
|
||||
|
@ -222,13 +222,8 @@ describe('GroupLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalledWith('Group "group" was successfully deleted.');
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.delete.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
GroupLogic.actions.deleteGroup();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -253,13 +248,8 @@ describe('GroupLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
GroupLogic.actions.updateGroupName();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -284,13 +274,8 @@ describe('GroupLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
GroupLogic.actions.saveGroupSources();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -322,13 +307,8 @@ describe('GroupLogic', () => {
|
|||
expect(onGroupPrioritiesChangedSpy).toHaveBeenCalledWith(group);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
GroupLogic.actions.saveGroupSourcePrioritization();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import { nextTick } from '@kbn/test/jest';
|
|||
import { JSON_HEADER as headers } from '../../../../../common/constants';
|
||||
import { DEFAULT_META } from '../../../shared/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { GroupsLogic } from './groups_logic';
|
||||
|
||||
// We need to mock out the debounced functionality
|
||||
|
@ -227,13 +229,8 @@ describe('GroupsLogic', () => {
|
|||
expect(onInitializeGroupsSpy).toHaveBeenCalledWith(groupsResponse);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
GroupsLogic.actions.initializeGroups();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -310,13 +307,8 @@ describe('GroupsLogic', () => {
|
|||
expect(setGroupUsersSpy).toHaveBeenCalledWith(users);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
GroupsLogic.actions.fetchGroupUsers('123');
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -336,13 +328,8 @@ describe('GroupsLogic', () => {
|
|||
expect(setNewGroupSpy).toHaveBeenCalledWith(groups[0]);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
GroupsLogic.actions.saveNewGroup();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ import {
|
|||
} from '../../../shared/role_mapping/__mocks__/roles';
|
||||
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { RoleMappingsLogic } from './role_mappings_logic';
|
||||
|
||||
const emptyUser = { username: '', email: '' };
|
||||
|
@ -349,12 +351,8 @@ describe('RoleMappingsLogic', () => {
|
|||
expect(setRoleMappingsSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.post.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.post, () => {
|
||||
RoleMappingsLogic.actions.enableRoleBasedAccess();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -369,12 +367,8 @@ describe('RoleMappingsLogic', () => {
|
|||
expect(setRoleMappingsDataSpy).toHaveBeenCalledWith(mappingsServerProps);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
RoleMappingsLogic.actions.initializeRoleMappings();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
|
||||
it('resets roleMapping state', () => {
|
||||
|
|
|
@ -5,19 +5,16 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
LogicMounter,
|
||||
mockHttpValues,
|
||||
mockFlashMessageHelpers,
|
||||
} from '../../../__mocks__/kea_logic';
|
||||
import { LogicMounter, mockHttpValues } from '../../../__mocks__/kea_logic';
|
||||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
|
||||
import { SecurityLogic } from './security_logic';
|
||||
|
||||
describe('SecurityLogic', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { flashAPIErrors } = mockFlashMessageHelpers;
|
||||
const { mount } = new LogicMounter(SecurityLogic);
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -124,15 +121,8 @@ describe('SecurityLogic', () => {
|
|||
expect(setServerPropsSpy).toHaveBeenCalledWith(serverProps);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
SecurityLogic.actions.initializeSourceRestrictions();
|
||||
try {
|
||||
await nextTick();
|
||||
} catch {
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -150,15 +140,8 @@ describe('SecurityLogic', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.patch.mockReturnValue(Promise.reject('this is an error'));
|
||||
|
||||
itShowsServerErrorAsFlashMessage(http.patch, () => {
|
||||
SecurityLogic.actions.saveSourceRestrictions();
|
||||
try {
|
||||
await nextTick();
|
||||
} catch {
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import { configuredSources, oauthApplication } from '../../__mocks__/content_sou
|
|||
|
||||
import { nextTick } from '@kbn/test/jest';
|
||||
|
||||
import { itShowsServerErrorAsFlashMessage } from '../../../test_helpers';
|
||||
import { ORG_UPDATED_MESSAGE, OAUTH_APP_UPDATED_MESSAGE } from '../../constants';
|
||||
|
||||
import { SettingsLogic } from './settings_logic';
|
||||
|
@ -22,7 +23,7 @@ import { SettingsLogic } from './settings_logic';
|
|||
describe('SettingsLogic', () => {
|
||||
const { http } = mockHttpValues;
|
||||
const { navigateToUrl } = mockKibanaValues;
|
||||
const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { clearFlashMessages, flashSuccessToast } = mockFlashMessageHelpers;
|
||||
const { mount } = new LogicMounter(SettingsLogic);
|
||||
const ORG_NAME = 'myOrg';
|
||||
const defaultValues = {
|
||||
|
@ -127,12 +128,8 @@ describe('SettingsLogic', () => {
|
|||
expect(setServerPropsSpy).toHaveBeenCalledWith(configuredSources);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
SettingsLogic.actions.initializeSettings();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -150,12 +147,8 @@ describe('SettingsLogic', () => {
|
|||
expect(onInitializeConnectorsSpy).toHaveBeenCalledWith(serverProps);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.get.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.get, () => {
|
||||
SettingsLogic.actions.initializeConnectors();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -176,12 +169,8 @@ describe('SettingsLogic', () => {
|
|||
expect(setUpdatedNameSpy).toHaveBeenCalledWith({ organizationName: NAME });
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
SettingsLogic.actions.updateOrgName();
|
||||
|
||||
await nextTick();
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -205,12 +194,8 @@ describe('SettingsLogic', () => {
|
|||
expect(setIconSpy).toHaveBeenCalledWith(ICON);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
SettingsLogic.actions.updateOrgIcon();
|
||||
|
||||
await nextTick();
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -234,12 +219,8 @@ describe('SettingsLogic', () => {
|
|||
expect(setLogoSpy).toHaveBeenCalledWith(LOGO);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
SettingsLogic.actions.updateOrgLogo();
|
||||
|
||||
await nextTick();
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -291,12 +272,8 @@ describe('SettingsLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalledWith(OAUTH_APP_UPDATED_MESSAGE);
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.put.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.put, () => {
|
||||
SettingsLogic.actions.updateOauthApplication();
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -313,12 +290,8 @@ describe('SettingsLogic', () => {
|
|||
expect(flashSuccessToast).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles error', async () => {
|
||||
http.delete.mockReturnValue(Promise.reject('this is an error'));
|
||||
itShowsServerErrorAsFlashMessage(http.delete, () => {
|
||||
SettingsLogic.actions.deleteSourceConfig(SERVICE_TYPE, NAME);
|
||||
await nextTick();
|
||||
|
||||
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue