import { BehaviorSubject } from 'rxjs' ; import type { PublicMethodsOf } from '@osd/utility-types' ; import { SavedObjectsService , InternalSavedObjectsServiceSetup , InternalSavedObjectsServiceStart , SavedObjectsServiceSetup , SavedObjectsServiceStart , } from './saved_objects_service' ; import { savedObjectsRepositoryMock } from './service/lib/repository.mock' ; import { savedObjectsClientMock } from './service/saved_objects_client.mock' ; import { typeRegistryMock } from './saved_objects_type_registry.mock' ; import { migrationMocks } from './migrations/mocks' ; import { ServiceStatusLevels } from '../status' ; import { ISavedObjectTypeRegistry } from './saved_objects_type_registry' ; type SavedObjectsServiceContract = PublicMethodsOf < SavedObjectsService > ; const createStartContractMock = ( typeRegistry ? ) => { const startContrat = { getScopedClient : jest . fn ( ) , createInternalRepository : jest . fn ( ) , createScopedRepository : jest . fn ( ) , createSerializer : jest . fn ( ) , getTypeRegistry : jest . fn ( ) , } ; startContrat . getScopedClient . mockReturnValue ( savedObjectsClientMock . create ( ) ) ; startContrat . createInternalRepository . mockReturnValue ( savedObjectsRepositoryMock . create ( ) ) ; startContrat . createScopedRepository . mockReturnValue ( savedObjectsRepositoryMock . create ( ) ) ; startContrat . getTypeRegistry . mockReturnValue ( typeRegistry ?? typeRegistryMock . create ( ) ) ; return startContrat ; } ; const createInternalStartContractMock = ( typeRegistry ? ) => { const internalStartContract = createStartContractMock ( typeRegistry ) ; return internalStartContract ; } ; const createSetupContractMock = ( ) => { const setupContract = { setClientFactoryProvider : jest . fn ( ) , addClientWrapper : jest . fn ( ) , registerType : jest . fn ( ) , getImportExportObjectLimit : jest . fn ( ) , } ; setupContract . getImportExportObjectLimit . mockReturnValue ( 100 ) ; return setupContract ; } ; const createInternalSetupContractMock = ( ) => { const internalSetupContract = { ... createSetupContractMock ( ) , status$ : new BehaviorSubject ( { level : ServiceStatusLevels . available , summary : `SavedObjects is available` , } ) , } ; return internalSetupContract ; } ; const createSavedObjectsServiceMock = ( ) => { const mocked = { setup : jest . fn ( ) , start : jest . fn ( ) , stop : jest . fn ( ) , } ; mocked . setup . mockResolvedValue ( createInternalSetupContractMock ( ) ) ; mocked . start . mockResolvedValue ( createInternalStartContractMock ( ) ) ; mocked . stop . mockResolvedValue ( ) ; return mocked ; } ; export const savedObjectsServiceMock = { create : createSavedObjectsServiceMock , createInternalSetupContract : createInternalSetupContractMock , createSetupContract : createSetupContractMock , createInternalStartContract : createInternalStartContractMock , createStartContract : createStartContractMock , createMigrationContext : migrationMocks . createContext , createTypeRegistryMock : typeRegistryMock . create , } ;