-
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.
- Loading branch information
1 parent
749793c
commit db83818
Showing
7 changed files
with
250 additions
and
190 deletions.
There are no files selected for viewing
190 changes: 0 additions & 190 deletions
190
...ggers_actions_ui/public/application/lib/action_connector_api/action_connector_api.test.ts
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...s/triggers_actions_ui/public/application/lib/action_connector_api/connector_types.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,49 @@ | ||
/* | ||
* 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 { ActionType } from '../../../types'; | ||
import { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
import { loadActionTypes } from './index'; | ||
|
||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('loadActionTypes', () => { | ||
test('should call get types API', async () => { | ||
const apiResponseValue = [ | ||
{ | ||
id: 'test', | ||
name: 'Test', | ||
enabled: true, | ||
enabled_in_config: true, | ||
enabled_in_license: true, | ||
minimum_license_required: 'basic', | ||
}, | ||
]; | ||
http.get.mockResolvedValueOnce(apiResponseValue); | ||
|
||
const resolvedValue: ActionType[] = [ | ||
{ | ||
id: 'test', | ||
name: 'Test', | ||
enabled: true, | ||
enabledInConfig: true, | ||
enabledInLicense: true, | ||
minimumLicenseRequired: 'basic', | ||
}, | ||
]; | ||
|
||
const result = await loadActionTypes({ http }); | ||
expect(result).toEqual(resolvedValue); | ||
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(` | ||
Array [ | ||
"/api/actions/connector_types", | ||
] | ||
`); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
...lugins/triggers_actions_ui/public/application/lib/action_connector_api/connectors.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,27 @@ | ||
/* | ||
* 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 { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
import { loadAllActions } from './index'; | ||
|
||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('loadAllActions', () => { | ||
test('should call getAll actions API', async () => { | ||
http.get.mockResolvedValueOnce([]); | ||
|
||
const result = await loadAllActions({ http }); | ||
expect(result).toEqual([]); | ||
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(` | ||
Array [ | ||
"/api/actions/connectors", | ||
] | ||
`); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...ck/plugins/triggers_actions_ui/public/application/lib/action_connector_api/create.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,48 @@ | ||
/* | ||
* 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 { ActionConnectorWithoutId } from '../../../types'; | ||
import { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
import { createActionConnector } from './index'; | ||
|
||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('createActionConnector', () => { | ||
test('should call create action API', async () => { | ||
const apiResponse = { | ||
connector_type_id: 'test', | ||
is_preconfigured: false, | ||
name: 'My test', | ||
config: {}, | ||
secrets: {}, | ||
id: '123', | ||
}; | ||
http.post.mockResolvedValueOnce(apiResponse); | ||
|
||
const connector: ActionConnectorWithoutId<{}, {}> = { | ||
actionTypeId: 'test', | ||
isPreconfigured: false, | ||
name: 'My test', | ||
config: {}, | ||
secrets: {}, | ||
}; | ||
const resolvedValue = { ...connector, id: '123' }; | ||
|
||
const result = await createActionConnector({ http, connector }); | ||
expect(result).toEqual(resolvedValue); | ||
expect(http.post.mock.calls[0]).toMatchInlineSnapshot(` | ||
Array [ | ||
"/api/actions/connector", | ||
Object { | ||
"body": "{\\"name\\":\\"My test\\",\\"config\\":{},\\"secrets\\":{},\\"connector_type_id\\":\\"test\\",\\"is_preconfigured\\":false}", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
...ck/plugins/triggers_actions_ui/public/application/lib/action_connector_api/delete.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,35 @@ | ||
/* | ||
* 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 { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
import { deleteActions } from './index'; | ||
|
||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('deleteActions', () => { | ||
test('should call delete API per action', async () => { | ||
const ids = ['1', '2', '3']; | ||
|
||
const result = await deleteActions({ ids, http }); | ||
expect(result).toEqual({ errors: [], successes: [undefined, undefined, undefined] }); | ||
expect(http.delete.mock.calls).toMatchInlineSnapshot(` | ||
Array [ | ||
Array [ | ||
"/api/actions/connector/1", | ||
], | ||
Array [ | ||
"/api/actions/connector/2", | ||
], | ||
Array [ | ||
"/api/actions/connector/3", | ||
], | ||
] | ||
`); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...k/plugins/triggers_actions_ui/public/application/lib/action_connector_api/execute.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,42 @@ | ||
/* | ||
* 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 { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
import { executeAction } from './index'; | ||
|
||
const http = httpServiceMock.createStartContract(); | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('executeAction', () => { | ||
test('should call execute API', async () => { | ||
const id = '123'; | ||
const params = { | ||
stringParams: 'someString', | ||
numericParams: 123, | ||
}; | ||
|
||
http.post.mockResolvedValueOnce({ | ||
connector_id: id, | ||
status: 'ok', | ||
}); | ||
|
||
const result = await executeAction({ id, http, params }); | ||
expect(result).toEqual({ | ||
actionId: id, | ||
status: 'ok', | ||
}); | ||
expect(http.post.mock.calls[0]).toMatchInlineSnapshot(` | ||
Array [ | ||
"/api/actions/connector/123/_execute", | ||
Object { | ||
"body": "{\\"params\\":{\\"stringParams\\":\\"someString\\",\\"numericParams\\":123}}", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.