Skip to content

Commit

Permalink
Add new e2e test for summart endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dasansol92 committed May 27, 2021
1 parent 9f6b620 commit 5b17fd5
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./find_exception_lists'));
loadTestFile(require.resolve('./find_exception_list_items'));
loadTestFile(require.resolve('./read_list_privileges'));
loadTestFile(require.resolve('./summary_exception_lists'));
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';

import { EXCEPTION_LIST_URL, EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import { LIST_ID } from '../../../../plugins/lists/common/constants.mock';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { getCreateExceptionListMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock';
import { getCreateExceptionListItemMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_item_schema.mock';
import { createListsIndex, deleteListsIndex, deleteAllExceptions } from '../../utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('es');

describe('summary_exception_lists', () => {
describe('summary exception lists', () => {
afterEach(async () => {
await deleteListsIndex(supertest);
await deleteAllExceptions(es);
});
beforeEach(async () => {
await createListsIndex(supertest);
});

it('should give a validation error if the list_id and the id are not supplied', async () => {
const { body } = await supertest
.get(`${EXCEPTION_LIST_URL}/summary`)
.set('kbn-xsrf', 'true')
.send(getCreateExceptionListMinimalSchemaMock())
.expect(400);

expect(body).to.eql({
message: 'id or list_id required',
status_code: 400,
});
});

it('should return init summary when there are no items created', async () => {
const { body } = await supertest
.get(`${EXCEPTION_LIST_URL}/summary?list_id=${LIST_ID}`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).to.eql({
linux: 0,
macos: 0,
total: 0,
windows: 0,
});
});

it('should return right summary when there are items created', async () => {
await supertest
.post(EXCEPTION_LIST_URL)
.set('kbn-xsrf', 'true')
.send(getCreateExceptionListMinimalSchemaMock())
.expect(200);

const item = getCreateExceptionListItemMinimalSchemaMock();

for (const os of ['windows', 'linux', 'macos']) {
await supertest
.post(EXCEPTION_LIST_ITEM_URL)
.set('kbn-xsrf', 'true')
.send({ ...item, os_types: [os], item_id: `${item.item_id}-${os}` })
.expect(200);
}

const { body } = await supertest
.get(`${EXCEPTION_LIST_URL}/summary?list_id=${LIST_ID}`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

delete body.cursor;
expect(body).to.eql({
linux: 1,
macos: 1,
total: 3,
windows: 1,
});
});
});
});
};

0 comments on commit 5b17fd5

Please sign in to comment.