Skip to content

Commit

Permalink
Added more end to end tests for lists
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Aug 10, 2020
1 parent c8aec74 commit 055b219
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ export const getCreateListItemSchemaMock = (): CreateListItemSchema => ({
value: VALUE,
});

/**
* Useful for end to end testing
*/
export const getCreateMinimalListItemSchemaMock = (): CreateListItemSchema => ({
id: LIST_ITEM_ID,
list_id: LIST_ID,
value: VALUE,
});

/**
* Useful for end to end testing
*/
export const getCreateMinimalListItemSchemaMockWithoutId = (): CreateListItemSchema => ({
list_id: LIST_ID,
value: VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ export const getCreateListSchemaMock = (): CreateListSchema => ({
version: VERSION,
});

/**
* Useful for end to end tests and other mechanisms which want to fill in the values
*/
export const getCreateMinimalListSchemaMock = (): CreateListSchema => ({
description: DESCRIPTION,
id: LIST_ID,
name: NAME,
type: TYPE,
});

/**
* Useful for end to end tests and other mechanisms which want to fill in the values
*/
export const getCreateMinimalListSchemaMockWithoutId = (): CreateListSchema => ({
description: DESCRIPTION,
name: NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ID, META, VALUE } from '../../constants.mock';
import { ID, LIST_ITEM_ID, META, VALUE } from '../../constants.mock';

import { UpdateListItemSchema } from './update_list_item_schema';

Expand All @@ -13,3 +13,11 @@ export const getUpdateListItemSchemaMock = (): UpdateListItemSchema => ({
meta: META,
value: VALUE,
});

/**
* Useful for end to end testing
*/
export const getUpdateMinimalListItemSchemaMock = (): UpdateListItemSchema => ({
id: LIST_ITEM_ID,
value: VALUE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const deleteListItemRoute = (router: IRouter): void => {
const deleted = await lists.deleteListItem({ id });
if (deleted == null) {
return siemResponse.error({
body: `list item with id: "${id}" item not found`,
body: `list item with id: "${id}" not found`,
statusCode: 404,
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
} from '../../../../plugins/lists/common/schemas/request/create_list_item_schema.mock';
import { getListItemResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_item_schema.mock';

import { createListsIndex, deleteListsIndex, removeServerGeneratedProperties } from '../../utils';
import {
createListsIndex,
deleteListsIndex,
removeListItemServerGeneratedProperties,
} from '../../utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
Expand Down Expand Up @@ -61,7 +65,7 @@ export default ({ getService }: FtrProviderContext) => {
.send(getCreateMinimalListItemSchemaMock())
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListItemServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListItemResponseMockWithoutAutoGeneratedValues());
});

Expand All @@ -78,7 +82,7 @@ export default ({ getService }: FtrProviderContext) => {
.send(getCreateMinimalListItemSchemaMockWithoutId())
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListItemServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListItemResponseMockWithoutAutoGeneratedValues());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import { getListResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_schema.mock';

import { createListsIndex, deleteListsIndex, removeServerGeneratedProperties } from '../../utils';
import {
createListsIndex,
deleteListsIndex,
removeListServerGeneratedProperties,
} from '../../utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
Expand Down Expand Up @@ -53,7 +57,7 @@ export default ({ getService }: FtrProviderContext) => {
.send(getCreateMinimalListSchemaMock())
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

Expand All @@ -64,7 +68,7 @@ export default ({ getService }: FtrProviderContext) => {
.send(getCreateMinimalListSchemaMockWithoutId())
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';

import { getListItemResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_item_schema.mock';
import { getCreateMinimalListItemSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_item_schema.mock';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { LIST_URL, LIST_ITEM_URL } from '../../../../plugins/lists/common/constants';

import { getCreateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import {
createListsIndex,
deleteListsIndex,
removeListItemServerGeneratedProperties,
} from '../../utils';

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

describe('delete_list_items', () => {
describe('deleting list items', () => {
beforeEach(async () => {
await createListsIndex(supertest);
});

afterEach(async () => {
await deleteListsIndex(supertest);
});

it('should delete a single list item with a list item id', async () => {
// create a list
await supertest
.post(LIST_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMock())
.expect(200);

// create a list item
await supertest
.post(LIST_ITEM_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListItemSchemaMock())
.expect(200);

// delete the list item by its list item id
const { body } = await supertest
.delete(`${LIST_ITEM_URL}?id=${getCreateMinimalListItemSchemaMock().id}`)
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeListItemServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListItemResponseMockWithoutAutoGeneratedValues());
});

it('should delete a single list using an auto generated id', async () => {
// create a list
await supertest
.post(LIST_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMock())
.expect(200);

// create a list item
const { body: bodyWithCreateListItem } = await supertest
.post(LIST_ITEM_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListItemSchemaMock())
.expect(200);

// delete that list by its auto-generated id
const { body } = await supertest
.delete(`${LIST_ITEM_URL}?id=${bodyWithCreateListItem.id}`)
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeListItemServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListItemResponseMockWithoutAutoGeneratedValues());
});

it('should return an error if the id does not exist when trying to delete it', async () => {
const { body } = await supertest
.delete(`${LIST_ITEM_URL}?id=c1e1b359-7ac1-4e96-bc81-c683c092436f`)
.set('kbn-xsrf', 'true')
.expect(404);

expect(body).to.eql({
message: 'list item with id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" not found',
status_code: 404,
});
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { FtrProviderContext } from '../../common/ftr_provider_context';
import { LIST_URL } from '../../../../plugins/lists/common/constants';

import { getCreateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import { createListsIndex, deleteListsIndex, removeServerGeneratedProperties } from '../../utils';
import {
createListsIndex,
deleteListsIndex,
removeListServerGeneratedProperties,
} from '../../utils';
import { getListResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_schema.mock';

// eslint-disable-next-line import/no-default-export
Expand Down Expand Up @@ -41,7 +45,7 @@ export default ({ getService }: FtrProviderContext) => {
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

Expand All @@ -59,7 +63,7 @@ export default ({ getService }: FtrProviderContext) => {
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { FtrProviderContext } from '../../common/ftr_provider_context';
import { LIST_URL } from '../../../../plugins/lists/common/constants';

import { getCreateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import { createListsIndex, deleteListsIndex, removeServerGeneratedProperties } from '../../utils';
import {
createListsIndex,
deleteListsIndex,
removeListServerGeneratedProperties,
} from '../../utils';
import { getListResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_schema.mock';

// eslint-disable-next-line import/no-default-export
Expand Down Expand Up @@ -58,7 +62,7 @@ export default ({ getService }: FtrProviderContext): void => {
.send()
.expect(200);

body.data = [removeServerGeneratedProperties(body.data[0])];
body.data = [removeListServerGeneratedProperties(body.data[0])];
// cursor is a constant changing value so we have to delete it as well.
delete body.cursor;
expect(body).to.eql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./read_lists'));
loadTestFile(require.resolve('./read_list_items'));
loadTestFile(require.resolve('./update_lists'));
loadTestFile(require.resolve('./update_list_items'));
loadTestFile(require.resolve('./delete_lists'));
loadTestFile(require.resolve('./delete_list_items'));
loadTestFile(require.resolve('./find_lists'));
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { FtrProviderContext } from '../../common/ftr_provider_context';
import { LIST_URL, LIST_ITEM_URL } from '../../../../plugins/lists/common/constants';

import { getCreateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import { createListsIndex, deleteListsIndex, removeServerGeneratedProperties } from '../../utils';
import {
createListsIndex,
deleteListsIndex,
removeListItemServerGeneratedProperties,
} from '../../utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
Expand Down Expand Up @@ -46,7 +50,7 @@ export default ({ getService }: FtrProviderContext) => {
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListItemServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListItemResponseMockWithoutAutoGeneratedValues());
});

Expand All @@ -68,7 +72,7 @@ export default ({ getService }: FtrProviderContext) => {
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListItemServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListItemResponseMockWithoutAutoGeneratedValues());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
getCreateMinimalListSchemaMock,
getCreateMinimalListSchemaMockWithoutId,
} from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import { createListsIndex, deleteListsIndex, removeServerGeneratedProperties } from '../../utils';
import {
createListsIndex,
deleteListsIndex,
removeListServerGeneratedProperties,
} from '../../utils';
import { getListResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_schema.mock';

// eslint-disable-next-line import/no-default-export
Expand Down Expand Up @@ -43,7 +47,7 @@ export default ({ getService }: FtrProviderContext) => {
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

Expand All @@ -60,7 +64,7 @@ export default ({ getService }: FtrProviderContext) => {
.set('kbn-xsrf', 'true')
.expect(200);

const bodyToCompare = removeServerGeneratedProperties(body);
const bodyToCompare = removeListServerGeneratedProperties(body);
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

Expand Down
Loading

0 comments on commit 055b219

Please sign in to comment.