-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
779 additions
and
84 deletions.
There are no files selected for viewing
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
87 changes: 87 additions & 0 deletions
87
...ggers_actions_ui/public/application/components/builtin_action_types/resilient/api.test.ts
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,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { httpServiceMock } from '../../../../../../../../src/core/public/mocks'; | ||
import { getIncidentTypes, getSeverity } from './api'; | ||
|
||
const incidentTypesResponse = { | ||
status: 'ok', | ||
data: [ | ||
{ id: 17, name: 'Communication error (fax; email)' }, | ||
{ id: 1001, name: 'Custom type' }, | ||
{ id: 21, name: 'Denial of Service' }, | ||
{ id: 6, name: 'Improper disposal: digital asset(s)' }, | ||
{ id: 7, name: 'Improper disposal: documents / files' }, | ||
{ id: 4, name: 'Lost documents / files / records' }, | ||
{ id: 3, name: 'Lost PC / laptop / tablet' }, | ||
{ id: 1, name: 'Lost PDA / smartphone' }, | ||
{ id: 8, name: 'Lost storage device / media' }, | ||
{ id: 19, name: 'Malware' }, | ||
{ id: 23, name: 'Not an Issue' }, | ||
{ id: 18, name: 'Other' }, | ||
{ id: 22, name: 'Phishing' }, | ||
{ id: 11, name: 'Stolen documents / files / records' }, | ||
{ id: 12, name: 'Stolen PC / laptop / tablet' }, | ||
{ id: 13, name: 'Stolen PDA / smartphone' }, | ||
{ id: 14, name: 'Stolen storage device / media' }, | ||
{ id: 20, name: 'System Intrusion' }, | ||
{ id: 16, name: 'TBD / Unknown' }, | ||
{ id: 15, name: 'Vendor / 3rd party error' }, | ||
], | ||
actionId: 'test', | ||
}; | ||
|
||
const severityResponse = { | ||
status: 'ok', | ||
data: [ | ||
{ id: 4, name: 'Low' }, | ||
{ id: 5, name: 'Medium' }, | ||
{ id: 6, name: 'High' }, | ||
], | ||
actionId: 'test', | ||
}; | ||
|
||
describe('Resilient API', () => { | ||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('getIncidentTypes', () => { | ||
test('should call get choices API', async () => { | ||
const abortCtrl = new AbortController(); | ||
http.post.mockResolvedValueOnce(incidentTypesResponse); | ||
const res = await getIncidentTypes({ | ||
http, | ||
signal: abortCtrl.signal, | ||
connectorId: 'test', | ||
}); | ||
|
||
expect(res).toEqual(incidentTypesResponse); | ||
expect(http.post).toHaveBeenCalledWith('/api/actions/action/test/_execute', { | ||
body: '{"params":{"subAction":"incidentTypes","subActionParams":{}}}', | ||
signal: abortCtrl.signal, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getSeverity', () => { | ||
test('should call get choices API', async () => { | ||
const abortCtrl = new AbortController(); | ||
http.post.mockResolvedValueOnce(severityResponse); | ||
const res = await getSeverity({ | ||
http, | ||
signal: abortCtrl.signal, | ||
connectorId: 'test', | ||
}); | ||
|
||
expect(res).toEqual(severityResponse); | ||
expect(http.post).toHaveBeenCalledWith('/api/actions/action/test/_execute', { | ||
body: '{"params":{"subAction":"severity","subActionParams":{}}}', | ||
signal: abortCtrl.signal, | ||
}); | ||
}); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
...gers_actions_ui/public/application/components/builtin_action_types/servicenow/api.test.ts
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,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { httpServiceMock } from '../../../../../../../../src/core/public/mocks'; | ||
import { getChoices } from './api'; | ||
|
||
const choicesResponse = { | ||
status: 'ok', | ||
data: [ | ||
{ | ||
dependent_value: '', | ||
label: '1 - Critical', | ||
value: '1', | ||
}, | ||
{ | ||
dependent_value: '', | ||
label: '2 - High', | ||
value: '2', | ||
}, | ||
{ | ||
dependent_value: '', | ||
label: '3 - Moderate', | ||
value: '3', | ||
}, | ||
{ | ||
dependent_value: '', | ||
label: '4 - Low', | ||
value: '4', | ||
}, | ||
{ | ||
dependent_value: '', | ||
label: '5 - Planning', | ||
value: '5', | ||
}, | ||
], | ||
}; | ||
|
||
describe('ServiceNow API', () => { | ||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('getChoices', () => { | ||
test('should call get choices API', async () => { | ||
const abortCtrl = new AbortController(); | ||
http.post.mockResolvedValueOnce(choicesResponse); | ||
const res = await getChoices({ | ||
http, | ||
signal: abortCtrl.signal, | ||
connectorId: 'test', | ||
field: 'priority', | ||
}); | ||
|
||
expect(res).toEqual(choicesResponse); | ||
expect(http.post).toHaveBeenCalledWith('/api/actions/action/test/_execute', { | ||
body: '{"params":{"subAction":"getChoices","subActionParams":{"field":"priority"}}}', | ||
signal: abortCtrl.signal, | ||
}); | ||
}); | ||
}); | ||
}); |
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.