import { newJobCapsProvider } from './index' ; import farequoteFieldCaps from './__mocks__/responses/farequote_field_caps.json' ; import cloudwatchFieldCaps from './__mocks__/responses/cloudwatch_field_caps.json' ; import rollupCaps from './__mocks__/responses/rollup_caps.json' ; import dataView from './__mocks__/responses/data_view_rollup_cloudwatch.json' ; import farequoteJobCaps from './__mocks__/results/farequote_job_caps.json' ; import farequoteJobCapsEmpty from './__mocks__/results/farequote_job_caps_empty.json' ; import cloudwatchJobCaps from './__mocks__/results/cloudwatch_rollup_job_caps.json' ; describe ( 'job_service - job_caps' , ( ) => { let mlClusterClientNonRollupMock ; let mlClusterClientRollupMock ; let dataViews ; beforeEach ( ( ) => { const asNonRollupMock = { fieldCaps : jest . fn ( ( ) => ( { body : farequoteFieldCaps } ) ) , } ; mlClusterClientNonRollupMock = { asCurrentUser : asNonRollupMock , asInternalUser : asNonRollupMock , } ; const callAsRollupMock = { fieldCaps : jest . fn ( ( ) => ( { body : cloudwatchFieldCaps } ) ) , rollup : { getRollupIndexCaps : jest . fn ( ( ) => Promise . resolve ( { body : rollupCaps } ) ) } , } ; mlClusterClientRollupMock = { asCurrentUser : callAsRollupMock , asInternalUser : callAsRollupMock , } ; dataViews = { async find ( ) { return Promise . resolve ( dataView ) ; } , } ; } ) ; describe ( 'farequote newJobCaps()' , ( ) => { it ( 'can get job caps for index pattern' , async ( ) => { const indexPattern = 'farequote-*' ; const isRollup = false ; const { newJobCaps } = newJobCapsProvider ( mlClusterClientNonRollupMock ) ; const response = await newJobCaps ( indexPattern , isRollup , dataViews ) ; expect ( response ) . toEqual ( farequoteJobCaps ) ; } ) ; it ( 'can get rollup job caps for non rollup index pattern' , async ( ) => { const indexPattern = 'farequote-*' ; const isRollup = true ; const { newJobCaps } = newJobCapsProvider ( mlClusterClientNonRollupMock ) ; const response = await newJobCaps ( indexPattern , isRollup , dataViews ) ; expect ( response ) . toEqual ( farequoteJobCapsEmpty ) ; } ) ; } ) ; describe ( 'cloudwatch newJobCaps()' , ( ) => { it ( 'can get rollup job caps for rollup index pattern' , async ( ) => { const indexPattern = 'cloud_roll_index' ; const isRollup = true ; const { newJobCaps } = newJobCapsProvider ( mlClusterClientRollupMock ) ; const response = await newJobCaps ( indexPattern , isRollup , dataViews ) ; expect ( response ) . toEqual ( cloudwatchJobCaps ) ; } ) ; it ( 'can get non rollup job caps for rollup index pattern' , async ( ) => { const indexPattern = 'cloud_roll_index' ; const isRollup = false ; const { newJobCaps } = newJobCapsProvider ( mlClusterClientRollupMock ) ; const response = await newJobCaps ( indexPattern , isRollup , dataViews ) ; expect ( response ) . not . toEqual ( cloudwatchJobCaps ) ; } ) ; } ) ; } ) ;