Skip to content

Commit

Permalink
create constants
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 20, 2020
1 parent 7c7fbc7 commit edbfad4
Show file tree
Hide file tree
Showing 39 changed files with 217 additions and 126 deletions.
34 changes: 19 additions & 15 deletions x-pack/legacy/plugins/siem/public/containers/case/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/

import { KibanaServices } from '../../lib/kibana';

import { CASE_URL } from '../../../../../../plugins/case/common/constants';

import {
deleteCases,
getActionLicense,
Expand All @@ -22,6 +25,7 @@ import {
pushCase,
pushToService,
} from './api';

import {
actionLicenses,
allCases,
Expand All @@ -44,7 +48,7 @@ import {
caseUserActionsSnake,
casesStatusSnake,
} from './mock';
import { CASES_URL } from './constants';

import { DEFAULT_FILTER_OPTIONS, DEFAULT_QUERY_PARAMS } from './use_get_cases';
import * as i18n from './translations';

Expand All @@ -65,7 +69,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await deleteCases(data, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}`, {
method: 'DELETE',
query: { ids: JSON.stringify(data) },
signal: abortCtrl.signal,
Expand Down Expand Up @@ -104,7 +108,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await getCase(data, true, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/${basicCase.id}`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/${basicCase.id}`, {
method: 'GET',
query: { includeComments: true },
signal: abortCtrl.signal,
Expand All @@ -127,7 +131,7 @@ describe('Case Configuration API', () => {
queryParams: DEFAULT_QUERY_PARAMS,
signal: abortCtrl.signal,
});
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/_find`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/_find`, {
method: 'GET',
query: {
...DEFAULT_QUERY_PARAMS,
Expand All @@ -150,7 +154,7 @@ describe('Case Configuration API', () => {
queryParams: DEFAULT_QUERY_PARAMS,
signal: abortCtrl.signal,
});
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/_find`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/_find`, {
method: 'GET',
query: {
...DEFAULT_QUERY_PARAMS,
Expand Down Expand Up @@ -178,7 +182,7 @@ describe('Case Configuration API', () => {
});
test('check url, method, signal', async () => {
await getCasesStatus(abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/status`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/status`, {
method: 'GET',
signal: abortCtrl.signal,
});
Expand All @@ -197,7 +201,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await getCaseUserActions(basicCase.id, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/${basicCase.id}/user_actions`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/${basicCase.id}/user_actions`, {
method: 'GET',
signal: abortCtrl.signal,
});
Expand All @@ -216,7 +220,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await getReporters(abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/reporters`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/reporters`, {
method: 'GET',
signal: abortCtrl.signal,
});
Expand All @@ -235,7 +239,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await getTags(abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/tags`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/tags`, {
method: 'GET',
signal: abortCtrl.signal,
});
Expand All @@ -254,7 +258,7 @@ describe('Case Configuration API', () => {
const data = { description: 'updated description' };
test('check url, method, signal', async () => {
await patchCase(basicCase.id, data, basicCase.version, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}`, {
method: 'PATCH',
body: JSON.stringify({
cases: [{ ...data, id: basicCase.id, version: basicCase.version }],
Expand Down Expand Up @@ -288,7 +292,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await patchCasesStatus(data, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}`, {
method: 'PATCH',
body: JSON.stringify({ cases: data }),
signal: abortCtrl.signal,
Expand All @@ -314,7 +318,7 @@ describe('Case Configuration API', () => {
basicCase.comments[0].version,
abortCtrl.signal
);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/${basicCase.id}/comments`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/${basicCase.id}/comments`, {
method: 'PATCH',
body: JSON.stringify({
comment: 'updated comment',
Expand Down Expand Up @@ -349,7 +353,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await postCase(data, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}`, {
method: 'POST',
body: JSON.stringify(data),
signal: abortCtrl.signal,
Expand All @@ -372,7 +376,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await postComment(data, basicCase.id, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/${basicCase.id}/comments`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/${basicCase.id}/comments`, {
method: 'POST',
body: JSON.stringify(data),
signal: abortCtrl.signal,
Expand All @@ -392,7 +396,7 @@ describe('Case Configuration API', () => {

test('check url, method, signal', async () => {
await pushCase(basicCase.id, pushSnake, abortCtrl.signal);
expect(fetchMock).toHaveBeenCalledWith(`${CASES_URL}/${basicCase.id}/_push`, {
expect(fetchMock).toHaveBeenCalledWith(`${CASE_URL}/${basicCase.id}/_push`, {
method: 'POST',
body: JSON.stringify(pushSnake),
signal: abortCtrl.signal,
Expand Down
67 changes: 37 additions & 30 deletions x-pack/legacy/plugins/siem/public/containers/case/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ import {
ActionTypeExecutorResult,
} from '../../../../../../plugins/case/common/api';

import {
CASE_STATUS_URL,
CASE_URL,
CASE_TAGS_URL,
CASE_REPORTERS_URL,
ACTION_TYPES_URL,
ACTION_URL,
} from '../../../../../../plugins/case/common/constants';

import {
getSingleCaseUrl,
getCaseUserActionUrl,
getCaseCommentUrl,
} from '../../../../../../plugins/case/common/api/helpers';

import { KibanaServices } from '../../lib/kibana';

import {
Expand All @@ -33,8 +48,6 @@ import {
CaseUserActions,
} from './types';

import { CASES_URL } from './constants';

import {
convertToCamelCase,
convertAllCasesToCamel,
Expand All @@ -54,7 +67,7 @@ export const getCase = async (
includeComments: boolean = true,
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(`${CASES_URL}/${caseId}`, {
const response = await KibanaServices.get().http.fetch<CaseResponse>(getSingleCaseUrl(caseId), {
method: 'GET',
query: {
includeComments,
Expand All @@ -65,26 +78,23 @@ export const getCase = async (
};

export const getCasesStatus = async (signal: AbortSignal): Promise<CasesStatus> => {
const response = await KibanaServices.get().http.fetch<CasesStatusResponse>(
`${CASES_URL}/status`,
{
method: 'GET',
signal,
}
);
const response = await KibanaServices.get().http.fetch<CasesStatusResponse>(CASE_STATUS_URL, {
method: 'GET',
signal,
});
return convertToCamelCase<CasesStatusResponse, CasesStatus>(decodeCasesStatusResponse(response));
};

export const getTags = async (signal: AbortSignal): Promise<string[]> => {
const response = await KibanaServices.get().http.fetch<string[]>(`${CASES_URL}/tags`, {
const response = await KibanaServices.get().http.fetch<string[]>(CASE_TAGS_URL, {
method: 'GET',
signal,
});
return response ?? [];
};

export const getReporters = async (signal: AbortSignal): Promise<User[]> => {
const response = await KibanaServices.get().http.fetch<User[]>(`${CASES_URL}/reporters`, {
const response = await KibanaServices.get().http.fetch<User[]>(CASE_REPORTERS_URL, {
method: 'GET',
signal,
});
Expand All @@ -96,7 +106,7 @@ export const getCaseUserActions = async (
signal: AbortSignal
): Promise<CaseUserActions[]> => {
const response = await KibanaServices.get().http.fetch<CaseUserActionsResponse>(
`${CASES_URL}/${caseId}/user_actions`,
getCaseUserActionUrl(caseId),
{
method: 'GET',
signal,
Expand Down Expand Up @@ -127,7 +137,7 @@ export const getCases = async ({
...(filterOptions.search.length > 0 ? { search: filterOptions.search } : {}),
...queryParams,
};
const response = await KibanaServices.get().http.fetch<CasesFindResponse>(`${CASES_URL}/_find`, {
const response = await KibanaServices.get().http.fetch<CasesFindResponse>(`${CASE_URL}/_find`, {
method: 'GET',
query,
signal,
Expand All @@ -136,7 +146,7 @@ export const getCases = async ({
};

export const postCase = async (newCase: CasePostRequest, signal: AbortSignal): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(CASES_URL, {
const response = await KibanaServices.get().http.fetch<CaseResponse>(CASE_URL, {
method: 'POST',
body: JSON.stringify(newCase),
signal,
Expand All @@ -150,7 +160,7 @@ export const patchCase = async (
version: string,
signal: AbortSignal
): Promise<Case[]> => {
const response = await KibanaServices.get().http.fetch<CasesResponse>(CASES_URL, {
const response = await KibanaServices.get().http.fetch<CasesResponse>(CASE_URL, {
method: 'PATCH',
body: JSON.stringify({ cases: [{ ...updatedCase, id: caseId, version }] }),
signal,
Expand All @@ -162,7 +172,7 @@ export const patchCasesStatus = async (
cases: BulkUpdateStatus[],
signal: AbortSignal
): Promise<Case[]> => {
const response = await KibanaServices.get().http.fetch<CasesResponse>(CASES_URL, {
const response = await KibanaServices.get().http.fetch<CasesResponse>(CASE_URL, {
method: 'PATCH',
body: JSON.stringify({ cases }),
signal,
Expand All @@ -176,7 +186,7 @@ export const postComment = async (
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(
`${CASES_URL}/${caseId}/comments`,
`${CASE_URL}/${caseId}/comments`,
{
method: 'POST',
body: JSON.stringify(newComment),
Expand All @@ -193,19 +203,16 @@ export const patchComment = async (
version: string,
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(
`${CASES_URL}/${caseId}/comments`,
{
method: 'PATCH',
body: JSON.stringify({ comment: commentUpdate, id: commentId, version }),
signal,
}
);
const response = await KibanaServices.get().http.fetch<CaseResponse>(getCaseCommentUrl(caseId), {
method: 'PATCH',
body: JSON.stringify({ comment: commentUpdate, id: commentId, version }),
signal,
});
return convertToCamelCase<CaseResponse, Case>(decodeCaseResponse(response));
};

export const deleteCases = async (caseIds: string[], signal: AbortSignal): Promise<string> => {
const response = await KibanaServices.get().http.fetch<string>(CASES_URL, {
const response = await KibanaServices.get().http.fetch<string>(CASE_URL, {
method: 'DELETE',
query: { ids: JSON.stringify(caseIds) },
signal,
Expand All @@ -219,7 +226,7 @@ export const pushCase = async (
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(
`${CASES_URL}/${caseId}/_push`,
`${getSingleCaseUrl(caseId)}/_push`,
{
method: 'POST',
body: JSON.stringify(push),
Expand All @@ -235,7 +242,7 @@ export const pushToService = async (
signal: AbortSignal
): Promise<ServiceConnectorCaseResponse> => {
const response = await KibanaServices.get().http.fetch<ActionTypeExecutorResult>(
`/api/action/${connectorId}/_execute`,
`${ACTION_URL}/${connectorId}/_execute`,
{
method: 'POST',
body: JSON.stringify({ params: casePushParams }),
Expand All @@ -251,7 +258,7 @@ export const pushToService = async (
};

export const getActionLicense = async (signal: AbortSignal): Promise<ActionLicense[]> => {
const response = await KibanaServices.get().http.fetch<ActionLicense[]>(`/api/action/types`, {
const response = await KibanaServices.get().http.fetch<ActionLicense[]>(ACTION_TYPES_URL, {
method: 'GET',
signal,
});
Expand Down
23 changes: 12 additions & 11 deletions x-pack/legacy/plugins/siem/public/containers/case/configure/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ import {
} from '../../../../../../../plugins/case/common/api';
import { KibanaServices } from '../../../lib/kibana';

import { CASES_CONFIGURE_URL } from '../constants';
import {
CASE_CONFIGURE_CONNECTORS_URL,
CASE_CONFIGURE_URL,
} from '../../../../../../../plugins/case/common/constants';

import { ApiProps } from '../types';
import { convertToCamelCase, decodeCaseConfigureResponse } from '../utils';
import { CaseConfigure } from './types';

export const fetchConnectors = async ({ signal }: ApiProps): Promise<Connector[]> => {
const response = await KibanaServices.get().http.fetch(
`${CASES_CONFIGURE_URL}/connectors/_find`,
{
method: 'GET',
signal,
}
);
const response = await KibanaServices.get().http.fetch(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`, {
method: 'GET',
signal,
});

return response;
};

export const getCaseConfigure = async ({ signal }: ApiProps): Promise<CaseConfigure | null> => {
const response = await KibanaServices.get().http.fetch<CasesConfigureResponse>(
CASES_CONFIGURE_URL,
CASE_CONFIGURE_URL,
{
method: 'GET',
signal,
Expand All @@ -51,7 +52,7 @@ export const postCaseConfigure = async (
signal: AbortSignal
): Promise<CaseConfigure> => {
const response = await KibanaServices.get().http.fetch<CasesConfigureResponse>(
CASES_CONFIGURE_URL,
CASE_CONFIGURE_URL,
{
method: 'POST',
body: JSON.stringify(caseConfiguration),
Expand All @@ -68,7 +69,7 @@ export const patchCaseConfigure = async (
signal: AbortSignal
): Promise<CaseConfigure> => {
const response = await KibanaServices.get().http.fetch<CasesConfigureResponse>(
CASES_CONFIGURE_URL,
CASE_CONFIGURE_URL,
{
method: 'PATCH',
body: JSON.stringify(caseConfiguration),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const CASES_URL = `/api/cases`;
export const CASES_CONFIGURE_URL = `/api/cases/configure`;
export const DEFAULT_TABLE_ACTIVE_PAGE = 1;
export const DEFAULT_TABLE_LIMIT = 5;
Loading

0 comments on commit edbfad4

Please sign in to comment.