import expect from '@kbn/expect' ; import { LIST_URL , LIST_ITEM_URL } from '@kbn/securitysolution-list-constants' ; 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 { getCreateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock' ; import { createListsIndex , deleteListsIndex , removeListItemServerGeneratedProperties , } from '../../utils' ; export default ( { getService } ) : void => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'find_list_items' , ( ) => { describe ( 'find list items' , ( ) => { beforeEach ( async ( ) => { await createListsIndex ( supertest , log ) ; } ) ; afterEach ( async ( ) => { await deleteListsIndex ( supertest , log ) ; } ) ; 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 ] ) ] ; delete body . cursor ; expect ( body ) . to . eql ( { data : [ getListItemResponseMockWithoutAutoGeneratedValues ( ) ] , page : 1 , per_page : 20 , total : 1 , } ) ; } ) ; } ) ; } ) ; } ;