Skip to content

Commit

Permalink
[BUG] Create detector | Interval field can be empty opensearch-projec…
Browse files Browse the repository at this point in the history
…t#378

Signed-off-by: Jovan Cvetkovic <[email protected]>
  • Loading branch information
jovancvetkovic3006 committed Jan 23, 2023
1 parent 0d514d8 commit ff8117e
Show file tree
Hide file tree
Showing 11 changed files with 1,713 additions and 2 deletions.
76 changes: 76 additions & 0 deletions public/models/Detectors/InterfacesMock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
AlertCondition,
Detector,
DetectorInput,
DetectorRuleInfo,
PeriodSchedule,
TriggerAction,
} from '../../../models/interfaces';

export const detectorRuleInfoMock: DetectorRuleInfo = {
id: 'detectorRuleId',
};

export const detectorInputMock: DetectorInput = {
detector_input: {
description: 'detectorDescription',
indices: ['.windows'],
pre_packaged_rules: [detectorRuleInfoMock],
custom_rules: [detectorRuleInfoMock],
},
};

export const periodScheduleMock: PeriodSchedule = {
period: {
interval: 1,
unit: 'minute',
},
};

export const triggerActionMock: TriggerAction = {
id: 'someId',
// Id of notification channel
destination_id: 'destinationId',
subject_template: {
source: 'sourceTemplate',
lang: 'en-US',
},
name: 'triggerName',
throttle_enabled: false,
message_template: {
source: 'messageSource',
lang: 'en-US',
},
throttle: {
unit: 'throttleUnit',
value: 1,
},
};

export const alertConditionMock: AlertCondition = {
// Trigger fields
name: 'alertName',

// Detector types
types: ['detectorType1'],

// Trigger fields based on Rules
sev_levels: ['low'],
tags: ['any.tag'],
ids: ['ruleId1'],

// Alert related fields
actions: [triggerActionMock, triggerActionMock],
severity: 'low',
};

export const detectorMock: Detector = {
type: 'detector',
detector_type: '.windows',
name: 'detectorName',
enabled: true,
createdBy: 'testUser',
schedule: periodScheduleMock,
inputs: [detectorInputMock],
triggers: [alertConditionMock, alertConditionMock],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { RuleInfo, RuleSource } from '../../../../../server/models/interfaces';
import { alertConditionMock, detectorMock } from '../../InterfacesMock.test';

const ruleSource: RuleSource = {
rule: 'ruleName',
last_update_time: '12/12/2022',
queries: [{ value: '.windows' }],
};

const ruleInfo: RuleInfo = {
_id: 'ruleId',
_index: '.windows',
_primary_term: 1,
_source: ruleSource,
_version: 1,
};

export default {
alertTrigger: alertConditionMock,
orderPosition: 1,
detector: detectorMock,
notificationChannels: [],
rules: { rileId: ruleInfo },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { detectorMock } from '../../InterfacesMock.test';

export default {
detector: detectorMock,
rulesCanFold: true,
enabled_time: 1,
last_update_time: 1,
onEditClicked: () => jest.fn(),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { detectorMock } from '../../InterfacesMock.test';

const notificationsStart: NotificationsStart = {};
export default {
detector: detectorMock,
rulesCanFold: true,
onEditClicked: jest.fn(),
notifications: notificationsStart,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import { AlertTriggerView } from './AlertTriggerView';
import props from '../../../../models/Detectors/components/AlertTriggerView/AlertTriggerViewMock.test';
import { expect } from '@jest/globals';

describe('<AlertTriggerView /> spec', () => {
it('renders the component', () => {
const view = render(<AlertTriggerView {...props} />);
expect(view).toMatchSnapshot();
});
});
Loading

0 comments on commit ff8117e

Please sign in to comment.