Skip to content

Commit

Permalink
moved alerts_client_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Jan 3, 2020
1 parent d8a07e1 commit 0a7dcf3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
*/

export { AlertInstance } from './alert_instance';
export { AlertsClientFactory } from './alerts_client_factory';
export { createAlertInstanceFactory } from './create_alert_instance_factory';
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import { Request } from 'hapi';
import { AlertsClientFactory, ConstructorOpts } from './alerts_client_factory';
import { alertTypeRegistryMock } from '../alert_type_registry.mock';
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
import { KibanaRequest } from '../../../../../../src/core/server';
import { loggingServiceMock } from '../../../../../../src/core/server/mocks';
import { alertTypeRegistryMock } from './alert_type_registry.mock';
import { taskManagerMock } from '../../task_manager/task_manager.mock';
import { KibanaRequest } from '../../../../../src/core/server';
import { loggingServiceMock } from '../../../../../src/core/server/mocks';

jest.mock('../alerts_client');
jest.mock('./alerts_client');

const savedObjectsClient = jest.fn();
const securityPluginSetup = {
Expand Down Expand Up @@ -51,7 +51,7 @@ test('creates an alerts client with proper constructor arguments', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);

expect(jest.requireMock('../alerts_client').AlertsClient).toHaveBeenCalledWith({
expect(jest.requireMock('./alerts_client').AlertsClient).toHaveBeenCalledWith({
savedObjectsClient,
logger: alertsClientFactoryParams.logger,
taskManager: alertsClientFactoryParams.taskManager,
Expand All @@ -65,7 +65,7 @@ test('creates an alerts client with proper constructor arguments', async () => {
test('getUserName() returns null when security is disabled', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

const userNameResult = await constructorCall.getUserName();
expect(userNameResult).toEqual(null);
Expand All @@ -77,7 +77,7 @@ test('getUserName() returns a name when security is enabled', async () => {
securityPluginSetup: securityPluginSetup as any,
});
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

securityPluginSetup.authc.getCurrentUser.mockResolvedValueOnce({ username: 'bob' });
const userNameResult = await constructorCall.getUserName();
Expand All @@ -87,7 +87,7 @@ test('getUserName() returns a name when security is enabled', async () => {
test('createAPIKey() returns { created: false } when security is disabled', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

const createAPIKeyResult = await constructorCall.createAPIKey();
expect(createAPIKeyResult).toEqual({ created: false });
Expand All @@ -96,7 +96,7 @@ test('createAPIKey() returns { created: false } when security is disabled', asyn
test('createAPIKey() returns { created: false } when security is enabled but ES security is disabled', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

securityPluginSetup.authc.createAPIKey.mockResolvedValueOnce(null);
const createAPIKeyResult = await constructorCall.createAPIKey();
Expand All @@ -109,7 +109,7 @@ test('createAPIKey() returns an API key when security is enabled', async () => {
securityPluginSetup: securityPluginSetup as any,
});
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

securityPluginSetup.authc.createAPIKey.mockResolvedValueOnce({ api_key: '123', id: 'abc' });
const createAPIKeyResult = await constructorCall.createAPIKey();
Expand All @@ -122,7 +122,7 @@ test('createAPIKey() throws when security plugin createAPIKey throws an error',
securityPluginSetup: securityPluginSetup as any,
});
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
const constructorCall = jest.requireMock('../alerts_client').AlertsClient.mock.calls[0][0];
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

securityPluginSetup.authc.createAPIKey.mockRejectedValueOnce(new Error('TLS disabled'));
await expect(constructorCall.createAPIKey()).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import Hapi from 'hapi';
import uuid from 'uuid';
import { AlertTypeRegistry } from '../types';
import { AlertsClient } from '../alerts_client';
import { SecurityPluginStartContract, TaskManagerStartContract } from '../shim';
import { KibanaRequest, Logger } from '../../../../../../src/core/server';
import { AlertTypeRegistry } from './types';
import { AlertsClient } from './alerts_client';
import { SecurityPluginStartContract, TaskManagerStartContract } from './shim';
import { KibanaRequest, Logger } from '../../../../../src/core/server';

export interface ConstructorOpts {
logger: Logger;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Services } from './types';
import { AlertsClient } from './alerts_client';
import { AlertTypeRegistry } from './alert_type_registry';
import { TaskRunnerFactory } from './task_runner';
import { AlertsClientFactory } from './alert_instance';
import { AlertsClientFactory } from './alerts_client_factory';
import { LicenseState } from './lib/license_state';
import { IClusterClient, KibanaRequest, Logger } from '../../../../../src/core/server';
import {
Expand Down

0 comments on commit 0a7dcf3

Please sign in to comment.