import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../../ftr_provider_context' ; import { USER } from '../../../../functional/services/ml/security_common' ; import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api' ; export default ( { getService } ) => { const supertest = getService ( 'supertestWithoutAuth' ) ; const ml = getService ( 'ml' ) ; describe ( 'GET trained_models/pipelines' , ( ) => { let testModelIds = [ ] ; before ( async ( ) => { await ml . testResources . setKibanaTimeZoneToUTC ( ) ; testModelIds = await ml . api . createTestTrainedModels ( 'regression' , 2 , true ) ; } ) ; after ( async ( ) => { await Promise . all ( testModelIds . map ( ( modelId ) => ml . api . deleteIngestPipeline ( modelId ) ) ) ; await ml . api . cleanMlIndices ( ) ; } ) ; it ( 'returns trained model pipelines by id' , async ( ) => { const { body } = await supertest . get ( `/api/ml/trained_models/dfa_regression_model_n_0/pipelines` ) . auth ( USER . ML_POWERUSER , ml . securityCommon . getPasswordForUser ( USER . ML_POWERUSER ) ) . set ( COMMON_REQUEST_HEADERS ) . expect ( 200 ) ; expect ( body . length ) . to . eql ( 1 ) ; expect ( body [ 0 ] . model_id ) . to . eql ( 'dfa_regression_model_n_0' ) ; expect ( Object . keys ( body [ 0 ] . pipelines ) . length ) . to . eql ( 1 ) ; } ) ; it ( 'returns an error in case user does not have required permission' , async ( ) => { await supertest . get ( `/api/ml/trained_models/dfa_regression_model_n_0/pipelines` ) . auth ( USER . ML_VIEWER , ml . securityCommon . getPasswordForUser ( USER . ML_VIEWER ) ) . set ( COMMON_REQUEST_HEADERS ) . expect ( 403 ) ; } ) ; } ) ; } ;