import http from 'http' ; import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../../../../common/ftr_provider_context' ; import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib' ; import { getServiceNowConnector , createConnector , createConfiguration , getConfiguration , getConfigurationRequest , removeServerGeneratedPropertiesFromSavedObject , getConfigurationOutput , getAuthWithSuperUser , getServiceNowSimulationServer , } from '../../../../common/lib/utils' ; import { ConnectorTypes } from '../../../../../../plugins/cases/common/api' ; import { nullUser } from '../../../../common/lib/mock' ; export default ( { getService } ) : void => { const supertest = getService ( 'supertest' ) ; const actionsRemover = new ActionsRemover ( supertest ) ; const authSpace1 = getAuthWithSuperUser ( ) ; describe ( 'get_configure' , ( ) => { let serviceNowSimulatorURL = '' ; let serviceNowServer ; before ( async ( ) => { const { server , url } = await getServiceNowSimulationServer ( ) ; serviceNowServer = server ; serviceNowSimulatorURL = url ; } ) ; afterEach ( async ( ) => { await actionsRemover . removeAll ( ) ; } ) ; after ( async ( ) => { serviceNowServer . close ( ) ; } ) ; it ( 'should return a configuration with a mapping from space1' , async ( ) => { const connector = await createConnector ( { supertest , req : { ... getServiceNowConnector ( ) , config : { apiUrl : serviceNowSimulatorURL } , } , auth : authSpace1 , } ) ; actionsRemover . add ( 'space1' , connector . id , 'action' , 'actions' ) ; await createConfiguration ( supertest , getConfigurationRequest ( { id : connector . id , name : connector . name , type : connector . connector_type_id as ConnectorTypes , } ) , 200 , authSpace1 ) ; const configuration = await getConfiguration ( { supertest , auth : authSpace1 } ) ; const data = removeServerGeneratedPropertiesFromSavedObject ( configuration [ 0 ] ) ; expect ( data ) . to . eql ( getConfigurationOutput ( false , { mappings : [ { action_type : 'overwrite' , source : 'title' , target : 'short_description' , } , { action_type : 'overwrite' , source : 'description' , target : 'description' , } , { action_type : 'append' , source : 'comments' , target : 'work_notes' , } , ] , connector : { id : connector . id , name : connector . name , type : connector . connector_type_id , fields : null , } , created_by : nullUser , } ) ) ; } ) ; it ( 'should not return a configuration with a mapping from a different space' , async ( ) => { const connector = await createConnector ( { supertest , req : { ... getServiceNowConnector ( ) , config : { apiUrl : serviceNowSimulatorURL } , } , auth : authSpace1 , } ) ; actionsRemover . add ( 'space1' , connector . id , 'action' , 'actions' ) ; await createConfiguration ( supertest , getConfigurationRequest ( { id : connector . id , name : connector . name , type : connector . connector_type_id as ConnectorTypes , } ) , 200 , authSpace1 ) ; const configuration = await getConfiguration ( { supertest , auth : getAuthWithSuperUser ( 'space2' ) , } ) ; expect ( configuration ) . to . eql ( [ ] ) ; } ) ; } ) ; } ;