Skip to content

Commit

Permalink
Fixed type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Feb 13, 2020
1 parent b46c124 commit aaf1dd8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions x-pack/plugins/alerting/server/alerts_client_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { Request } from 'hapi';
import { AlertsClientFactory, ConstructorOpts } from './alerts_client_factory';
import { AlertsClientFactory, AlertsClientFactoryOpts } from './alerts_client_factory';
import { alertTypeRegistryMock } from './alert_type_registry.mock';
import { taskManagerMock } from '../../../plugins/task_manager/server/task_manager.mock';
import { KibanaRequest } from '../../../../src/core/server';
Expand All @@ -21,7 +21,7 @@ const securityPluginSetup = {
getCurrentUser: jest.fn(),
},
};
const alertsClientFactoryParams: jest.Mocked<ConstructorOpts> = {
const alertsClientFactoryParams: jest.Mocked<AlertsClientFactoryOpts> = {
logger: loggingServiceMock.create().get(),
taskManager: taskManagerMock.start(),
alertTypeRegistry: alertTypeRegistryMock.create(),
Expand Down Expand Up @@ -52,7 +52,8 @@ beforeEach(() => {
});

test('creates an alerts client with proper constructor arguments', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
const factory = new AlertsClientFactory();
factory.initialize(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);

expect(jest.requireMock('./alerts_client').AlertsClient).toHaveBeenCalledWith({
Expand All @@ -70,7 +71,8 @@ test('creates an alerts client with proper constructor arguments', async () => {
});

test('getUserName() returns null when security is disabled', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
const factory = new AlertsClientFactory();
factory.initialize(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

Expand All @@ -79,7 +81,8 @@ test('getUserName() returns null when security is disabled', async () => {
});

test('getUserName() returns a name when security is enabled', async () => {
const factory = new AlertsClientFactory({
const factory = new AlertsClientFactory();
factory.initialize({
...alertsClientFactoryParams,
securityPluginSetup: securityPluginSetup as any,
});
Expand All @@ -92,7 +95,8 @@ test('getUserName() returns a name when security is enabled', async () => {
});

test('createAPIKey() returns { apiKeysEnabled: false } when security is disabled', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
const factory = new AlertsClientFactory();
factory.initialize(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

Expand All @@ -101,7 +105,8 @@ test('createAPIKey() returns { apiKeysEnabled: false } when security is disabled
});

test('createAPIKey() returns { apiKeysEnabled: false } when security is enabled but ES security is disabled', async () => {
const factory = new AlertsClientFactory(alertsClientFactoryParams);
const factory = new AlertsClientFactory();
factory.initialize(alertsClientFactoryParams);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

Expand All @@ -111,7 +116,8 @@ test('createAPIKey() returns { apiKeysEnabled: false } when security is enabled
});

test('createAPIKey() returns an API key when security is enabled', async () => {
const factory = new AlertsClientFactory({
const factory = new AlertsClientFactory();
factory.initialize({
...alertsClientFactoryParams,
securityPluginSetup: securityPluginSetup as any,
});
Expand All @@ -127,7 +133,8 @@ test('createAPIKey() returns an API key when security is enabled', async () => {
});

test('createAPIKey() throws when security plugin createAPIKey throws an error', async () => {
const factory = new AlertsClientFactory({
const factory = new AlertsClientFactory();
factory.initialize({
...alertsClientFactoryParams,
securityPluginSetup: securityPluginSetup as any,
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Alerting Plugin', () => {
describe('setup()', () => {
it('should log warning when Encrypted Saved Objects plugin is using an ephemeral encryption key', async () => {
const context = coreMock.createPluginInitializerContext();
const plugin = new Plugin(context);
const plugin = new AlertingPlugin(context);

const coreSetup = coreMock.createSetup();
const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup();
Expand Down

0 comments on commit aaf1dd8

Please sign in to comment.