Skip to content

Commit

Permalink
fix extend jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Feb 7, 2021
1 parent 902e280 commit 911a3a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('Search Sessions Management API', () => {

describe('extend', () => {
beforeEach(() => {
sessionsClient.find = jest.fn().mockImplementation(async () => {
sessionsClient.extend = jest.fn().mockImplementation(async () => {
return {
saved_objects: [
{
Expand All @@ -188,6 +188,20 @@ describe('Search Sessions Management API', () => {
});
await api.sendExtend('my-id', '5d');

expect(sessionsClient.extend).toHaveBeenCalledTimes(1);
expect(mockCoreStart.notifications.toasts.addSuccess).toHaveBeenCalled();
});

test('displays error on reject', async () => {
sessionsClient.extend = jest.fn().mockRejectedValue({});
const api = new SearchSessionsMgmtAPI(sessionsClient, mockConfig, {
urls: mockUrls,
notifications: mockCoreStart.notifications,
application: mockCoreStart.application,
});
await api.sendExtend('my-id', '5d');

expect(sessionsClient.extend).toHaveBeenCalledTimes(1);
expect(mockCoreStart.notifications.toasts.addError).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ export class SearchSessionsMgmtAPI {
}),
});
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);

this.deps.notifications.toasts.addError(err, {
title: i18n.translate('xpack.data.mgmt.searchSessions.api.deletedError', {
defaultMessage: 'Failed to delete the search session!',
Expand All @@ -188,9 +185,6 @@ export class SearchSessionsMgmtAPI {
}),
});
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);

this.deps.notifications.toasts.addError(err, {
title: i18n.translate('xpack.data.mgmt.searchSessions.api.extendError', {
defaultMessage: 'Failed to extend the search session!',
Expand Down

0 comments on commit 911a3a5

Please sign in to comment.