Skip to content

Commit 1c6a6b0

Browse files
committed
fix tests
1 parent a3afefd commit 1c6a6b0

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('conditions', () => {
152152

153153
test('uses basePath from job when creating saved object service', async () => {
154154
const mockGetSavedObjectsClient = jest.fn();
155-
mockReportingPlugin.getSavedObjectsClient = jest.fn();
155+
mockReportingPlugin.getSavedObjectsClient = mockGetSavedObjectsClient;
156156

157157
const permittedHeaders = {
158158
foo: 'bar',

x-pack/legacy/plugins/reporting/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export const plugin = (context: PluginInitializerContext) => {
1313

1414
export { ReportingCore } from './core';
1515
export { ReportingPlugin } from './plugin';
16-
export { ReportingSetupDeps, ReportingStartDeps } from './types';
16+
export { ReportingSetupDeps, ReportingStartDeps } from './types.d';

x-pack/legacy/plugins/reporting/server/usage/reporting_usage_collector.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import * as Rx from 'rxjs';
87
import sinon from 'sinon';
8+
import { createMockReportingCore } from '../../test_helpers';
99
import { getExportTypesRegistry } from '../lib/export_types_registry';
1010
import {
11-
getReportingUsageCollector,
1211
registerReportingUsageCollector,
12+
getReportingUsageCollector,
1313
} from './reporting_usage_collector';
1414

1515
const exportTypesRegistry = getExportTypesRegistry();
@@ -415,20 +415,20 @@ describe('data modeling', () => {
415415
});
416416

417417
describe('Ready for collection observable', () => {
418+
let mockReporting;
419+
420+
beforeEach(async () => {
421+
mockReporting = await createMockReportingCore();
422+
});
423+
418424
test('converts observable to promise', async () => {
419425
const serverWithBasicLicenseMock = getServerMock();
420426
const makeCollectorSpy = sinon.spy();
421427
const usageCollection = {
422428
makeUsageCollector: makeCollectorSpy,
423429
registerCollector: sinon.stub(),
424430
};
425-
const start$ = Rx.of({ start: true });
426-
registerReportingUsageCollector(
427-
serverWithBasicLicenseMock,
428-
usageCollection,
429-
start$,
430-
exportTypesRegistry
431-
);
431+
registerReportingUsageCollector(mockReporting, serverWithBasicLicenseMock, usageCollection);
432432

433433
const [args] = makeCollectorSpy.firstCall.args;
434434
expect(args).toMatchInlineSnapshot(`

x-pack/legacy/plugins/reporting/server/usage/reporting_usage_collector.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@
77
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
88
import { KIBANA_REPORTING_TYPE } from '../../common/constants';
99
import { ReportingCore } from '../../server';
10-
import { ESCallCluster, ServerFacade } from '../../types';
10+
import { ESCallCluster, ExportTypesRegistry, ServerFacade } from '../../types';
1111
import { getReportingUsage } from './get_reporting_usage';
1212
import { RangeStats } from './types';
1313

1414
// places the reporting data as kibana stats
1515
const METATYPE = 'kibana_stats';
1616

17-
export function registerReportingUsageCollector(
18-
reporting: ReportingCore,
17+
/*
18+
* @param {Object} server
19+
* @return {Object} kibana usage stats type collection object
20+
*/
21+
export function getReportingUsageCollector(
1922
server: ServerFacade,
20-
usageCollection: UsageCollectionSetup
23+
usageCollection: UsageCollectionSetup,
24+
exportTypesRegistry: ExportTypesRegistry,
25+
isReady: () => Promise<boolean>
2126
) {
22-
const collector = usageCollection.makeUsageCollector({
27+
return usageCollection.makeUsageCollector({
2328
type: KIBANA_REPORTING_TYPE,
2429
fetch: (callCluster: ESCallCluster) =>
25-
getReportingUsage(server, callCluster, reporting.getExportTypesRegistry()),
26-
isReady: reporting.pluginHasStarted,
30+
getReportingUsage(server, callCluster, exportTypesRegistry),
31+
isReady,
2732

2833
/*
2934
* Format the response data into a model for internal upload
@@ -43,6 +48,21 @@ export function registerReportingUsageCollector(
4348
};
4449
},
4550
});
51+
}
52+
53+
export function registerReportingUsageCollector(
54+
reporting: ReportingCore,
55+
server: ServerFacade,
56+
usageCollection: UsageCollectionSetup
57+
) {
58+
const exportTypesRegistry = reporting.getExportTypesRegistry();
59+
const collectionIsReady = reporting.pluginHasStarted.bind(reporting);
4660

61+
const collector = getReportingUsageCollector(
62+
server,
63+
usageCollection,
64+
exportTypesRegistry,
65+
collectionIsReady
66+
);
4767
usageCollection.registerCollector(collector);
4868
}

0 commit comments

Comments
 (0)