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 { getListResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/list_schema.mock' ; import { createListsIndex , deleteListsIndex , removeListServerGeneratedProperties , } from '../../utils' ; export default ( { getService } ) => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'create_lists' , ( ) => { describe ( 'creating lists' , ( ) => { beforeEach ( async ( ) => { await createListsIndex ( supertest , log ) ; } ) ; afterEach ( async ( ) => { await deleteListsIndex ( supertest , log ) ; } ) ; it ( 'should create a simple list with a list_id' , async ( ) => { const { body } = await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const bodyToCompare = removeListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getListResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should create a simple list without a list_id' , async ( ) => { const { body } = await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMockWithoutId ( ) ) . expect ( 200 ) ; const bodyToCompare = removeListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getListResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should cause a 409 conflict if we attempt to create the same list_id twice' , async ( ) => { await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 409 ) ; expect ( body ) . to . eql ( { message : 'list id: "some-list-id" already exists' , status_code : 409 , } ) ; } ) ; } ) ; } ) ; } ;