import { createCloudUsageCollector } from './cloud_usage_collector' ; import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks' ; const mockUsageCollection = ( ) => ( { makeUsageCollector : jest . fn ( ) . mockImplementation ( ( args ) => ( { ... args } ) ) , } ) ; const getMockConfigs = ( isCloudEnabled ) => ( { isCloudEnabled } ) ; describe ( 'createCloudUsageCollector' , ( ) => { it ( 'calls `makeUsageCollector`' , ( ) => { const mockConfigs = getMockConfigs ( false ) ; const usageCollection = mockUsageCollection ( ) ; createCloudUsageCollector ( usageCollection as any , mockConfigs ) ; expect ( usageCollection . makeUsageCollector ) . toBeCalledTimes ( 1 ) ; } ) ; describe ( 'Fetched Usage data' , ( ) => { it ( 'return isCloudEnabled boolean' , async ( ) => { const mockConfigs = getMockConfigs ( true ) ; const usageCollection = mockUsageCollection ( ) as any ; const collector = createCloudUsageCollector ( usageCollection , mockConfigs ) ; const collectorFetchContext = createCollectorFetchContextMock ( ) ; expect ( ( await collector . fetch ( collectorFetchContext ) ) . isCloudEnabled ) . toBe ( true ) ; } ) ; } ) ; } ) ;