Skip to content

Commit

Permalink
Adds test for required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiopro committed Dec 6, 2021
1 parent 04e4381 commit ad2c223
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions x-pack/plugins/rule_registry/common/parse_technical_fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { parseTechnicalFields } from './parse_technical_fields';

describe('parseTechnicalFields', () => {
it('parses an alert with default fields', () => {
it('parses an alert with default fields without error', () => {
const ALERT_WITH_DEFAULT_FIELDS = {
'kibana.alert.status': ['active'],
'@timestamp': ['2021-12-06T12:30:59.411Z'],
'kibana.alert.status': ['active'],
'kibana.alert.duration.us': ['488935266000'],
'kibana.alert.reason': ['host.uptime has reported no data over the past 1m for *'],
'kibana.alert.workflow_status': ['open'],
Expand All @@ -32,12 +32,36 @@ describe('parseTechnicalFields', () => {
expect(() => parseTechnicalFields(ALERT_WITH_DEFAULT_FIELDS)).not.toThrow();
});

it('parses an alert without reason', () => {
const ALERT_WITHOUT_REASON = {
'@timestamp': ['2021-12-06T12:25:47.356Z'],
it('parses an alert with missing required fields with error', () => {
const ALERT_WITH_MISSING_REQUIRED_FIELDS = {
'@timestamp': ['2021-12-06T12:30:59.411Z'],
'kibana.alert.duration.us': ['488935266000'],
'kibana.alert.reason': ['host.uptime has reported no data over the past 1m for *'],
'kibana.alert.workflow_status': ['open'],
'kibana.alert.start': ['2021-11-30T20:42:04.145Z'],
'event.action': ['active'],
'kibana.alert.instance.id': ['*'],
'kibana.version': ['8.1.0'],
'event.kind': ['signal'],
};
expect(() => parseTechnicalFields(ALERT_WITH_MISSING_REQUIRED_FIELDS)).toThrow();
});

it('parses an alert with missing optional fields without error', () => {
const ALERT_WITH_MISSING_OPTIONAL_FIELDS = {
'@timestamp': ['2021-12-06T12:30:59.411Z'],
'kibana.alert.rule.uuid': ['c8ef4420-4604-11ec-b08c-c590e7b8c4cd'],
'kibana.alert.status': ['active'],
'kibana.alert.duration.us': ['1806762716000'],
'kibana.alert.rule.producer': ['infrastructure'],
'kibana.alert.rule.consumer': ['alerts'],
'kibana.alert.rule.category': ['Metric threshold'],
'kibana.alert.rule.rule_type_id': ['metrics.alert.threshold'],
'kibana.alert.instance.id': ['*'],
'kibana.alert.rule.name': ['Uptime'],
'kibana.alert.uuid': ['f31f5726-3c47-4c88-bc42-4e1fbde17e34'],
'kibana.space_ids': ['default'],
};
expect(() => parseTechnicalFields(ALERT_WITHOUT_REASON)).not.toThrow();

expect(() => parseTechnicalFields(ALERT_WITH_MISSING_OPTIONAL_FIELDS)).not.toThrow();
});
});

0 comments on commit ad2c223

Please sign in to comment.