Skip to content

Commit

Permalink
Fixes lint issue and adds a base read_lists end to end test
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Aug 6, 2020
1 parent 7d1d940 commit 55bc2ad
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ export const getCreateMinimalListSchemaMock = (): CreateListSchema => ({
name: NAME,
type: TYPE,
});

export const getCreateMinimalListSchemaMockWithoutId = (): CreateListSchema => ({
description: DESCRIPTION,
name: NAME,
type: TYPE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import expect from '@kbn/expect';

import { LIST_URL } from '../../../../plugins/lists/common/constants';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { getCreateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock';
import {
getCreateMinimalListSchemaMock,
getCreateMinimalListSchemaMockWithoutId,
} 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';
Expand Down Expand Up @@ -54,6 +57,17 @@ export default ({ getService }: FtrProviderContext) => {
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues());
});

it('should create a simple list without a list_id', async () => {
const { body } = await supertest
.post(LIST_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMockWithoutId())
.expect(200);

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

it('should cause a 409 conflict if we attempt to create the same list_id twice', async () => {
await supertest
.post(LIST_URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
this.tags('ciGroup1');

loadTestFile(require.resolve('./create_lists'));
loadTestFile(require.resolve('./read_lists'));
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 { FtrProviderContext } from '../../common/ftr_provider_context';
import { LIST_URL } from '../../../../plugins/lists/common/constants';

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

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

describe('read_lists', () => {
describe('reading lists', () => {
beforeEach(async () => {
await createListsIndex(supertest);
});

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

it('should be able to read a single list using id', async () => {
// create a simple list to read
await supertest
.post(LIST_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMock())
.expect(200);

const { body } = await supertest
.get(`${LIST_URL}?id=some-list-id`)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMock())
.expect(200);

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

it('should be able to read a single list with an auto-generated list id', async () => {
// create a simple list to read
const { body: createListBody } = await supertest
.post(LIST_URL)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMockWithoutId())
.expect(200);

const { body } = await supertest
.get(`${LIST_URL}?id=${createListBody.id}`)
.set('kbn-xsrf', 'true')
.send(getCreateMinimalListSchemaMock())
.expect(200);

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

it('should return 404 if given a fake id', async () => {
const { body } = await supertest
.get(`${LIST_URL}?id=c1e1b359-7ac1-4e96-bc81-c683c092436f`)
.set('kbn-xsrf', 'true')
.expect(404);

expect(body).to.eql({
status_code: 404,
message: 'list id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist',
});
});
});
});
};
1 change: 1 addition & 0 deletions x-pack/test/lists_api_integration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const deleteListsIndex = async (
* @param rule Rule to pass in to remove typical server generated properties
*/
export const removeServerGeneratedProperties = (rule: Partial<ListSchema>): Partial<ListSchema> => {
/* eslint-disable-next-line @typescript-eslint/naming-convention */
const { created_at, updated_at, id, tie_breaker_id, ...removedProperties } = rule;
return removedProperties;
};

0 comments on commit 55bc2ad

Please sign in to comment.