Skip to content

Commit a6c905b

Browse files
committed
fix oss telemetry tests
1 parent d63a190 commit a6c905b

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

x-pack/legacy/plugins/oss_telemetry/server/lib/collectors/visualizations/get_usage_collector.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ describe('getVisualizationsCollector#fetch', () => {
4444
// In real life, the CollectorSet calls fetch and handles errors
4545
test('defers the errors', async () => {
4646
const mockTaskFetch = jest.fn(() => {
47-
return Promise.reject(Error('BOOM'));
47+
throw new Error('BOOM');
4848
});
4949

5050
const { fetch } = getUsageCollector(getMockTaskManager(mockTaskFetch));
51-
await expect(async () => {
52-
await fetch();
53-
}).rejects.toEqual({ message: 'BOOM' });
51+
await expect(fetch()).rejects.toThrowErrorMatchingInlineSnapshot(`"BOOM"`);
5452
});
5553
});
5654
});

x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../../
99
import { PLUGIN_ID, VIS_TELEMETRY_TASK } from '../../../constants';
1010
import { visualizationsTaskRunner } from './visualizations/task_runner';
1111
import KbnServer from '../../../../../../../src/legacy/server/kbn_server';
12+
import { LegacyConfig } from '../../plugin';
13+
import { TaskInstance } from '../../../../task_manager';
1214

1315
export function registerTasks({
1416
taskManager,
@@ -19,7 +21,7 @@ export function registerTasks({
1921
taskManager?: TaskManagerPluginSetupContract;
2022
logger: Logger;
2123
elasticsearch: CoreSetup['elasticsearch'];
22-
config: any;
24+
config: LegacyConfig;
2325
}) {
2426
if (!taskManager) {
2527
logger.debug('Task manager is not available');
@@ -30,7 +32,7 @@ export function registerTasks({
3032
[VIS_TELEMETRY_TASK]: {
3133
title: 'X-Pack telemetry calculator for Visualizations',
3234
type: VIS_TELEMETRY_TASK,
33-
createTaskRunner({ taskInstance }: { taskInstance: any }) {
35+
createTaskRunner({ taskInstance }: { taskInstance: TaskInstance }) {
3436
return {
3537
run: visualizationsTaskRunner(taskInstance, config, elasticsearch),
3638
};

x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getNextMidnight } from '../../get_next_midnight';
1010
import { VisState } from '../../../../../../../../src/legacy/core_plugins/visualizations/public';
1111
import { TaskInstance } from '../../../../../task_manager';
1212
import { ESSearchHit } from '../../../../../apm/typings/elasticsearch';
13+
import { LegacyConfig } from '../../../plugin';
1314

1415
interface VisSummary {
1516
type: string;
@@ -72,7 +73,7 @@ async function getStats(callCluster: APICaller, index: string) {
7273

7374
export function visualizationsTaskRunner(
7475
taskInstance: TaskInstance,
75-
config: any,
76+
config: LegacyConfig,
7677
es: CoreSetup['elasticsearch']
7778
) {
7879
const { callAsInternalUser: callCluster } = es.createClient('data');

x-pack/legacy/plugins/oss_telemetry/server/plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ interface UsageCollectorDefinition {
1717
fetch(): Promise<any>;
1818
}
1919

20+
export interface LegacyConfig {
21+
get: (key: string) => string | number | boolean;
22+
}
23+
2024
export interface OssTelemetrySetupDependencies {
2125
__LEGACY: {
2226
telemetry: {
@@ -25,7 +29,7 @@ export interface OssTelemetrySetupDependencies {
2529
register(collector: UsageCollector): void;
2630
};
2731
};
28-
config: any;
32+
config: LegacyConfig;
2933
xpackMainStatus: { kbnServer: KbnServer };
3034
};
3135
taskManager?: TaskManagerPluginSetupContract;

x-pack/legacy/plugins/oss_telemetry/test_utils/index.ts

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

7-
import { CoreSetup } from 'kibana/server';
7+
import { APICaller, CoreSetup } from 'kibana/server';
88

99
import { TaskInstance } from '../../task_manager';
1010
import { PluginSetupContract as TaskManagerPluginSetupContract } from '../../task_manager/plugin';
@@ -27,15 +27,15 @@ const defaultMockSavedObjects = [
2727

2828
const defaultMockTaskDocs = [getMockTaskInstance()];
2929

30-
export const getMockEs = (mockCallWithInternal: any = getMockCallWithInternal()) =>
30+
export const getMockEs = (mockCallWithInternal: APICaller = getMockCallWithInternal()) =>
3131
(({
3232
createClient: () => ({ callAsInternalUser: mockCallWithInternal }),
3333
} as unknown) as CoreSetup['elasticsearch']);
3434

35-
export const getMockCallWithInternal = (hits: any[] = defaultMockSavedObjects) => {
36-
return (): Promise<any> => {
35+
export const getMockCallWithInternal = (hits: unknown[] = defaultMockSavedObjects): APICaller => {
36+
return ((() => {
3737
return Promise.resolve({ hits: { hits } });
38-
};
38+
}) as unknown) as APICaller;
3939
};
4040

4141
export const getMockTaskFetch = (docs: TaskInstance[] = defaultMockTaskDocs) => {
@@ -50,8 +50,8 @@ export const getMockConfig = () => {
5050

5151
export const getMockTaskManager = (fetch: any = getMockTaskFetch()) =>
5252
(({
53-
registerTaskDefinitions: (opts: any) => undefined,
54-
ensureScheduled: (opts: any) => Promise.resolve(),
53+
registerTaskDefinitions: () => undefined,
54+
ensureScheduled: () => Promise.resolve(),
5555
fetch,
5656
} as unknown) as TaskManagerPluginSetupContract);
5757

0 commit comments

Comments
 (0)