37525f80a0
* [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>
90 lines
2.2 KiB
TypeScript
90 lines
2.2 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 { schema } from '@kbn/config-schema';
|
|
import { validateAlertTypeParams } from './validate_alert_type_params';
|
|
|
|
test('should return passed in params when validation not defined', () => {
|
|
const result = validateAlertTypeParams(
|
|
{
|
|
id: 'my-alert-type',
|
|
name: 'My description',
|
|
actionGroups: [
|
|
{
|
|
id: 'default',
|
|
name: 'Default',
|
|
},
|
|
],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
async executor() {},
|
|
producer: 'alerts',
|
|
},
|
|
{
|
|
foo: true,
|
|
}
|
|
);
|
|
expect(result).toEqual({ foo: true });
|
|
});
|
|
|
|
test('should validate and apply defaults when params is valid', () => {
|
|
const result = validateAlertTypeParams(
|
|
{
|
|
id: 'my-alert-type',
|
|
name: 'My description',
|
|
actionGroups: [
|
|
{
|
|
id: 'default',
|
|
name: 'Default',
|
|
},
|
|
],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
validate: {
|
|
params: schema.object({
|
|
param1: schema.string(),
|
|
param2: schema.string({ defaultValue: 'default-value' }),
|
|
}),
|
|
},
|
|
async executor() {},
|
|
producer: 'alerts',
|
|
},
|
|
{ param1: 'value' }
|
|
);
|
|
expect(result).toEqual({
|
|
param1: 'value',
|
|
param2: 'default-value',
|
|
});
|
|
});
|
|
|
|
test('should validate and throw error when params is invalid', () => {
|
|
expect(() =>
|
|
validateAlertTypeParams(
|
|
{
|
|
id: 'my-alert-type',
|
|
name: 'My description',
|
|
actionGroups: [
|
|
{
|
|
id: 'default',
|
|
name: 'Default',
|
|
},
|
|
],
|
|
defaultActionGroupId: 'default',
|
|
minimumLicenseRequired: 'basic',
|
|
validate: {
|
|
params: schema.object({
|
|
param1: schema.string(),
|
|
}),
|
|
},
|
|
async executor() {},
|
|
producer: 'alerts',
|
|
},
|
|
{}
|
|
)
|
|
).toThrowErrorMatchingInlineSnapshot(
|
|
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
|
|
);
|
|
});
|