import expect from '@kbn/expect' ; import type { GetTransformNodesResponseSchema } from '../../../../plugins/transform/common/api_schemas/transforms' ; import { isGetTransformNodesResponseSchema } from '../../../../plugins/transform/common/api_schemas/type_guards' ; import { COMMON_REQUEST_HEADERS } from '../../../functional/services/ml/common_api' ; import { USER } from '../../../functional/services/transform/security_common' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export default ( { getService } ) => { const supertest = getService ( 'supertestWithoutAuth' ) ; const transform = getService ( 'transform' ) ; const expected = { apiTransformTransformsNodes : { minCount : 1 , } , } ; function assertTransformsNodesResponseBody ( body ) { expect ( isGetTransformNodesResponseSchema ( body ) ) . to . eql ( true ) ; expect ( body . count ) . to . not . be . lessThan ( expected . apiTransformTransformsNodes . minCount ) ; } describe ( '/api/transform/transforms/_nodes' , function ( ) { it ( 'should return the number of available transform nodes for a power user' , async ( ) => { const { body } = await supertest . get ( '/api/transform/transforms/_nodes' ) . auth ( USER . TRANSFORM_POWERUSER , transform . securityCommon . getPasswordForUser ( USER . TRANSFORM_POWERUSER ) ) . set ( COMMON_REQUEST_HEADERS ) . send ( ) . expect ( 200 ) ; assertTransformsNodesResponseBody ( body ) ; } ) ; it ( 'should return the number of available transform nodes for a viewer user' , async ( ) => { const { body } = await supertest . get ( '/api/transform/transforms/_nodes' ) . auth ( USER . TRANSFORM_VIEWER , transform . securityCommon . getPasswordForUser ( USER . TRANSFORM_VIEWER ) ) . set ( COMMON_REQUEST_HEADERS ) . send ( ) . expect ( 200 ) ; assertTransformsNodesResponseBody ( body ) ; } ) ; it ( 'should not return the number of available transform nodes for an unauthorized user' , async ( ) => { await supertest . get ( '/api/transform/transforms/_nodes' ) . auth ( USER . TRANSFORM_UNAUTHORIZED , transform . securityCommon . getPasswordForUser ( USER . TRANSFORM_UNAUTHORIZED ) ) . set ( COMMON_REQUEST_HEADERS ) . send ( ) . expect ( 403 ) ; } ) ; } ) ; } ;