Skip to content

Commit

Permalink
fix types and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlog committed Jun 21, 2021
1 parent d09829e commit 9a102f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RequestHandler } from 'src/core/server';
import uuid from 'uuid';
import { TypeOf } from '@kbn/config-schema';
import { CommentType } from '../../../../../cases/common';
import { CasesByAlertId } from '../../../../../cases/common/api/cases/case';
import { HostIsolationRequestSchema } from '../../../../common/endpoint/schema/actions';
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants';
import { AGENT_ACTIONS_INDEX } from '../../../../../fleet/common';
Expand Down Expand Up @@ -103,12 +104,17 @@ export const isolationRequestHandler = function (
let caseIDs: string[] = req.body.case_ids?.slice() || [];
if (req.body.alert_ids && req.body.alert_ids.length > 0) {
const newIDs: string[][] = await Promise.all(
req.body.alert_ids.map(async (a: string) =>
(await endpointContext.service.getCasesClient(req)).cases.getCaseIDsByAlertID({
req.body.alert_ids.map(async (a: string) => {
const cases: CasesByAlertId = await (
await endpointContext.service.getCasesClient(req)
).cases.getCasesByAlertID({
alertID: a,
options: { owner: APP_ID },
})
)
});
return cases.map((caseInfo): string => {
return caseInfo.id;
});
})
);
caseIDs = caseIDs.concat(...newIDs);
}
Expand Down
8 changes: 7 additions & 1 deletion x-pack/test/case_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ export const findCases = async ({
return res;
};

export const getCaseIDsByAlert = async ({
export const getCasesByAlert = async ({
supertest,
alertID,
query = {},
Expand All @@ -1040,6 +1040,12 @@ export const getCaseIDsByAlert = async ({
return res;
};

export const getCaseIDsFromCases = (cases: CasesByAlertId) => {
return cases.map((caseInfo): string => {
return caseInfo.id;
});
};

export const getTags = async ({
supertest,
query = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { getPostCaseRequest, postCommentAlertReq } from '../../../../common/lib/
import {
createCase,
createComment,
getCaseIDsByAlert,
getCasesByAlert,
deleteAllCaseItems,
getAuthWithSuperUser,
getCaseIDsFromCases,
} from '../../../../common/lib/utils';

// eslint-disable-next-line import/no-default-export
Expand Down Expand Up @@ -57,12 +58,14 @@ export default ({ getService }: FtrProviderContext): void => {
}),
]);

const caseIDsWithAlert = await getCaseIDsByAlert({
const casesByAlert = await getCasesByAlert({
supertest,
alertID: 'test-id',
auth: authSpace1,
});

const caseIDsWithAlert = getCaseIDsFromCases(casesByAlert);

expect(caseIDsWithAlert.length).to.eql(3);
expect(caseIDsWithAlert).to.contain(case1.id);
expect(caseIDsWithAlert).to.contain(case2.id);
Expand Down Expand Up @@ -97,12 +100,14 @@ export default ({ getService }: FtrProviderContext): void => {
}),
]);

const caseIDsWithAlert = await getCaseIDsByAlert({
const casesByAlert = await getCasesByAlert({
supertest,
alertID: 'test-id',
auth: authSpace2,
});

const caseIDsWithAlert = getCaseIDsFromCases(casesByAlert);

expect(caseIDsWithAlert.length).to.eql(1);
expect(caseIDsWithAlert).to.eql([case3.id]);
});
Expand Down

0 comments on commit 9a102f5

Please sign in to comment.