From cef0969e3eb0968e0ea648368d595ae735a34f17 Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Thu, 14 Nov 2019 17:25:50 -0500 Subject: [PATCH] replaces mock implementation with mock return value for unit test --- .../lib/detection_engine/alerts/utils.test.ts | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/alerts/utils.test.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/alerts/utils.test.ts index 1518b3f9fd0091f..af0f02079e94ab1 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/alerts/utils.test.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/alerts/utils.test.ts @@ -78,34 +78,15 @@ describe('utils', () => { test('create successful bulk index', async () => { const sampleParams = sampleSignalAlertParams(undefined); const sampleSearchResult = sampleDocSearchResultsNoSortId; - const bulkBody = sampleDocSearchResultsNoSortId.hits.hits.flatMap(doc => [ - { - index: { - _index: process.env.SIGNALS_INDEX || DEFAULT_SIGNALS_INDEX, - _id: doc._id, + mockService.callCluster.mockReturnValueOnce({ + took: 100, + errors: false, + items: [ + { + fakeItemValue: 'fakeItemKey', }, - }, - buildBulkBody(doc, sampleParams), - ]); - mockService.callCluster.mockImplementation( - async (action: string, params: BulkIndexDocumentsParams) => { - expect(action).toEqual('bulk'); - expect(params.index).toEqual(DEFAULT_SIGNALS_INDEX); - - // timestamps are annoying... - (bulkBody[1] as SignalHit).signal['@timestamp'] = params.body[1].signal['@timestamp']; - expect(params.body).toEqual(bulkBody); - return { - took: 100, - errors: false, - items: [ - { - fakeItemValue: 'fakeItemKey', - }, - ], - }; - } - ); + ], + }); const successfulSingleBulkIndex = await singleBulkIndex( sampleSearchResult, sampleParams,