-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create unit test for registerBuiltInActionTypes and move common code (#…
…45648) * Create unit test for registerBuiltInActionTypes and move common code
- Loading branch information
1 parent
68ffe7e
commit c6e7859
Showing
6 changed files
with
82 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
x-pack/legacy/plugins/actions/server/builtin_action_types/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ActionsConfigurationUtilities } from '../actions_config'; | ||
import { ActionTypeRegistry } from '../action_type_registry'; | ||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock'; | ||
import { taskManagerMock } from '../../../task_manager/task_manager.mock'; | ||
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks'; | ||
import { registerBuiltInActionTypes } from './index'; | ||
|
||
const ACTION_TYPE_IDS = ['.index', '.email', '.pagerduty', '.server-log', '.slack', '.webhook']; | ||
const NO_OP_FN = () => {}; | ||
const MOCK_KIBANA_CONFIG_UTILS: ActionsConfigurationUtilities = { | ||
isWhitelistedHostname: _ => true, | ||
isWhitelistedUri: _ => true, | ||
ensureWhitelistedHostname: _ => {}, | ||
ensureWhitelistedUri: _ => {}, | ||
}; | ||
|
||
const services = { | ||
log: NO_OP_FN, | ||
callCluster: jest.fn(), | ||
savedObjectsClient: SavedObjectsClientMock.create(), | ||
}; | ||
|
||
function getServices() { | ||
return services; | ||
} | ||
|
||
const mockEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.create(); | ||
|
||
export function createActionTypeRegistry(): ActionTypeRegistry { | ||
const actionTypeRegistry = new ActionTypeRegistry({ | ||
getServices, | ||
isSecurityEnabled: true, | ||
taskManager: taskManagerMock.create(), | ||
encryptedSavedObjectsPlugin: mockEncryptedSavedObjectsPlugin, | ||
spaceIdToNamespace: jest.fn().mockReturnValue(undefined), | ||
getBasePath: jest.fn().mockReturnValue(undefined), | ||
}); | ||
registerBuiltInActionTypes(actionTypeRegistry, MOCK_KIBANA_CONFIG_UTILS); | ||
return actionTypeRegistry; | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('action is registered', () => { | ||
test('gets registered with builtin actions', () => { | ||
const actionTypeRegistry = createActionTypeRegistry(); | ||
ACTION_TYPE_IDS.forEach(ACTION_TYPE_ID => | ||
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.