kibana/x-pack/plugins/actions/server/usage/actions_usage_collector.test.ts
ymao1 b09e418e51
[Actions][Telemetry] Counting number of alert history connectors in use (#97063)
* Counting number of alert history connectors in use

* Telemetry for preconfigured alert history config enabled

* Updating telemetry mappings

* Updating tests

* Adding descriptions to new telemetry fields

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-04-15 14:13:19 -04:00

46 lines
1.6 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { registerActionsUsageCollector } from './actions_usage_collector';
import { configSchema, ActionsConfig } from '../config';
import { taskManagerMock } from '../../../task_manager/server/mocks';
const mockTaskManagerStart = taskManagerMock.createStart();
beforeEach(() => jest.resetAllMocks());
describe('registerActionsUsageCollector', () => {
let config: ActionsConfig;
let usageCollectionMock: jest.Mocked<UsageCollectionSetup>;
beforeEach(() => {
config = configSchema.validate({});
usageCollectionMock = ({
makeUsageCollector: jest.fn(),
registerCollector: jest.fn(),
} as unknown) as jest.Mocked<UsageCollectionSetup>;
});
it('should call registerCollector', () => {
registerActionsUsageCollector(
usageCollectionMock as UsageCollectionSetup,
config,
new Promise(() => mockTaskManagerStart)
);
expect(usageCollectionMock.registerCollector).toHaveBeenCalledTimes(1);
});
it('should call makeUsageCollector with type = actions', () => {
registerActionsUsageCollector(
usageCollectionMock as UsageCollectionSetup,
config,
new Promise(() => mockTaskManagerStart)
);
expect(usageCollectionMock.makeUsageCollector).toHaveBeenCalledTimes(1);
expect(usageCollectionMock.makeUsageCollector.mock.calls[0][0].type).toBe('actions');
});
});