import { fakeServer , SinonFakeServer } from 'sinon' ; import { API_BASE_PATH } from '../../../common/constants' ; import { ListNodesRouteResponse , ListSnapshotReposResponse , NodesDetailsResponse , } from '../../../common/types' ; import { getDefaultHotPhasePolicy } from '../edit_policy/constants' ; export const init = ( ) => { const server = fakeServer . create ( ) ; server . respondImmediately = true ; server . respondWith ( [ 200 , { } , 'DefaultServerResponse' ] ) ; return { server , httpRequestsMockHelpers : registerHttpRequestMockHelpers ( server ) , } ; } ; const registerHttpRequestMockHelpers = ( server ) => { const setLoadPolicies = ( response = [ ] ) => { server . respondWith ( 'GET' , `${ API_BASE_PATH }/policies` , [ 200 , { 'Content-Type' : 'application/json' } , JSON . stringify ( response ) , ] ) ; } ; const setLoadSnapshotPolicies = ( response = [ ] , error ? ) => { const status = error ? error . status : 200 ; const body = error ? error . body : response ; server . respondWith ( 'GET' , `${ API_BASE_PATH }/snapshot_policies` , [ status , { 'Content-Type' : 'application/json' } , JSON . stringify ( body ) , ] ) ; } ; const setListNodes = ( body ) => { server . respondWith ( 'GET' , `${ API_BASE_PATH }/nodes/list` , [ 200 , { 'Content-Type' : 'application/json' } , JSON . stringify ( body ) , ] ) ; } ; const setNodesDetails = ( nodeAttributes , body ) => { server . respondWith ( 'GET' , `${ API_BASE_PATH }/nodes/${ nodeAttributes }/details` , [ 200 , { 'Content-Type' : 'application/json' } , JSON . stringify ( body ) , ] ) ; } ; const setListSnapshotRepos = ( body ) => { server . respondWith ( 'GET' , `${ API_BASE_PATH }/snapshot_repositories` , [ 200 , { 'Content-Type' : 'application/json' } , JSON . stringify ( body ) , ] ) ; } ; const setDefaultResponses = ( ) => { setLoadPolicies ( [ getDefaultHotPhasePolicy ( ) ] ) ; setLoadSnapshotPolicies ( [ ] ) ; setListSnapshotRepos ( { repositories : [ 'abc' ] } ) ; setListNodes ( { nodesByRoles : { } , nodesByAttributes : { test : [ '123' ] } , isUsingDeprecatedDataRoleConfig : false , } ) ; } ; return { setLoadPolicies , setLoadSnapshotPolicies , setListNodes , setNodesDetails , setListSnapshotRepos , setDefaultResponses , } ; } ;