import expect from '@kbn/expect' ; import type { UpdateListSchema , ListSchema } from '@kbn/securitysolution-io-ts-list-types' ; import { LIST_URL } from '@kbn/securitysolution-list-constants' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { getCreateMinimalListSchemaMock } 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' ; import { getUpdateMinimalListSchemaMock } from '../../../../plugins/lists/common/schemas/request/update_list_schema.mock' ; export default ( { getService } ) => { const supertest = getService ( 'supertest' ) ; const log = getService ( 'log' ) ; describe ( 'update_lists' , ( ) => { describe ( 'update lists' , ( ) => { beforeEach ( async ( ) => { await createListsIndex ( supertest , log ) ; } ) ; afterEach ( async ( ) => { await deleteListsIndex ( supertest , log ) ; } ) ; it ( 'should update a single list property of name using an id' , async ( ) => { await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const updatedList = { ... getUpdateMinimalListSchemaMock ( ) , name : 'some other name' , } ; const { body } = await supertest . put ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( updatedList ) . expect ( 200 ) ; const outputList = { ... getListResponseMockWithoutAutoGeneratedValues ( ) , name : 'some other name' , version : 2 , } ; const bodyToCompare = removeListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( outputList ) ; } ) ; it ( 'should update a single list property of name using an auto-generated id' , async ( ) => { const { id , ... listNoId } = getCreateMinimalListSchemaMock ( ) ; const { body : createListBody } = await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( listNoId ) . expect ( 200 ) ; const updatedList = { ... getUpdateMinimalListSchemaMock ( ) , id : createListBody . id , name : 'some other name' , } ; const { body } = await supertest . put ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( updatedList ) . expect ( 200 ) ; const outputList = { ... getListResponseMockWithoutAutoGeneratedValues ( ) , name : 'some other name' , version : 2 , } ; const bodyToCompare = removeListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( outputList ) ; } ) ; it ( 'should change the version of a list when it updates a property' , async ( ) => { await supertest . post ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( getCreateMinimalListSchemaMock ( ) ) . expect ( 200 ) ; const updatedList = { ... getUpdateMinimalListSchemaMock ( ) , name : 'some other name' , description : 'some other description' , } ; const { body } = await supertest . put ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( updatedList ) ; const outputList = { ... getListResponseMockWithoutAutoGeneratedValues ( ) , name : 'some other name' , description : 'some other description' , version : 2 , } ; const bodyToCompare = removeListServerGeneratedProperties ( body ) ; expect ( bodyToCompare ) . to . eql ( outputList ) ; } ) ; it ( 'should give a 404 if it is given a fake id' , async ( ) => { const simpleList = { ... getUpdateMinimalListSchemaMock ( ) , id : '5096dec6-b6b9-4d8d-8f93-6c2602079d9d' , } ; const { body } = await supertest . put ( LIST_URL ) . set ( 'kbn-xsrf' , 'true' ) . send ( simpleList ) . expect ( 404 ) ; expect ( body ) . to . eql ( { status_code : 404 , message : 'list id: "5096dec6-b6b9-4d8d-8f93-6c2602079d9d" not found' , } ) ; } ) ; } ) ; } ) ; } ;