Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Feb 13, 2020
1 parent a3afefd commit 1c6a6b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('conditions', () => {

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

const permittedHeaders = {
foo: 'bar',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const plugin = (context: PluginInitializerContext) => {

export { ReportingCore } from './core';
export { ReportingPlugin } from './plugin';
export { ReportingSetupDeps, ReportingStartDeps } from './types';
export { ReportingSetupDeps, ReportingStartDeps } from './types.d';
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as Rx from 'rxjs';
import sinon from 'sinon';
import { createMockReportingCore } from '../../test_helpers';
import { getExportTypesRegistry } from '../lib/export_types_registry';
import {
getReportingUsageCollector,
registerReportingUsageCollector,
getReportingUsageCollector,
} from './reporting_usage_collector';

const exportTypesRegistry = getExportTypesRegistry();
Expand Down Expand Up @@ -415,20 +415,20 @@ describe('data modeling', () => {
});

describe('Ready for collection observable', () => {
let mockReporting;

beforeEach(async () => {
mockReporting = await createMockReportingCore();
});

test('converts observable to promise', async () => {
const serverWithBasicLicenseMock = getServerMock();
const makeCollectorSpy = sinon.spy();
const usageCollection = {
makeUsageCollector: makeCollectorSpy,
registerCollector: sinon.stub(),
};
const start$ = Rx.of({ start: true });
registerReportingUsageCollector(
serverWithBasicLicenseMock,
usageCollection,
start$,
exportTypesRegistry
);
registerReportingUsageCollector(mockReporting, serverWithBasicLicenseMock, usageCollection);

const [args] = makeCollectorSpy.firstCall.args;
expect(args).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { KIBANA_REPORTING_TYPE } from '../../common/constants';
import { ReportingCore } from '../../server';
import { ESCallCluster, ServerFacade } from '../../types';
import { ESCallCluster, ExportTypesRegistry, ServerFacade } from '../../types';
import { getReportingUsage } from './get_reporting_usage';
import { RangeStats } from './types';

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

export function registerReportingUsageCollector(
reporting: ReportingCore,
/*
* @param {Object} server
* @return {Object} kibana usage stats type collection object
*/
export function getReportingUsageCollector(
server: ServerFacade,
usageCollection: UsageCollectionSetup
usageCollection: UsageCollectionSetup,
exportTypesRegistry: ExportTypesRegistry,
isReady: () => Promise<boolean>
) {
const collector = usageCollection.makeUsageCollector({
return usageCollection.makeUsageCollector({
type: KIBANA_REPORTING_TYPE,
fetch: (callCluster: ESCallCluster) =>
getReportingUsage(server, callCluster, reporting.getExportTypesRegistry()),
isReady: reporting.pluginHasStarted,
getReportingUsage(server, callCluster, exportTypesRegistry),
isReady,

/*
* Format the response data into a model for internal upload
Expand All @@ -43,6 +48,21 @@ export function registerReportingUsageCollector(
};
},
});
}

export function registerReportingUsageCollector(
reporting: ReportingCore,
server: ServerFacade,
usageCollection: UsageCollectionSetup
) {
const exportTypesRegistry = reporting.getExportTypesRegistry();
const collectionIsReady = reporting.pluginHasStarted.bind(reporting);

const collector = getReportingUsageCollector(
server,
usageCollection,
exportTypesRegistry,
collectionIsReady
);
usageCollection.registerCollector(collector);
}

0 comments on commit 1c6a6b0

Please sign in to comment.