Skip to content

Commit

Permalink
pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Apr 14, 2020
1 parent a58f974 commit 1c3ee15
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
65 changes: 63 additions & 2 deletions x-pack/legacy/plugins/siem/public/containers/case/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
caseUserActions,
pushedCase,
pushSnake,
reporters,
respReporters,
serviceConnector,
casePushParams,
Expand All @@ -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;
Expand All @@ -57,7 +59,7 @@ describe('Case Configuration API', () => {
describe('deleteCases', () => {
beforeEach(() => {
fetchMock.mockClear();
fetchMock.mockResolvedValue('true');
fetchMock.mockResolvedValue('');
});
const data = ['1', '2'];

Expand All @@ -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', () => {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, UseDeleteCase>(() =>
Expand Down Expand Up @@ -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);
});
});

Expand All @@ -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,
Expand All @@ -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();
Expand All @@ -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);
});
});
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -117,8 +117,8 @@ export const useDeleteCases = (): UseDeleteCase => {
}, [state.isDisplayConfirmDeleteModal]);

const handleOnDeleteConfirm = useCallback(
caseIds => {
dispatchDeleteCases(caseIds);
(cases: DeleteCase[]) => {
dispatchDeleteCases(cases);
dispatchToggleDeleteModal();
},
[state.isDisplayConfirmDeleteModal]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('useGetActionLicense', () => {
await waitForNextUpdate();

expect(result.current).toEqual({
...initialData,
actionLicense: null,
isLoading: false,
isError: true,
});
Expand Down

0 comments on commit 1c3ee15

Please sign in to comment.