import expect from '@kbn/expect' ; import type { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types' ; import { EXCEPTION_LIST_URL , EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants' ; import { getExceptionListItemResponseMockWithoutAutoGeneratedValues } from '../../../../plugins/lists/common/schemas/response/exception_list_item_schema.mock' ; import { getCreateExceptionListItemMinimalSchemaMock , getCreateExceptionListItemMinimalSchemaMockWithoutId , } from '../../../../plugins/lists/common/schemas/request/create_exception_list_item_schema.mock' ; import { getCreateExceptionListMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { deleteAllExceptions , removeExceptionListItemServerGeneratedProperties } from '../../utils' ; export default ( { getService } ) => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'read_exception_list_items' , ( ) => { describe ( 'reading exception list items' , ( ) => { afterEach ( async ( ) => { await deleteAllExceptions ( supertest , log ) ; } ) ; it ( 'should be able to read a single exception list items using item_id' , async ( ) => { await supertest . post ( EXCEPTION_LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListMinimalSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . post ( EXCEPTION_LIST_ITEM_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListItemMinimalSchemaMock ( ) ) . expect ( 200 ) ; const bodyToCompare = removeExceptionListItemServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getExceptionListItemResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should be able to read a single exception list item using id' , async ( ) => { await supertest . post ( EXCEPTION_LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListMinimalSchemaMock ( ) ) . expect ( 200 ) ; const { body : createListBody } = await supertest . post ( EXCEPTION_LIST_ITEM_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListItemMinimalSchemaMock ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ EXCEPTION_LIST_ITEM_URL }?id=${ createListBody . id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const bodyToCompare = removeExceptionListItemServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( getExceptionListItemResponseMockWithoutAutoGeneratedValues ( ) ) ; } ) ; it ( 'should be able to read a single list item with an auto-generated id' , async ( ) => { await supertest . post ( EXCEPTION_LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListMinimalSchemaMock ( ) ) . expect ( 200 ) ; const { body : createListBody } = await supertest . post ( EXCEPTION_LIST_ITEM_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListItemMinimalSchemaMockWithoutId ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ EXCEPTION_LIST_ITEM_URL }?id=${ createListBody . id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const outputtedList = { ... getExceptionListItemResponseMockWithoutAutoGeneratedValues ( ) , item_id : body . item_id , } ; const bodyToCompare = removeExceptionListItemServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( outputtedList ) ; } ) ; it ( 'should be able to read a single list item with an auto-generated item_id' , async ( ) => { await supertest . post ( EXCEPTION_LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListMinimalSchemaMock ( ) ) . expect ( 200 ) ; const { body : createListBody } = await supertest . post ( EXCEPTION_LIST_ITEM_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateExceptionListItemMinimalSchemaMockWithoutId ( ) ) . expect ( 200 ) ; const { body } = await supertest . get ( `${ EXCEPTION_LIST_ITEM_URL }?item_id=${ createListBody . item_id }` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 200 ) ; const outputtedList = { ... getExceptionListItemResponseMockWithoutAutoGeneratedValues ( ) , item_id : body . item_id , } ; const bodyToCompare = removeExceptionListItemServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( outputtedList ) ; } ) ; it ( 'should return 404 if given a fake id' , async ( ) => { const { body } = await supertest . get ( `${ EXCEPTION_LIST_ITEM_URL }?id=c1e1b359-7ac1-4e96-bc81-c683c092436f` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 404 ) ; expect ( body ) . to . eql ( { status_code : 404 , message : 'exception list item id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist' , } ) ; } ) ; it ( 'should return 404 if given a fake list_id' , async ( ) => { const { body } = await supertest . get ( `${ EXCEPTION_LIST_ITEM_URL }?item_id=c1e1b359-7ac1-4e96-bc81-c683c092436f` ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 404 ) ; expect ( body ) . to . eql ( { status_code : 404 , message : 'exception list item item_id: "c1e1b359-7ac1-4e96-bc81-c683c092436f" does not exist' , } ) ; } ) ; } ) ; } ) ; } ;