import expect from '@kbn/expect' ; import { LIST_URL , LIST_ITEM_URL } from '@kbn/securitysolution-list-constants' ; 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 } ) => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'read_list_items' , ( ) => { describe ( 'reading list items' , ( ) => { beforeEach ( async ( ) => { await createListsIndex ( supertest , log ) ; } ) ; afterEach ( async ( ) => { await deleteListsIndex ( supertest , log ) ; } ) ; it ( 'should be able to read a single list item using id' , 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 }?id=${ getCreateMinimalListItemSchemaMock ( ) . id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const bodyToCompare = removeListItemServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getListItemResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should be able to read a single list item with an auto-generated list id' , async ( ) => { await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const { body : createListBody } = await supertest . post ( LIST_ITEM_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListItemSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ LIST_ITEM_URL }?id=${ createListBody . id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const bodyToCompare = removeListItemServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getListItemResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should return 404 if given a fake id' , async ( ) => { await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ LIST_ITEM_URL }?id=c1e1b359-7ac1-4e96-bc81-c683c092436f` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 404 ) ; expect ( body ) . to . eql ( { status_code : 404 , message : 'list item id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist' , } ) ; } ) ; } ) ; } ) ; } ;