From 1723e065f34e63478d3cca99229cd4862b11a480 Mon Sep 17 00:00:00 2001 From: Alexandra Doak Date: Wed, 5 Oct 2022 16:03:25 -0400 Subject: [PATCH] Fixing jest tests --- .../lib/get_execution_log_aggregation.test.ts | 90 ++++++++++--------- .../tests/get_execution_log.test.ts | 60 ++++++------- 2 files changed, 77 insertions(+), 73 deletions(-) diff --git a/x-pack/plugins/alerting/server/lib/get_execution_log_aggregation.test.ts b/x-pack/plugins/alerting/server/lib/get_execution_log_aggregation.test.ts index dad1263e73772..8670875336550 100644 --- a/x-pack/plugins/alerting/server/lib/get_execution_log_aggregation.test.ts +++ b/x-pack/plugins/alerting/server/lib/get_execution_log_aggregation.test.ts @@ -779,12 +779,13 @@ describe('formatExecutionLogResult', () => { _id: 'S4wIZX8B8TGQpG7XQZns', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -860,12 +861,13 @@ describe('formatExecutionLogResult', () => { _id: 'a4wIZX8B8TGQpG7Xwpnz', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -1013,13 +1015,14 @@ describe('formatExecutionLogResult', () => { _id: 'S4wIZX8B8TGQpG7XQZns', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'failure', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['failure'], + message: [ "rule execution failure: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", - 'error.message': 'I am erroring in rule execution!!', + ], + 'error.message': ['I am erroring in rule execution!!'], }, }, ], @@ -1095,12 +1098,13 @@ describe('formatExecutionLogResult', () => { _id: 'a4wIZX8B8TGQpG7Xwpnz', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -1248,12 +1252,13 @@ describe('formatExecutionLogResult', () => { _id: 'dJkWa38B1ylB1EvsAckB', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -1324,12 +1329,13 @@ describe('formatExecutionLogResult', () => { _id: 'a4wIZX8B8TGQpG7Xwpnz', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -1477,12 +1483,13 @@ describe('formatExecutionLogResult', () => { _id: '7xKcb38BcntAq5ycFwiu', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -1558,12 +1565,13 @@ describe('formatExecutionLogResult', () => { _id: 'zRKbb38BcntAq5ycOwgk', _score: 1.0, fields: { - 'rule.id': 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - 'rule.name': 'rule_name', - 'kibana.version': '8.2.0', - 'kibana.alerting.outcome': 'success', - message: + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule_name'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], diff --git a/x-pack/plugins/alerting/server/rules_client/tests/get_execution_log.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/get_execution_log.test.ts index 83b85f4879cff..6c6763ab2dd4e 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/get_execution_log.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/get_execution_log.test.ts @@ -20,7 +20,10 @@ import { SavedObject } from '@kbn/core/server'; import { RawRule } from '../../types'; import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks'; import { getBeforeSetup, mockedDateString, setGlobalDate } from './lib'; -import { getExecutionLogAggregation } from '../../lib/get_execution_log_aggregation'; +import { + getExecutionLogAggregation, + getExecutionLogRuntimeMappings, +} from '../../lib/get_execution_log_aggregation'; import { fromKueryExpression } from '@kbn/es-query'; const taskManager = taskManagerMock.createStart(); @@ -142,22 +145,15 @@ const aggregateResults = { _index: '.kibana-event-log-8.2.0-000001', _id: 'S4wIZX8B8TGQpG7XQZns', _score: 1.0, - _source: { - rule: { - id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef', - name: 'rule-name', - }, - event: { - outcome: 'success', - }, - kibana: { - version: '8.2.0', - alerting: { - outcome: 'success', - }, - }, - message: + fields: { + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule-name'], + 'event.outcome': ['success'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -191,8 +187,8 @@ const aggregateResults = { _index: '.kibana-event-log-8.2.0-000001', _id: 'S4wIZX8B8TGQpG7XQZns', _score: 1.0, - _source: { - rule: { id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef' }, + fields: { + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], }, }, ], @@ -251,19 +247,15 @@ const aggregateResults = { _index: '.kibana-event-log-8.2.0-000001', _id: 'a4wIZX8B8TGQpG7Xwpnz', _score: 1.0, - _source: { - rule: { id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef', name: 'rule-name' }, - event: { - outcome: 'success', - }, - kibana: { - version: '8.2.0', - alerting: { - outcome: 'success', - }, - }, - message: + fields: { + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], + 'rule.name': ['rule-name'], + 'event.outcome': ['success'], + 'kibana.version': ['8.2.0'], + 'kibana.alerting.outcome': ['success'], + message: [ "rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'", + ], }, }, ], @@ -297,8 +289,8 @@ const aggregateResults = { _index: '.kibana-event-log-8.2.0-000001', _id: 'S4wIZX8B8TGQpG7XQZns', _score: 1.0, - _source: { - rule: { id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef' }, + fields: { + 'rule.id': ['a348a740-9e2c-11ec-bd64-774ed95c43ef'], }, }, ], @@ -437,6 +429,7 @@ describe('getExecutionLogForRule()', () => { start: '2019-02-12T20:01:22.479Z', }, undefined, + getExecutionLogRuntimeMappings(), ]); }); @@ -463,6 +456,7 @@ describe('getExecutionLogForRule()', () => { start: '2019-02-12T20:01:22.479Z', }, ['99999'], + getExecutionLogRuntimeMappings(), ]); }); @@ -489,6 +483,7 @@ describe('getExecutionLogForRule()', () => { start: '2019-02-12T20:01:22.479Z', }, undefined, + getExecutionLogRuntimeMappings(), ]); }); @@ -516,6 +511,7 @@ describe('getExecutionLogForRule()', () => { start: '2019-02-12T20:01:22.479Z', }, undefined, + getExecutionLogRuntimeMappings(), ]); });