-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds more end to end tests, fixes some message bugs in the REST route…
…s, and adds some missing unit tests
- Loading branch information
1 parent
cc685d0
commit ec64d17
Showing
12 changed files
with
374 additions
and
8 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/lists/common/schemas/request/update_list_schema.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 { DESCRIPTION, LIST_ID, META, NAME, _VERSION } from '../../constants.mock'; | ||
|
||
import { UpdateListSchema } from './update_list_schema'; | ||
|
||
export const getUpdateListSchemaMock = (): UpdateListSchema => ({ | ||
_version: _VERSION, | ||
description: DESCRIPTION, | ||
id: LIST_ID, | ||
meta: META, | ||
name: NAME, | ||
}); | ||
|
||
/** | ||
* Useful for end to end tests and other mechanisms which want to fill in the values | ||
* after doing a get of the structure. | ||
*/ | ||
export const getUpdateMinimalListSchemaMock = (): UpdateListSchema => ({ | ||
description: DESCRIPTION, | ||
id: LIST_ID, | ||
name: NAME, | ||
}); |
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/lists/common/schemas/request/update_list_schema.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 { left } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
|
||
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports'; | ||
|
||
import { UpdateListSchema, updateListSchema } from './update_list_schema'; | ||
import { getUpdateListSchemaMock } from './update_list_schema.mock'; | ||
|
||
describe('update_list_schema', () => { | ||
test('it should validate a typical list request', () => { | ||
const payload = getUpdateListSchemaMock(); | ||
const decoded = updateListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an undefined for "meta" but strip it out', () => { | ||
const payload = getUpdateListSchemaMock(); | ||
const outputPayload = getUpdateListSchemaMock(); | ||
delete payload.meta; | ||
const decoded = updateListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
delete outputPayload.meta; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: UpdateListSchema & { | ||
extraKey?: string; | ||
} = getUpdateListSchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = updateListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual(['invalid keys "extraKey"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
x-pack/test/lists_api_integration/security_and_spaces/tests/delete_lists.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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 } 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('delete_lists', () => { | ||
describe('deleting lists', () => { | ||
beforeEach(async () => { | ||
await createListsIndex(supertest); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteListsIndex(supertest); | ||
}); | ||
|
||
it('should delete a single list with a list id', async () => { | ||
// create a list | ||
await supertest | ||
.post(LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateMinimalListSchemaMock()) | ||
.expect(200); | ||
|
||
// delete the list by its list id | ||
const { body } = await supertest | ||
.delete(`${LIST_URL}?id=${getCreateMinimalListSchemaMock().id}`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(200); | ||
|
||
const bodyToCompare = removeServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues()); | ||
}); | ||
|
||
it('should delete a single list using an auto generated id', async () => { | ||
// add a list | ||
const { body: bodyWithCreatedList } = await supertest | ||
.post(LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateMinimalListSchemaMock()) | ||
.expect(200); | ||
|
||
// delete that list by its auto-generated id | ||
const { body } = await supertest | ||
.delete(`${LIST_URL}?id=${bodyWithCreatedList.id}`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(200); | ||
|
||
const bodyToCompare = removeServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(getListResponseMockWithoutAutoGeneratedValues()); | ||
}); | ||
|
||
it('should return an error if the id does not exist when trying to delete it', async () => { | ||
const { body } = await supertest | ||
.delete(`${LIST_URL}?id=c1e1b359-7ac1-4e96-bc81-c683c092436f`) | ||
.set('kbn-xsrf', 'true') | ||
.expect(404); | ||
|
||
expect(body).to.eql({ | ||
message: 'list id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" was not found', | ||
status_code: 404, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
73 changes: 73 additions & 0 deletions
73
x-pack/test/lists_api_integration/security_and_spaces/tests/find_lists.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 } 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): void => { | ||
const supertest = getService('supertest'); | ||
|
||
describe('find_lists', () => { | ||
describe('find lists', () => { | ||
beforeEach(async () => { | ||
await createListsIndex(supertest); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteListsIndex(supertest); | ||
}); | ||
|
||
it('should return an empty find body correctly if no lists are loaded', async () => { | ||
const { body } = await supertest | ||
.get(`${LIST_URL}/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(body).to.eql({ | ||
cursor: 'WzBd', | ||
data: [], | ||
page: 1, | ||
per_page: 20, | ||
total: 0, | ||
}); | ||
}); | ||
|
||
it('should return a single list when a single list is loaded from a find with defaults added', async () => { | ||
// add a single list | ||
await supertest | ||
.post(LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateMinimalListSchemaMock()) | ||
.expect(200); | ||
|
||
// query the single list from _find | ||
const { body } = await supertest | ||
.get(`${LIST_URL}/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
body.data = [removeServerGeneratedProperties(body.data[0])]; | ||
// cursor is a constant changing value so we have to delete it as well. | ||
delete body.cursor; | ||
expect(body).to.eql({ | ||
data: [getListResponseMockWithoutAutoGeneratedValues()], | ||
page: 1, | ||
per_page: 20, | ||
total: 1, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.