import expect from '@kbn/expect' ; import type { ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types' ; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants' ; import { getExceptionResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/exception_list_schema.mock' ; import { getCreateExceptionListMinimalSchemaMock , getCreateExceptionListMinimalSchemaMockWithoutId , } from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { deleteAllExceptions , removeExceptionListServerGeneratedProperties } from '../../utils' ; export default ( { getService } ) => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'delete_exception_lists' , ( ) => { describe ( 'delete exception lists' , ( ) => { afterEach ( async ( ) => { await deleteAllExceptions ( supertest , log ) ; } ) ; it ( 'should delete a single exception list by its list_id' , async ( ) => { await supertest . post ( EXCEPTION_LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListMinimalSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . delete ( `${ EXCEPTION_LIST_URL }?list_id=${ getCreateExceptionListMinimalSchemaMock ( ) . list_id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const bodyToCompare = removeExceptionListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getExceptionResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should delete a single exception list using an auto generated id' , async ( ) => { const { body : bodyWithCreatedList } = await supertest . post ( EXCEPTION_LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListMinimalSchemaMockWithoutId ( ) ) . expect ( 200 ) ; const { body } = await supertest . delete ( `${ EXCEPTION_LIST_URL }?id=${ bodyWithCreatedList . id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const outputtedList = { ... getExceptionResponseMockWithoutAutoGeneratedValues ( ) , list_id : body . list_id , } ; const bodyToCompare = removeExceptionListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( outputtedList ) ; } ) ; it ( 'should return an error if the id does not exist when trying to delete it' , async ( ) => { const { body } = await supertest . delete ( `${ EXCEPTION_LIST_URL }?id=c1e1b359-7ac1-4e96-bc81-c683c092436f` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 404 ) ; expect ( body ) . to . eql ( { message : 'exception list id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist' , status_code : 404 , } ) ; } ) ; it ( 'should return an error if the list_id does not exist when trying to delete it' , async ( ) => { const { body } = await supertest . delete ( `${ EXCEPTION_LIST_URL }?list_id=c1e1b359-7ac1-4e96-bc81-c683c092436f` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 404 ) ; expect ( body ) . to . eql ( { message : 'exception list list_id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist' , status_code : 404 , } ) ; } ) ; } ) ; } ) ; } ;