Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Oct 13, 2020
1 parent ffddcb7 commit c76d3c4
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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' }]);
});
});
});

0 comments on commit c76d3c4

Please sign in to comment.