Skip to content

Commit 484ce16

Browse files
committed
Merge branch 'convert_unit_tests_to_integration_tests' of github.com:cnasikas/kibana into convert_unit_tests_to_integration_tests
2 parents 1aaeb4f + 77e9a93 commit 484ce16

16 files changed

Lines changed: 70 additions & 200 deletions

File tree

x-pack/plugins/cases/server/routes/api/cases/delete_cases.test.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.

x-pack/test/case_api_integration/common/lib/utils.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export const removeServerGeneratedPropertiesFromComments = (
448448

449449
export const deleteAllCaseItems = async (es: KibanaClient) => {
450450
await Promise.all([
451-
deleteCases(es),
451+
deleteCasesByESQuery(es),
452452
deleteSubCases(es),
453453
deleteCasesUserActions(es),
454454
deleteComments(es),
@@ -468,7 +468,7 @@ export const deleteCasesUserActions = async (es: KibanaClient): Promise<void> =>
468468
});
469469
};
470470

471-
export const deleteCases = async (es: KibanaClient): Promise<void> => {
471+
export const deleteCasesByESQuery = async (es: KibanaClient): Promise<void> => {
472472
await es.deleteByQuery({
473473
index: '.kibana',
474474
// @ts-expect-error @elastic/elasticsearch DeleteByQueryRequest doesn't accept q parameter
@@ -600,6 +600,27 @@ export const createCase = async (
600600
return theCase;
601601
};
602602

603+
/**
604+
* Sends a delete request for the specified case IDs.
605+
*/
606+
export const deleteCases = async ({
607+
supertest,
608+
caseIDs,
609+
expectedHttpCode = 204,
610+
}: {
611+
supertest: st.SuperTest<supertestAsPromised.Test>;
612+
caseIDs: string[];
613+
expectedHttpCode?: number;
614+
}) => {
615+
const { body } = await supertest
616+
.delete(`${CASES_URL}?ids=${JSON.stringify(caseIDs)}`)
617+
.set('kbn-xsrf', 'true')
618+
.send()
619+
.expect(expectedHttpCode);
620+
621+
return body;
622+
};
623+
603624
export const createComment = async (
604625
supertest: st.SuperTest<supertestAsPromised.Test>,
605626
caseId: string,

x-pack/test/case_api_integration/security_and_spaces/tests/basic/cases/push_case.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
99

1010
import { postCaseReq } from '../../../../common/lib/mock';
1111
import {
12-
deleteCases,
12+
deleteCasesByESQuery,
1313
deleteCasesUserActions,
1414
deleteComments,
1515
deleteConfiguration,
@@ -29,7 +29,7 @@ export default ({ getService }: FtrProviderContext): void => {
2929

3030
describe('push_case', () => {
3131
afterEach(async () => {
32-
await deleteCases(es);
32+
await deleteCasesByESQuery(es);
3333
await deleteComments(es);
3434
await deleteConfiguration(es);
3535
await deleteCasesUserActions(es);

x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/delete_cases.ts

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ import expect from '@kbn/expect';
99
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
1010

1111
import { CASES_URL } from '../../../../../../plugins/cases/common/constants';
12-
import { postCaseReq, postCommentUserReq } from '../../../../common/lib/mock';
12+
import { getPostCaseRequest, postCommentUserReq } from '../../../../common/lib/mock';
1313
import {
1414
createCaseAction,
1515
createSubCase,
1616
deleteAllCaseItems,
1717
deleteCaseAction,
18-
deleteCases,
18+
deleteCasesByESQuery,
1919
deleteCasesUserActions,
2020
deleteComments,
21+
createCase,
22+
deleteCases,
23+
createComment,
24+
getComment,
2125
} from '../../../../common/lib/utils';
2226
import { getSubCaseDetailsUrl } from '../../../../../../plugins/cases/common/api/helpers';
2327
import { CaseResponse } from '../../../../../../plugins/cases/common/api';
@@ -29,65 +33,32 @@ export default ({ getService }: FtrProviderContext): void => {
2933

3034
describe('delete_cases', () => {
3135
afterEach(async () => {
32-
await deleteCases(es);
36+
await deleteCasesByESQuery(es);
3337
await deleteComments(es);
3438
await deleteCasesUserActions(es);
3539
});
3640

3741
it('should delete a case', async () => {
38-
const { body: postedCase } = await supertest
39-
.post(CASES_URL)
40-
.set('kbn-xsrf', 'true')
41-
.send(postCaseReq)
42-
.expect(200);
43-
44-
const { body } = await supertest
45-
.delete(`${CASES_URL}?ids=["${postedCase.id}"]`)
46-
.set('kbn-xsrf', 'true')
47-
.send()
48-
.expect(204);
42+
const postedCase = await createCase(supertest, getPostCaseRequest());
43+
const body = await deleteCases({ supertest, caseIDs: [postedCase.id] });
4944

5045
expect(body).to.eql({});
5146
});
5247

5348
it(`should delete a case's comments when that case gets deleted`, async () => {
54-
const { body: postedCase } = await supertest
55-
.post(CASES_URL)
56-
.set('kbn-xsrf', 'true')
57-
.send(postCaseReq)
58-
.expect(200);
59-
60-
const { body: patchedCase } = await supertest
61-
.post(`${CASES_URL}/${postedCase.id}/comments`)
62-
.set('kbn-xsrf', 'true')
63-
.send(postCommentUserReq)
64-
.expect(200);
65-
66-
await supertest
67-
.get(`${CASES_URL}/${postedCase.id}/comments/${patchedCase.comments[0].id}`)
68-
.set('kbn-xsrf', 'true')
69-
.send()
70-
.expect(200);
71-
72-
await supertest
73-
.delete(`${CASES_URL}?ids=["${postedCase.id}"]`)
74-
.set('kbn-xsrf', 'true')
75-
.send()
76-
.expect(204);
77-
78-
await supertest
79-
.get(`${CASES_URL}/${postedCase.id}/comments/${patchedCase.comments[0].id}`)
80-
.set('kbn-xsrf', 'true')
81-
.send()
82-
.expect(404);
49+
const postedCase = await createCase(supertest, getPostCaseRequest());
50+
const patchedCase = await createComment(supertest, postedCase.id, postCommentUserReq);
51+
// ensure that we can get the comment before deleting the case
52+
await getComment(supertest, postedCase.id, patchedCase.comments![0].id);
53+
54+
await deleteCases({ supertest, caseIDs: [postedCase.id] });
55+
56+
// make sure the comment is now gone
57+
await getComment(supertest, postedCase.id, patchedCase.comments![0].id, 404);
8358
});
8459

8560
it('unhappy path - 404s when case is not there', async () => {
86-
await supertest
87-
.delete(`${CASES_URL}?ids=["fake-id"]`)
88-
.set('kbn-xsrf', 'true')
89-
.send()
90-
.expect(404);
61+
await deleteCases({ supertest, caseIDs: ['fake-id'], expectedHttpCode: 404 });
9162
});
9263

9364
// ENABLE_CASE_CONNECTOR: once the case connector feature is completed unskip these tests
@@ -107,11 +78,7 @@ export default ({ getService }: FtrProviderContext): void => {
10778
const { newSubCaseInfo: caseInfo } = await createSubCase({ supertest, actionID });
10879
expect(caseInfo.subCases![0].id).to.not.eql(undefined);
10980

110-
const { body } = await supertest
111-
.delete(`${CASES_URL}?ids=["${caseInfo.id}"]`)
112-
.set('kbn-xsrf', 'true')
113-
.send()
114-
.expect(204);
81+
const body = await deleteCases({ supertest, caseIDs: [caseInfo.id] });
11582

11683
expect(body).to.eql({});
11784
await supertest
@@ -138,11 +105,7 @@ export default ({ getService }: FtrProviderContext): void => {
138105
// make sure we can get the second comment
139106
await supertest.get(subCaseCommentUrl).set('kbn-xsrf', 'true').send().expect(200);
140107

141-
await supertest
142-
.delete(`${CASES_URL}?ids=["${caseInfo.id}"]`)
143-
.set('kbn-xsrf', 'true')
144-
.send()
145-
.expect(204);
108+
await deleteCases({ supertest, caseIDs: [caseInfo.id] });
146109

147110
await supertest.get(subCaseCommentUrl).set('kbn-xsrf', 'true').send().expect(404);
148111
});

x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/get_case.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
postCommentUserReq,
1818
} from '../../../../common/lib/mock';
1919
import {
20-
deleteCases,
20+
deleteCasesByESQuery,
2121
createCase,
2222
getCase,
2323
createComment,
@@ -32,7 +32,7 @@ export default ({ getService }: FtrProviderContext): void => {
3232

3333
describe('get_case', () => {
3434
afterEach(async () => {
35-
await deleteCases(es);
35+
await deleteCasesByESQuery(es);
3636
});
3737

3838
it('should return a case with no comments', async () => {

x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/post_case.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { getPostCaseRequest, postCaseResp, defaultUser } from '../../../../common/lib/mock';
1717
import {
1818
createCaseAsUser,
19-
deleteCases,
19+
deleteCasesByESQuery,
2020
createCase,
2121
removeServerGeneratedPropertiesFromCase,
2222
removeServerGeneratedPropertiesFromUserAction,
@@ -40,7 +40,7 @@ export default ({ getService }: FtrProviderContext): void => {
4040

4141
describe('post_case', () => {
4242
afterEach(async () => {
43-
await deleteCases(es);
43+
await deleteCasesByESQuery(es);
4444
});
4545

4646
describe('happy path', () => {

x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/reporters/get_reporters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FtrProviderContext } from '../../../../../../common/ftr_provider_contex
1010

1111
import { CASES_URL, CASE_REPORTERS_URL } from '../../../../../../../plugins/cases/common/constants';
1212
import { defaultUser, postCaseReq } from '../../../../../common/lib/mock';
13-
import { deleteCases } from '../../../../../common/lib/utils';
13+
import { deleteCasesByESQuery } from '../../../../../common/lib/utils';
1414

1515
// eslint-disable-next-line import/no-default-export
1616
export default ({ getService }: FtrProviderContext): void => {
@@ -19,7 +19,7 @@ export default ({ getService }: FtrProviderContext): void => {
1919

2020
describe('get_reporters', () => {
2121
afterEach(async () => {
22-
await deleteCases(es);
22+
await deleteCasesByESQuery(es);
2323
});
2424

2525
it('should return reporters', async () => {

x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/status/get_status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../../../../../common/ftr_provider_contex
1111
import { CaseStatuses } from '../../../../../../../plugins/cases/common/api';
1212
import { postCaseReq } from '../../../../../common/lib/mock';
1313
import {
14-
deleteCases,
14+
deleteCasesByESQuery,
1515
createCase,
1616
updateCase,
1717
getAllCasesStatuses,
@@ -24,7 +24,7 @@ export default ({ getService }: FtrProviderContext): void => {
2424

2525
describe('get_status', () => {
2626
afterEach(async () => {
27-
await deleteCases(es);
27+
await deleteCasesByESQuery(es);
2828
});
2929

3030
it('should return case statuses', async () => {

x-pack/test/case_api_integration/security_and_spaces/tests/common/cases/tags/get_tags.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FtrProviderContext } from '../../../../../../common/ftr_provider_contex
1010

1111
import { CASES_URL, CASE_TAGS_URL } from '../../../../../../../plugins/cases/common/constants';
1212
import { postCaseReq } from '../../../../../common/lib/mock';
13-
import { deleteCases } from '../../../../../common/lib/utils';
13+
import { deleteCasesByESQuery } from '../../../../../common/lib/utils';
1414

1515
// eslint-disable-next-line import/no-default-export
1616
export default ({ getService }: FtrProviderContext): void => {
@@ -19,7 +19,7 @@ export default ({ getService }: FtrProviderContext): void => {
1919

2020
describe('get_tags', () => {
2121
afterEach(async () => {
22-
await deleteCases(es);
22+
await deleteCasesByESQuery(es);
2323
});
2424

2525
it('should return case tags', async () => {

0 commit comments

Comments
 (0)