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 12, 2020
1 parent d5c4d6a commit e65f3f8
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Alert } from '../../../../../alerting/common';
import { Alert } from '../../../../../../../plugins/alerting/common';
import { APP_ID, SIGNALS_ID } from '../../../../common/constants';
import { CreateRuleParams } from './types';
import { addTags } from './add_tags';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { defaults } from 'lodash/fp';
import { PartialAlert } from '../../../../../alerting/server/types';
import { PartialAlert } from '../../../../../../../plugins/alerting/server';
import { readRules } from './read_rules';
import { PatchRuleParams, IRuleSavedAttributesSavedObjectAttributes } from './types';
import { addTags } from './add_tags';
Expand Down
18 changes: 9 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 @@ -9,12 +9,12 @@ import { AlertsClientFactory, ConstructorOpts } 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';
import { loggingServiceMock } from '../../../../src/core/server/mocks';
import { loggingServiceMock, savedObjectsClientMock } from '../../../../src/core/server/mocks';
import { encryptedSavedObjectsMock } from '../../../plugins/encrypted_saved_objects/server/mocks';

jest.mock('./alerts_client');

const savedObjectsClient = jest.fn();
const savedObjectsClient = savedObjectsClientMock.create();
const securityPluginSetup = {
authc: {
createAPIKey: jest.fn(),
Expand Down Expand Up @@ -53,7 +53,7 @@ beforeEach(() => {

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

expect(jest.requireMock('./alerts_client').AlertsClient).toHaveBeenCalledWith({
savedObjectsClient,
Expand All @@ -71,7 +71,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);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

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

securityPluginSetup.authc.getCurrentUser.mockReturnValueOnce({ username: 'bob' });
Expand All @@ -93,7 +93,7 @@ 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);
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

const createAPIKeyResult = await constructorCall.createAPIKey();
Expand All @@ -102,7 +102,7 @@ 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);
factory.create(KibanaRequest.from(fakeRequest), fakeRequest);
factory.create(KibanaRequest.from(fakeRequest), savedObjectsClient);
const constructorCall = jest.requireMock('./alerts_client').AlertsClient.mock.calls[0][0];

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

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

securityPluginSetup.authc.createAPIKey.mockRejectedValueOnce(new Error('TLS disabled'));
Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/alerting/server/alerts_client_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
import uuid from 'uuid';
import { AlertsClient } from './alerts_client';
import { AlertTypeRegistry, SpaceIdToNamespaceFunction } from './types';
import { SecurityPluginStartContract } from './shim';
import { KibanaRequest, Logger, SavedObjectsClientContract } from '../../../../src/core/server';
import { InvalidateAPIKeyParams } from '../../../plugins/security/server';
import { InvalidateAPIKeyParams, SecurityPluginSetup } from '../../../plugins/security/server';
import { EncryptedSavedObjectsPluginStart } from '../../../plugins/encrypted_saved_objects/server';
import { TaskManagerStartContract } from '../../../plugins/task_manager/server';

export interface ConstructorOpts {
logger: Logger;
taskManager: TaskManagerStartContract;
alertTypeRegistry: AlertTypeRegistry;
securityPluginSetup?: SecurityPluginStartContract;
securityPluginSetup?: SecurityPluginSetup;
getSpaceId: (request: KibanaRequest) => string | undefined;
spaceIdToNamespace: SpaceIdToNamespaceFunction;
encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
Expand All @@ -27,7 +26,7 @@ export class AlertsClientFactory {
private readonly logger: Logger;
private readonly taskManager: TaskManagerStartContract;
private readonly alertTypeRegistry: AlertTypeRegistry;
private readonly securityPluginSetup?: SecurityPluginStartContract;
private readonly securityPluginSetup?: SecurityPluginSetup;
private readonly getSpaceId: (request: KibanaRequest) => string | undefined;
private readonly spaceIdToNamespace: SpaceIdToNamespaceFunction;
private readonly encryptedSavedObjectsPlugin: EncryptedSavedObjectsPluginStart;
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
} from './routes';
import { LicensingPluginSetup } from '../../licensing/server';
import {
ActionsPlugin,
PluginSetupContract as ActionsPluginSetupContract,
PluginStartContract as ActionsPluginStartContract,
} from '../../../plugins/actions/server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { HttpSetup } from 'kibana/public';
import * as t from 'io-ts';
import { pipe } from 'fp-ts/lib/pipeable';
import { fold } from 'fp-ts/lib/Either';
import { alertStateSchema } from '../../../../alerting/common';
import { BASE_ALERT_API_PATH } from '../constants';
import { Alert, AlertType, AlertWithoutId, AlertTaskState } from '../../types';
import { alertStateSchema } from '../../../../../legacy/plugins/alerting/common';

export async function loadAlertTypes({ http }: { http: HttpSetup }): Promise<AlertType[]> {
return await http.get(`${BASE_ALERT_API_PATH}/types`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { EuiBasicTable, EuiButtonToggle, EuiBadge, EuiHealth } from '@elastic/eu
import { RIGHT_ALIGNMENT, CENTER_ALIGNMENT } from '@elastic/eui/lib/services';
import { padLeft, difference } from 'lodash';
import { FormattedMessage } from '@kbn/i18n/react';
import { RawAlertInstance } from '../../../../../../../legacy/plugins/alerting/common';
import { Alert, AlertTaskState } from '../../../../types';
import { Alert, AlertTaskState, RawAlertInstance } from '../../../../types';
import {
ComponentOpts as AlertApis,
withBulkAlertOperations,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/triggers_actions_ui/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
AlertAction,
AlertTaskState,
RawAlertInstance,
} from '../../../legacy/plugins/alerting/common';
} from '../../../plugins/alerting/common';
export { Alert, AlertAction, AlertTaskState, RawAlertInstance };
export { ActionType };

Expand Down

0 comments on commit e65f3f8

Please sign in to comment.