Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgiota committed Aug 30, 2021
1 parent feb7298 commit f7436e7
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;

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',
Expand All @@ -274,14 +304,14 @@ describe('createLifecycleRuleTypeFactory', () => {
id: 'opbeans-node',
fields: {
'service.name': 'opbeans-node',
'kibana.alert.workflow_status': 'closed',
},
},
]);
});

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[];
Expand Down

0 comments on commit f7436e7

Please sign in to comment.