diff --git a/src/plugins/home/server/services/sample_data/usage/collector_fetch.test.ts b/src/plugins/home/server/services/sample_data/usage/collector_fetch.test.ts index 54df964e4bdec..fcf49eb7f744d 100644 --- a/src/plugins/home/server/services/sample_data/usage/collector_fetch.test.ts +++ b/src/plugins/home/server/services/sample_data/usage/collector_fetch.test.ts @@ -19,8 +19,10 @@ const getMockFetchClients = (hits?: unknown[]) => { describe('Sample Data Fetch', () => { let collectorFetchContext: CollectorFetchContext; + const getIndexForType = (index: string) => (type: string) => Promise.resolve(index); + test('uninitialized .kibana', async () => { - const fetch = fetchProvider('index'); + const fetch = fetchProvider(getIndexForType('index')); collectorFetchContext = getMockFetchClients(); const telemetry = await fetch(collectorFetchContext); @@ -28,7 +30,7 @@ describe('Sample Data Fetch', () => { }); test('installed data set', async () => { - const fetch = fetchProvider('index'); + const fetch = fetchProvider(getIndexForType('index')); collectorFetchContext = getMockFetchClients([ { _id: 'sample-data-telemetry:test1', @@ -55,7 +57,7 @@ Object { }); test('multiple installed data sets', async () => { - const fetch = fetchProvider('index'); + const fetch = fetchProvider(getIndexForType('index')); collectorFetchContext = getMockFetchClients([ { _id: 'sample-data-telemetry:test1', @@ -90,7 +92,7 @@ Object { }); test('installed data set, missing counts', async () => { - const fetch = fetchProvider('index'); + const fetch = fetchProvider(getIndexForType('index')); collectorFetchContext = getMockFetchClients([ { _id: 'sample-data-telemetry:test1', @@ -112,7 +114,7 @@ Object { }); test('installed and uninstalled data sets', async () => { - const fetch = fetchProvider('index'); + const fetch = fetchProvider(getIndexForType('index')); collectorFetchContext = getMockFetchClients([ { _id: 'sample-data-telemetry:test0', diff --git a/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/get_saved_object_counts/get_saved_object_counts.test.ts b/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/get_saved_object_counts/get_saved_object_counts.test.ts index 173453e9e2420..dee08d70ddf86 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/get_saved_object_counts/get_saved_object_counts.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/get_saved_object_counts/get_saved_object_counts.test.ts @@ -20,7 +20,7 @@ describe('getSavedObjectsCounts', () => { test('should not fail if no body returned', async () => { const esClient = mockGetSavedObjectsCounts({}); - const results = await getSavedObjectsCounts(esClient, '.kibana', ['type-a']); + const results = await getSavedObjectsCounts(esClient, ['.kibana'], ['type-a']); // Make sure ES.search is triggered (we'll test the actual params in other specific tests) expect(esClient.search).toHaveBeenCalledTimes(1); expect(results).toStrictEqual({ total: 0, per_type: [], non_expected_types: [], others: 0 }); @@ -28,9 +28,9 @@ describe('getSavedObjectsCounts', () => { test('should match all and request the `missing` bucket (size + 1) when `exclusive === false`', async () => { const esClient = mockGetSavedObjectsCounts({}); - await getSavedObjectsCounts(esClient, '.kibana', ['type-a', 'type_2']); + await getSavedObjectsCounts(esClient, ['.kibana'], ['type-a', 'type_2']); expect(esClient.search).toHaveBeenCalledWith({ - index: '.kibana', + index: ['.kibana'], ignore_unavailable: true, filter_path: [ 'aggregations.types.buckets', @@ -56,9 +56,9 @@ describe('getSavedObjectsCounts', () => { test('should apply the terms query and aggregation with the size matching the length of the list when `exclusive === true`', async () => { const esClient = mockGetSavedObjectsCounts({}); - await getSavedObjectsCounts(esClient, '.kibana', ['type_one', 'type_two'], true); + await getSavedObjectsCounts(esClient, ['.kibana'], ['type_one', 'type_two'], true); expect(esClient.search).toHaveBeenCalledWith({ - index: '.kibana', + index: ['.kibana'], ignore_unavailable: true, filter_path: [ 'aggregations.types.buckets', @@ -85,11 +85,11 @@ describe('getSavedObjectsCounts', () => { aggregations: { types: { buckets, sum_other_doc_count: 10 } }, }); - const results = await getSavedObjectsCounts(esClient, '.kibana', [ - 'type_one', - 'type-two', - 'type-3', - ]); + const results = await getSavedObjectsCounts( + esClient, + ['.kibana'], + ['type_one', 'type-two', 'type-3'] + ); expect(results).toStrictEqual({ total: 13, per_type: [ @@ -112,7 +112,7 @@ describe('getSavedObjectsCounts', () => { aggregations: { types: { buckets, sum_other_doc_count: 10 } }, }); - const results = await getSavedObjectsCounts(esClient, '.kibana', ['type_one', 'type-two']); + const results = await getSavedObjectsCounts(esClient, ['.kibana'], ['type_one', 'type-two']); expect(results).toStrictEqual({ total: 13, per_type: [ @@ -137,7 +137,7 @@ describe('getSavedObjectsCounts', () => { aggregations: { types: { buckets, sum_other_doc_count: 6 } }, }); - const results = await getSavedObjectsCounts(esClient, '.kibana', ['type_one', 'type-two']); + const results = await getSavedObjectsCounts(esClient, ['.kibana'], ['type_one', 'type-two']); expect(results).toStrictEqual({ total: 13, per_type: [ diff --git a/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/kibana_usage_collector.test.ts b/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/kibana_usage_collector.test.ts index 65003ff99c22a..f9e76253dcbb2 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/kibana_usage_collector.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/saved_objects_counts/kibana_usage_collector.test.ts @@ -27,8 +27,9 @@ describe('kibana_usage', () => { }); const kibanaIndex = '.kibana-tests'; + const getIndexForTypes = (index: string) => (types: string[]) => Promise.resolve([index]); - beforeAll(() => registerKibanaUsageCollector(usageCollectionMock, kibanaIndex)); + beforeAll(() => registerKibanaUsageCollector(usageCollectionMock, getIndexForTypes(kibanaIndex))); afterAll(() => jest.clearAllTimers()); afterEach(() => getSavedObjectsCountsMock.mockReset()); @@ -61,7 +62,7 @@ describe('getKibanaSavedObjectCounts', () => { non_expected_types: [], others: 0, }); - const results = await getKibanaSavedObjectCounts(esClient, '.kibana'); + const results = await getKibanaSavedObjectCounts(esClient, ['.kibana']); expect(results).toStrictEqual({ dashboard: { total: 0 }, visualization: { total: 0 }, @@ -83,7 +84,7 @@ describe('getKibanaSavedObjectCounts', () => { others: 0, }); - const results = await getKibanaSavedObjectCounts(esClient, '.kibana'); + const results = await getKibanaSavedObjectCounts(esClient, ['.kibana']); expect(results).toStrictEqual({ dashboard: { total: 1 }, visualization: { total: 0 }, @@ -94,7 +95,7 @@ describe('getKibanaSavedObjectCounts', () => { expect(getSavedObjectsCountsMock).toHaveBeenCalledWith( esClient, - '.kibana', + ['.kibana'], ['dashboard', 'visualization', 'search', 'index-pattern', 'graph-workspace'], true );