import supertest from 'supertest' ; import { UnwrapPromise } from '@osd/utility-types' ; import { registerDeleteRoute } from '../delete' ; import { savedObjectsClientMock } from '../../../../../core/server/mocks' ; import { setupServer } from '../test_utils' ; type SetupServerReturn = UnwrapPromise < ReturnType < typeof setupServer > > ; describe ( 'DELETE /api/saved_objects/{type}/{id}' , ( ) => { let server ; let httpSetup ; let handlerContext ; let savedObjectsClient ; beforeEach ( async ( ) => { ( { server , httpSetup , handlerContext } = await setupServer ( ) ) ; savedObjectsClient = handlerContext . savedObjects . client ; const router = httpSetup . createRouter ( '/api/saved_objects/' ) ; registerDeleteRoute ( router ) ; await server . start ( ) ; } ) ; afterEach ( async ( ) => { await server . stop ( ) ; } ) ; it ( 'formats successful response' , async ( ) => { const result = await supertest ( httpSetup . server . listener ) . delete ( '/api/saved_objects/index-pattern/logstash-*' ) . expect ( 200 ) ; expect ( result . body ) . toEqual ( { } ) ; } ) ; it ( 'calls upon savedObjectClient.delete' , async ( ) => { await supertest ( httpSetup . server . listener ) . delete ( '/api/saved_objects/index-pattern/logstash-*' ) . expect ( 200 ) ; expect ( savedObjectsClient . delete ) . toHaveBeenCalledWith ( 'index-pattern' , 'logstash-*' , { force : undefined , } ) ; } ) ; it ( 'can specify `force` option' , async ( ) => { await supertest ( httpSetup . server . listener ) . delete ( '/api/saved_objects/index-pattern/logstash-*' ) . query ( { force : true } ) . expect ( 200 ) ; expect ( savedObjectsClient . delete ) . toHaveBeenCalledWith ( 'index-pattern' , 'logstash-*' , { force : true , } ) ; } ) ; } ) ;