* [Alerts][License] Define minimum license required for each alert type (#84997) * Define minimum license required for each alert type * fixed typechecks * fixed tests * fixed tests * fixed due to comments * fixed due to comments * removed file * removed casting to LicenseType * [Alerts][License] Add license checks to alerts HTTP APIs and execution (#85223) * [Alerts][License] Add license checks to alerts HTTP APIs and execution * fixed typechecks * resolved conflicts * resolved conflicts * added router tests * fixed typechecks * added license check support for alert task running * fixed typechecks * added integration tests * fixed due to comments * fixed due to comments * fixed tests * fixed typechecks * [Alerting UI][License] Disable alert types in UI when the license doesn't support it. (#85496) * [Alerting UI][License] Disable alert types in UI when the license doesn't support it. * fixed typechecks * added licensing for alert list and details page * fixed multy select menu * fixed due to comments * fixed due to comments * fixed due to comments * fixed typechecks * fixed license error message * fixed license error message * fixed typechecks * fixed license error message Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
125 lines
3.7 KiB
TypeScript
125 lines
3.7 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;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
|
|
import { AlertType, RecoveredActionGroup } from '../common';
|
|
import { httpServiceMock } from '../../../../src/core/public/mocks';
|
|
import { loadAlert, loadAlertType, loadAlertTypes } from './alert_api';
|
|
import uuid from 'uuid';
|
|
|
|
const http = httpServiceMock.createStartContract();
|
|
|
|
beforeEach(() => jest.resetAllMocks());
|
|
|
|
describe('loadAlertTypes', () => {
|
|
test('should call get alert types API', async () => {
|
|
const resolvedValue: AlertType[] = [
|
|
{
|
|
id: 'test',
|
|
name: 'Test',
|
|
actionVariables: ['var1'],
|
|
actionGroups: [{ id: 'default', name: 'Default' }],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
recoveryActionGroup: RecoveredActionGroup,
|
|
producer: 'alerts',
|
|
},
|
|
];
|
|
http.get.mockResolvedValueOnce(resolvedValue);
|
|
|
|
const result = await loadAlertTypes({ http });
|
|
expect(result).toEqual(resolvedValue);
|
|
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
|
|
Array [
|
|
"/api/alerts/list_alert_types",
|
|
]
|
|
`);
|
|
});
|
|
});
|
|
|
|
describe('loadAlertType', () => {
|
|
test('should call get alert types API', async () => {
|
|
const alertType: AlertType = {
|
|
id: 'test',
|
|
name: 'Test',
|
|
actionVariables: ['var1'],
|
|
actionGroups: [{ id: 'default', name: 'Default' }],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
recoveryActionGroup: RecoveredActionGroup,
|
|
producer: 'alerts',
|
|
};
|
|
http.get.mockResolvedValueOnce([alertType]);
|
|
|
|
await loadAlertType({ http, id: alertType.id });
|
|
|
|
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
|
|
Array [
|
|
"/api/alerts/list_alert_types",
|
|
]
|
|
`);
|
|
});
|
|
|
|
test('should find the required alertType', async () => {
|
|
const alertType: AlertType = {
|
|
id: 'test-another',
|
|
name: 'Test Another',
|
|
actionVariables: [],
|
|
actionGroups: [{ id: 'default', name: 'Default' }],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
recoveryActionGroup: RecoveredActionGroup,
|
|
producer: 'alerts',
|
|
};
|
|
http.get.mockResolvedValueOnce([alertType]);
|
|
|
|
expect(await loadAlertType({ http, id: 'test-another' })).toEqual(alertType);
|
|
});
|
|
|
|
test('should throw if required alertType is missing', async () => {
|
|
http.get.mockResolvedValueOnce([
|
|
{
|
|
id: 'test-another',
|
|
name: 'Test Another',
|
|
actionVariables: [],
|
|
actionGroups: [{ id: 'default', name: 'Default' }],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
recoveryActionGroup: RecoveredActionGroup,
|
|
producer: 'alerts',
|
|
},
|
|
]);
|
|
|
|
expect(loadAlertType({ http, id: 'test' })).rejects.toMatchInlineSnapshot(
|
|
`[Error: Alert type "test" is not registered.]`
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('loadAlert', () => {
|
|
test('should call get API with base parameters', async () => {
|
|
const alertId = uuid.v4();
|
|
const resolvedValue = {
|
|
id: alertId,
|
|
name: 'name',
|
|
tags: [],
|
|
enabled: true,
|
|
alertTypeId: '.noop',
|
|
schedule: { interval: '1s' },
|
|
actions: [],
|
|
params: {},
|
|
createdBy: null,
|
|
updatedBy: null,
|
|
throttle: null,
|
|
muteAll: false,
|
|
mutedInstanceIds: [],
|
|
};
|
|
http.get.mockResolvedValueOnce(resolvedValue);
|
|
|
|
expect(await loadAlert({ http, alertId })).toEqual(resolvedValue);
|
|
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}`);
|
|
});
|
|
});
|