From 1c3ee1558cbff11ac6456a4129d95b18f79bd7d6 Mon Sep 17 00:00:00 2001 From: stephmilovic Date: Tue, 14 Apr 2020 10:28:05 -0600 Subject: [PATCH] pr changes --- .../siem/public/containers/case/api.test.tsx | 65 ++++++++++++++++++- .../containers/case/use_delete_cases.test.tsx | 14 ++-- .../containers/case/use_delete_cases.tsx | 6 +- .../case/use_get_action_license.test.tsx | 2 +- 4 files changed, 75 insertions(+), 12 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/containers/case/api.test.tsx b/x-pack/legacy/plugins/siem/public/containers/case/api.test.tsx index a6bc497c5a2dc..4f5655cc9f221 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/api.test.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/api.test.tsx @@ -36,6 +36,7 @@ import { caseUserActions, pushedCase, pushSnake, + reporters, respReporters, serviceConnector, casePushParams, @@ -45,6 +46,7 @@ import { } from './mock'; import { CASES_URL } from './constants'; import { DEFAULT_FILTER_OPTIONS, DEFAULT_QUERY_PARAMS } from './use_get_cases'; +import * as i18n from './translations'; const abortCtrl = new AbortController(); const mockKibanaServices = KibanaServices.get as jest.Mock; @@ -57,7 +59,7 @@ describe('Case Configuration API', () => { describe('deleteCases', () => { beforeEach(() => { fetchMock.mockClear(); - fetchMock.mockResolvedValue('true'); + fetchMock.mockResolvedValue(''); }); const data = ['1', '2']; @@ -72,7 +74,7 @@ describe('Case Configuration API', () => { test('happy path', async () => { const resp = await deleteCases(data, abortCtrl.signal); - expect(resp).toEqual('true'); + expect(resp).toEqual(''); }); }); describe('getActionLicense', () => { @@ -136,6 +138,29 @@ describe('Case Configuration API', () => { signal: abortCtrl.signal, }); }); + test('correctly applies filters', async () => { + await getCases({ + filterOptions: { + ...DEFAULT_FILTER_OPTIONS, + reporters: [...respReporters, { username: null, full_name: null, email: null }], + tags, + status: '', + search: 'hello', + }, + queryParams: DEFAULT_QUERY_PARAMS, + signal: abortCtrl.signal, + }); + expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/_find`, { + method: 'GET', + query: { + ...DEFAULT_QUERY_PARAMS, + reporters, + tags, + search: 'hello', + }, + signal: abortCtrl.signal, + }); + }); test('happy path', async () => { const resp = await getCases({ @@ -398,5 +423,41 @@ describe('Case Configuration API', () => { const resp = await pushToService(connectorId, casePushParams, abortCtrl.signal); expect(resp).toEqual(serviceConnector); }); + + test('unhappy path - serviceMessage', async () => { + const theError = 'the error'; + fetchMock.mockResolvedValue({ + ...actionTypeExecutorResult, + status: 'error', + serviceMessage: theError, + message: 'not it', + }); + await expect( + pushToService(connectorId, casePushParams, abortCtrl.signal) + ).rejects.toMatchObject({ message: theError }); + }); + + test('unhappy path - message', async () => { + const theError = 'the error'; + fetchMock.mockResolvedValue({ + ...actionTypeExecutorResult, + status: 'error', + message: theError, + }); + await expect( + pushToService(connectorId, casePushParams, abortCtrl.signal) + ).rejects.toMatchObject({ message: theError }); + }); + + test('unhappy path - no message', async () => { + const theError = i18n.ERROR_PUSH_TO_SERVICE; + fetchMock.mockResolvedValue({ + ...actionTypeExecutorResult, + status: 'error', + }); + await expect( + pushToService(connectorId, casePushParams, abortCtrl.signal) + ).rejects.toMatchObject({ message: theError }); + }); }); }); diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.test.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.test.tsx index 5ef70b237cbdc..45ba392f3b5b4 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.test.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.test.tsx @@ -12,6 +12,8 @@ jest.mock('./api'); describe('useDeleteCases', () => { const abortCtrl = new AbortController(); + const deleteObj = [{ id: '1' }, { id: '2' }, { id: '3' }]; + const deleteArr = ['1', '2', '3']; it('init', async () => { await act(async () => { const { result, waitForNextUpdate } = renderHook(() => @@ -39,9 +41,9 @@ describe('useDeleteCases', () => { ); await waitForNextUpdate(); - result.current.handleOnDeleteConfirm([{ id: '1' }, { id: '2' }, { id: '3' }]); + result.current.handleOnDeleteConfirm(deleteObj); await waitForNextUpdate(); - expect(spyOnDeleteCases).toBeCalledWith(['1', '2', '3'], abortCtrl.signal); + expect(spyOnDeleteCases).toBeCalledWith(deleteArr, abortCtrl.signal); }); }); @@ -52,7 +54,7 @@ describe('useDeleteCases', () => { ); await waitForNextUpdate(); result.current.handleToggleModal(); - result.current.handleOnDeleteConfirm([{ id: '1' }, { id: '2' }, { id: '3' }]); + result.current.handleOnDeleteConfirm(deleteObj); await waitForNextUpdate(); expect(result.current).toEqual({ isDisplayConfirmDeleteModal: false, @@ -73,7 +75,7 @@ describe('useDeleteCases', () => { ); await waitForNextUpdate(); result.current.handleToggleModal(); - result.current.handleOnDeleteConfirm([{ id: '1' }, { id: '2' }, { id: '3' }]); + result.current.handleOnDeleteConfirm(deleteObj); await waitForNextUpdate(); expect(result.current.isDeleted).toBeTruthy(); result.current.handleToggleModal(); @@ -89,7 +91,7 @@ describe('useDeleteCases', () => { ); await waitForNextUpdate(); result.current.handleToggleModal(); - result.current.handleOnDeleteConfirm([{ id: '1' }, { id: '2' }, { id: '3' }]); + result.current.handleOnDeleteConfirm(deleteObj); expect(result.current.isLoading).toBe(true); }); }); @@ -106,7 +108,7 @@ describe('useDeleteCases', () => { ); await waitForNextUpdate(); result.current.handleToggleModal(); - result.current.handleOnDeleteConfirm([{ id: '1' }, { id: '2' }, { id: '3' }]); + result.current.handleOnDeleteConfirm(deleteObj); expect(result.current).toEqual({ isDisplayConfirmDeleteModal: false, diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.tsx index 4add69835ed33..3c49be551c064 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.tsx @@ -61,7 +61,7 @@ const dataFetchReducer = (state: DeleteState, action: Action): DeleteState => { export interface UseDeleteCase extends DeleteState { dispatchResetIsDeleted: () => void; - handleOnDeleteConfirm: (caseIds: DeleteCase[]) => void; + handleOnDeleteConfirm: (cases: DeleteCase[]) => void; handleToggleModal: () => void; } @@ -117,8 +117,8 @@ export const useDeleteCases = (): UseDeleteCase => { }, [state.isDisplayConfirmDeleteModal]); const handleOnDeleteConfirm = useCallback( - caseIds => { - dispatchDeleteCases(caseIds); + (cases: DeleteCase[]) => { + dispatchDeleteCases(cases); dispatchToggleDeleteModal(); }, [state.isDisplayConfirmDeleteModal] diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_get_action_license.test.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_get_action_license.test.tsx index 7003a78288c4f..23c9ff5e49586 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_get_action_license.test.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_get_action_license.test.tsx @@ -80,7 +80,7 @@ describe('useGetActionLicense', () => { await waitForNextUpdate(); expect(result.current).toEqual({ - ...initialData, + actionLicense: null, isLoading: false, isError: true, });