import type { PublicMethodsOf } from '@osd/utility-types' ; import { HttpService } from './http_service' ; import { HttpSetup } from './types' ; import { BehaviorSubject } from 'rxjs' ; import { BasePath } from './base_path' ; export type HttpSetupMock = jest . Mocked < HttpSetup > & { basePath : BasePath ; anonymousPaths : jest . Mocked < HttpSetup [ 'anonymousPaths' ] > ; } ; const createServiceMock = ( { basePath = '' } = { } ) : HttpSetupMock => ( { fetch : jest . fn ( ) , get : jest . fn ( ) , head : jest . fn ( ) , post : jest . fn ( ) , put : jest . fn ( ) , patch : jest . fn ( ) , delete : jest . fn ( ) , options : jest . fn ( ) , basePath : new BasePath ( basePath ) , anonymousPaths : { register : jest . fn ( ) , isAnonymous : jest . fn ( ) , } , addLoadingCountSource : jest . fn ( ) , getLoadingCount$ : jest . fn ( ) . mockReturnValue ( new BehaviorSubject ( 0 ) ) , intercept : jest . fn ( ) , } ) ; const createMock = ( { basePath = '' } = { } ) => { const mocked = { setup : jest . fn ( ) , start : jest . fn ( ) , stop : jest . fn ( ) , } ; mocked . setup . mockReturnValue ( createServiceMock ( { basePath } ) ) ; mocked . start . mockReturnValue ( createServiceMock ( { basePath } ) ) ; return mocked ; } ; export const httpServiceMock = { create : createMock , createSetupContract : createServiceMock , createStartContract : createServiceMock , } ;