From f7436e706756b479108d14ff134f99a8bbb2c3b6 Mon Sep 17 00:00:00 2001 From: mgiota Date: Mon, 30 Aug 2021 20:42:55 +0200 Subject: [PATCH] fix failing tests --- .../utils/create_lifecycle_rule_type.test.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/rule_registry/server/utils/create_lifecycle_rule_type.test.ts b/x-pack/plugins/rule_registry/server/utils/create_lifecycle_rule_type.test.ts index 2b138ae723305..b2cd69be7fdad 100644 --- a/x-pack/plugins/rule_registry/server/utils/create_lifecycle_rule_type.test.ts +++ b/x-pack/plugins/rule_registry/server/utils/create_lifecycle_rule_type.test.ts @@ -263,6 +263,36 @@ describe('createLifecycleRuleTypeFactory', () => { }, ]); + // TODO mock the resolved value before calling alertWithLifecycle again + const lastOpbeansNodeDoc = helpers.ruleDataClientMock + .getWriter() + .bulk.mock.calls[0][0].body?.concat() + .reverse() + .find( + (doc: any) => !('index' in doc) && doc['service.name'] === 'opbeans-node' + ) as Record; + + const stored = mapValues(lastOpbeansNodeDoc, (val) => { + return castArray(val); + }); + + helpers.ruleDataClientMock.getReader().search.mockResolvedValueOnce({ + hits: { + hits: [{ fields: stored } as any], + total: { + value: 1, + relation: 'eq', + }, + }, + took: 0, + timed_out: false, + _shards: { + failed: 0, + successful: 1, + total: 1, + }, + }); + await helpers.alertWithLifecycle([ { id: 'opbeans-java', @@ -274,6 +304,7 @@ describe('createLifecycleRuleTypeFactory', () => { id: 'opbeans-node', fields: { 'service.name': 'opbeans-node', + 'kibana.alert.workflow_status': 'closed', }, }, ]); @@ -281,7 +312,6 @@ describe('createLifecycleRuleTypeFactory', () => { it('writes the correct alerts', () => { expect(helpers.ruleDataClientMock.getWriter().bulk).toHaveBeenCalledTimes(2); - const body = helpers.ruleDataClientMock.getWriter().bulk.mock.calls[1][0].body!; const documents = body.filter((op: any) => !('index' in op)) as any[];