Skip to content

Commit

Permalink
fix rule add test
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Sep 21, 2023
1 parent 4b45345 commit caa3180
Showing 1 changed file with 11 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RuleAdd from './rule_add';
import { createRule } from '../../lib/rule_api/create';
import { alertingFrameworkHealth } from '../../lib/rule_api/health';
import { actionTypeRegistryMock } from '../../action_type_registry.mock';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { AlertConsumers, OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '@kbn/rule-data-utils';
import {
Rule,
RuleAddProps,
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('rule_add', () => {
});
});

it('should set consumer when the consumer selection renders and rule is created', async () => {
it('should NOT allow to save the rule if the consumer is not set', async () => {
(triggersActionsUiConfig as jest.Mock).mockResolvedValue({
minimumScheduleInterval: { value: '1m', enforce: false },
});
Expand All @@ -349,7 +349,7 @@ describe('rule_add', () => {
initialValues: {
name: 'Simple rule',
consumer: 'alerts',
ruleTypeId: 'observability.rules.threshold',
ruleTypeId: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
tags: ['uptime', 'logs'],
schedule: {
interval: '1h',
Expand All @@ -358,7 +358,7 @@ describe('rule_add', () => {
onClose,
ruleTypesOverwrite: [
{
id: 'observability.rules.threshold',
id: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
name: 'Threshold Rule',
actionGroups: [
{
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('rule_add', () => {
},
],
ruleTypeModelOverwrite: {
id: 'observability.rules.threshold',
id: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
iconClass: 'test',
description: 'test',
documentationUrl: null,
Expand All @@ -403,13 +403,7 @@ describe('rule_add', () => {
ruleParamsExpression: TestExpression,
requiresAppContext: false,
},
validConsumers: [
AlertConsumers.APM,
AlertConsumers.INFRASTRUCTURE,
AlertConsumers.LOGS,
AlertConsumers.UPTIME,
AlertConsumers.SLO,
],
validConsumers: [AlertConsumers.INFRASTRUCTURE, AlertConsumers.LOGS],
});

await act(async () => {
Expand All @@ -424,13 +418,7 @@ describe('rule_add', () => {
wrapper.update();
});

expect(createRule).toHaveBeenLastCalledWith(
expect.objectContaining({
rule: expect.objectContaining({
consumer: 'apm',
}),
})
);
expect(createRule).toBeCalledTimes(0);
});

it('should set consumer automatically if only 1 authorized consumer exists', async () => {
Expand All @@ -442,7 +430,7 @@ describe('rule_add', () => {
initialValues: {
name: 'Simple rule',
consumer: 'alerts',
ruleTypeId: 'observability.rules.threshold',
ruleTypeId: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
tags: ['uptime', 'logs'],
schedule: {
interval: '1h',
Expand All @@ -451,7 +439,7 @@ describe('rule_add', () => {
onClose,
ruleTypesOverwrite: [
{
id: 'observability.rules.threshold',
id: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
name: 'Threshold Rule',
actionGroups: [
{
Expand All @@ -475,7 +463,7 @@ describe('rule_add', () => {
},
],
ruleTypeModelOverwrite: {
id: 'observability.rules.threshold',
id: OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
iconClass: 'test',
description: 'test',
documentationUrl: null,
Expand All @@ -485,13 +473,7 @@ describe('rule_add', () => {
ruleParamsExpression: TestExpression,
requiresAppContext: false,
},
validConsumers: [
AlertConsumers.APM,
AlertConsumers.INFRASTRUCTURE,
AlertConsumers.LOGS,
AlertConsumers.UPTIME,
AlertConsumers.SLO,
],
validConsumers: [AlertConsumers.INFRASTRUCTURE, AlertConsumers.LOGS],
});

await act(async () => {
Expand Down

0 comments on commit caa3180

Please sign in to comment.