From c76d3c48d1394ad6e359ffd6a6fe1a87a66640d3 Mon Sep 17 00:00:00 2001 From: FrankHassanabad Date: Tue, 13 Oct 2020 09:38:45 -0600 Subject: [PATCH] Added unit tests --- .../threat_mapping/get_threat_list.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/get_threat_list.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/get_threat_list.test.ts index 8deda5f03f5e6..59919a1cef8b1 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/get_threat_list.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/get_threat_list.test.ts @@ -18,6 +18,16 @@ describe('get_threat_signals', () => { expect(sortOrder).toEqual([{ '@timestamp': 'asc' }]); }); + test('it should return sort field of just timestamp if given no sort order for a list item index', () => { + const sortOrder = getSortWithTieBreaker({ + sortField: undefined, + sortOrder: undefined, + index: ['list-item-index-123'], + listItemIndex: 'list-item-index-123', + }); + expect(sortOrder).toEqual([{ tie_breaker_id: 'asc' }]); + }); + test('it should return sort field of timestamp with asc even if sortOrder is changed as it is hard wired in', () => { const sortOrder = getSortWithTieBreaker({ sortField: undefined, @@ -28,6 +38,16 @@ describe('get_threat_signals', () => { expect(sortOrder).toEqual([{ '@timestamp': 'asc' }]); }); + test('it should return sort field of timestamp with asc even if sortOrder is changed as it is hard wired in for a list item index', () => { + const sortOrder = getSortWithTieBreaker({ + sortField: undefined, + sortOrder: 'desc', + index: ['list-index-123'], + listItemIndex: 'list-index-123', + }); + expect(sortOrder).toEqual([{ tie_breaker_id: 'asc' }]); + }); + test('it should return sort field of an extra field if given one', () => { const sortOrder = getSortWithTieBreaker({ sortField: 'some-field', @@ -38,6 +58,16 @@ describe('get_threat_signals', () => { expect(sortOrder).toEqual([{ 'some-field': 'asc', '@timestamp': 'asc' }]); }); + test('it should return sort field of an extra field if given one for a list item index', () => { + const sortOrder = getSortWithTieBreaker({ + sortField: 'some-field', + sortOrder: undefined, + index: ['list-index-123'], + listItemIndex: 'list-index-123', + }); + expect(sortOrder).toEqual([{ 'some-field': 'asc', tie_breaker_id: 'asc' }]); + }); + test('it should return sort field of desc if given one', () => { const sortOrder = getSortWithTieBreaker({ sortField: 'some-field', @@ -47,5 +77,15 @@ describe('get_threat_signals', () => { }); expect(sortOrder).toEqual([{ 'some-field': 'desc', '@timestamp': 'asc' }]); }); + + test('it should return sort field of desc if given one for a list item index', () => { + const sortOrder = getSortWithTieBreaker({ + sortField: 'some-field', + sortOrder: 'desc', + index: ['list-index-123'], + listItemIndex: 'list-index-123', + }); + expect(sortOrder).toEqual([{ 'some-field': 'desc', tie_breaker_id: 'asc' }]); + }); }); });