import url from 'url' ; import expect from '@kbn/expect' ; import { omit } from 'lodash' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import archives from '../../common/fixtures/es_archiver/archives_metadata' ; import { APIReturnType } from '../../../../plugins/apm/public/services/rest/createCallApmApi' ; import { getServiceNodeIds } from './get_service_node_ids' ; import { createApmApiClient } from '../../common/apm_api_supertest' ; type ServiceOverviewInstanceDetails = APIReturnType < 'GET /internal/apm/services/{serviceName}/service_overview_instances/details/{serviceNodeName}' > ; export default function ApiTest ( { getService } ) { const registry = getService ( 'registry' ) ; const supertest = getService ( 'legacySupertestAsApmReadUser' ) ; const apmApiSupertest = createApmApiClient ( supertest ) ; const archiveName = 'apm_8.0.0' ; const { start , end } = archives [ archiveName ] ; registry . when ( 'Instance details when data is not loaded' , { config : 'basic' , archives : [ ] } , ( ) => { describe ( 'when data is not loaded' , ( ) => { it ( 'handles empty state' , async ( ) => { const response = await supertest . get ( url . format ( { pathname : '/internal/apm/services/opbeans-java/service_overview_instances/details/foo' , query : { start , end , } , } ) ) ; expect ( response . status ) . to . be ( 200 ) ; expect ( response . body ) . to . eql ( { } ) ; } ) ; } ) ; } ) ; registry . when . skip ( 'Instance details when data is loaded' , { config : 'basic' , archives : [ archiveName ] } , ( ) => { describe . skip ( 'fetch instance details' , ( ) => { let response ; let serviceNodeIds ; before ( async ( ) => { serviceNodeIds = await getServiceNodeIds ( { apmApiSupertest , start , end } ) ; response = await supertest . get ( url . format ( { pathname : `/internal/apm/services/opbeans-java/service_overview_instances/details/${ serviceNodeIds [ 0 ] }` , query : { start , end , } , } ) ) ; } ) ; it ( 'returns the instance details' , ( ) => { expect ( response . body ) . to . not . eql ( { } ) ; } ) ; it ( 'return the correct data' , ( ) => { expectSnapshot ( omit ( response . body , '@timestamp' ) ) . toMatch ( ) ; } ) ; } ) ; } ) ; registry . when ( 'Instance details when data is loaded but details not found' , { config : 'basic' , archives : [ archiveName ] } , ( ) => { it ( 'handles empty state when instance id not found' , async ( ) => { const response = await supertest . get ( url . format ( { pathname : '/internal/apm/services/opbeans-java/service_overview_instances/details/foo' , query : { start , end , } , } ) ) ; expect ( response . status ) . to . be ( 200 ) ; expect ( response . body ) . to . eql ( { } ) ; } ) ; } ) ; }