-
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.
- Loading branch information
1 parent
11c0ebb
commit 3e0e4bf
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
x-pack/test/lists_api_integration/security_and_spaces/tests/find_list_items.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,116 @@ | ||
/* | ||
* 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 { LIST_ITEM_ID, LIST_ID } from '../../../../plugins/lists/common/constants.mock'; | ||
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): void => { | ||
const supertest = getService('supertest'); | ||
|
||
describe('find_list_items', () => { | ||
describe('find list items', () => { | ||
beforeEach(async () => { | ||
await createListsIndex(supertest); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteListsIndex(supertest); | ||
}); | ||
|
||
it('should give a validation error if the list_id is not supplied', async () => { | ||
const { body } = await supertest | ||
.get(`${LIST_ITEM_URL}/_find`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(400); | ||
|
||
expect(body).to.eql({ | ||
error: 'Bad Request', | ||
message: '[request query]: Invalid value "undefined" supplied to "list_id"', | ||
statusCode: 400, | ||
}); | ||
}); | ||
|
||
it('should give a 404 if the list has not been created yet', async () => { | ||
const { body } = await supertest | ||
.get(`${LIST_ITEM_URL}/_find?list_id=${LIST_ITEM_ID}`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(404); | ||
|
||
expect(body).to.eql({ | ||
message: 'list id: "some-list-item-id" does not exist', | ||
status_code: 404, | ||
}); | ||
}); | ||
|
||
it('should return an empty find body correctly if no list items are loaded', async () => { | ||
await supertest | ||
.post(LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateMinimalListSchemaMock()) | ||
.expect(200); | ||
|
||
const { body } = await supertest | ||
.get(`${LIST_ITEM_URL}/_find?list_id=${LIST_ID}`) | ||
.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 item when a single list item is loaded from a find with defaults added', async () => { | ||
await supertest | ||
.post(LIST_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateMinimalListSchemaMock()) | ||
.expect(200); | ||
|
||
await supertest | ||
.post(LIST_ITEM_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getCreateMinimalListItemSchemaMock()) | ||
.expect(200); | ||
|
||
const { body } = await supertest | ||
.get(`${LIST_ITEM_URL}/_find?list_id=${LIST_ID}`) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
body.data = [removeListItemServerGeneratedProperties(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: [getListItemResponseMockWithoutAutoGeneratedValues()], | ||
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