-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ResponseOps][Cases] Set case alert attachment rule info to null (#12…
…3094) * Setting rule info to null * Renaming variables * Addressing PR feedback Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
3280400
commit d1eb0df
Showing
12 changed files
with
882 additions
and
23 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
x-pack/plugins/cases/public/components/user_actions/comment/alert.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CommentResponseAlertsType } from '../../../../common/api'; | ||
import { SnakeToCamelCase } from '../../../../common/types'; | ||
import { getRuleId, getRuleName } from './alert'; | ||
import { Ecs } from '../../../containers/types'; | ||
|
||
describe('rule getters', () => { | ||
describe.each([ | ||
['getRuleId', getRuleId], | ||
['getRuleName', getRuleName], | ||
])('%s null checks', (name, funcToExec) => { | ||
it('returns null if the comment field is an empty string', () => { | ||
const comment = { | ||
rule: { | ||
id: '', | ||
name: '', | ||
}, | ||
} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
|
||
expect(funcToExec(comment)).toBeNull(); | ||
}); | ||
|
||
it('returns null if the comment field is an empty string in an array', () => { | ||
const comment = { | ||
rule: { | ||
id: [''], | ||
name: [''], | ||
}, | ||
} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
|
||
expect(funcToExec(comment)).toBeNull(); | ||
}); | ||
|
||
it('returns null if the comment does not have a rule field', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
|
||
expect(funcToExec(comment)).toBeNull(); | ||
}); | ||
|
||
it('returns null if the signals and alert field is an empty string', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
signal: { rule: { id: '', name: '' } }, | ||
kibana: { alert: { rule: { uuid: '', name: '' } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe.each([ | ||
['getRuleId', getRuleId, '1'], | ||
['getRuleName', getRuleName, 'Rule name1'], | ||
])('%s', (name, funcToExec, expectedResult) => { | ||
it('returns the first entry in the comment field', () => { | ||
const comment = { | ||
rule: { | ||
id: ['1', '2'], | ||
name: ['Rule name1', 'Rule name2'], | ||
}, | ||
} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
|
||
expect(funcToExec(comment)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns signal field', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { signal: { rule: { id: '1', name: 'Rule name1' } } } as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns kibana alert field', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
kibana: { alert: { rule: { uuid: '1', name: 'Rule name1' } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns signal field even when kibana alert field is defined', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
signal: { rule: { id: '1', name: 'Rule name1' } }, | ||
kibana: { alert: { rule: { uuid: 'rule id1', name: 'other rule name1' } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns the first entry in the signals field', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
signal: { rule: { id: '1', name: 'Rule name1' } }, | ||
kibana: { alert: { rule: { uuid: 'rule id1', name: 'other rule name1' } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns the alert field if the signals field is an empty string', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
signal: { rule: { id: '', name: '' } }, | ||
kibana: { alert: { rule: { uuid: '1', name: 'Rule name1' } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns the alert field if the signals field is an empty string in an array', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
signal: { rule: { id: [''], name: [''] } }, | ||
kibana: { alert: { rule: { uuid: '1', name: 'Rule name1' } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
|
||
it('returns the alert field first item if the signals field is an empty string in an array', () => { | ||
const comment = {} as unknown as SnakeToCamelCase<CommentResponseAlertsType>; | ||
const alert = { | ||
signal: { rule: { id: [''], name: [''] } }, | ||
kibana: { alert: { rule: { uuid: ['1', '2'], name: ['Rule name1', 'Rule name2'] } } }, | ||
} as unknown as Ecs; | ||
|
||
expect(funcToExec(comment, alert)).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.