import expect from '@kbn/expect' ; import { LIST_URL } from '@kbn/securitysolution-list-constants' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { getCreateMinimalListSchemaMock , getCreateMinimalListSchemaMockWithoutId , } from '../../../../plugins/lists/common/schemas/request/create_list_schema.mock' ; import { createListsIndex , deleteListsIndex , removeListServerGeneratedProperties , } from '../../utils' ; import { getListResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_schema.mock' ; export default ( { getService } ) => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'read_lists' , ( ) => { describe ( 'reading lists' , ( ) => { beforeEach ( async ( ) => { await createListsIndex ( supertest , log ) ; } ) ; afterEach ( async ( ) => { await deleteListsIndex ( supertest , log ) ; } ) ; it ( 'should be able to read a single list using id' , async ( ) => { await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ LIST_URL }?id=${ getCreateMinimalListSchemaMock ( ) . id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const bodyToCompare = removeListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getListResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should be able to read a single list with an auto-generated list id' , async ( ) => { 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' ) . expect ( 200 ) ; const bodyToCompare = removeListServerGeneratedProperties ( 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' , } ) ; } ) ; } ) ; } ) ; } ;