import { newJobCapsService } from './new_job_capabilities_service' ; import type { DataView } from '../../../../../../../src/plugins/data_views/public' ; import mockCloudwatchResponse from '../__mocks__/cloudwatch_job_caps_response.json' ; jest . mock ( '../ml_api_service' , ( ) => ( { ml : { jobs : { newJobCaps : jest . fn ( ( ) => Promise . resolve ( mockCloudwatchResponse ) ) , } , } , } ) ) ; const dataView = { id : 'cloudwatch-*' , title : 'cloudwatch-*' , } as unknown as DataView ; describe ( 'new_job_capabilities_service' , ( ) => { describe ( 'cloudwatch newJobCaps()' , ( ) => { it ( 'can construct job caps objects from endpoint json' , async ( ) => { await newJobCapsService . initializeFromDataVIew ( dataView ) ; const { fields , aggs } = await newJobCapsService . newJobCaps ; const networkOutField = fields . find ( ( f ) => f . id === 'NetworkOut' ) || { aggs : [ ] } ; const regionField = fields . find ( ( f ) => f . id === 'region' ) || { aggs : [ ] } ; const meanAgg = aggs . find ( ( a ) => a . id === 'mean' ) || { fields : [ ] } ; const distinctCountAgg = aggs . find ( ( a ) => a . id === 'distinct_count' ) || { fields : [ ] } ; expect ( fields ) . toHaveLength ( 12 ) ; expect ( aggs ) . toHaveLength ( 35 ) ; expect ( networkOutField . aggs ) . toHaveLength ( 25 ) ; expect ( regionField . aggs ) . toHaveLength ( 3 ) ; expect ( meanAgg . fields ) . toHaveLength ( 7 ) ; expect ( distinctCountAgg . fields ) . toHaveLength ( 10 ) ; } ) ; it ( 'job caps including text fields' , async ( ) => { await newJobCapsService . initializeFromDataVIew ( dataView , true , false ) ; const { fields , aggs } = await newJobCapsService . newJobCaps ; expect ( fields ) . toHaveLength ( 13 ) ; expect ( aggs ) . toHaveLength ( 35 ) ; } ) ; it ( 'job caps excluding event rate' , async ( ) => { await newJobCapsService . initializeFromDataVIew ( dataView , false , true ) ; const { fields , aggs } = await newJobCapsService . newJobCaps ; expect ( fields ) . toHaveLength ( 11 ) ; expect ( aggs ) . toHaveLength ( 35 ) ; } ) ; } ) ; } ) ;