Skip to content

Commit 53ad1ab

Browse files
bernardtheredorvisevans
authored andcommitted
IWH support & tests
1 parent 95d4508 commit 53ad1ab

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import crud from '../../../crudOperations'
2+
3+
const URL = 'v3/cmp/inboundWebHooks'
4+
5+
export default {
6+
/**
7+
* Retrieve a list of existing Inbound Web Hooks
8+
* @param options anything parsable by URLSearchParams. See useful options here https://docs.cloudbolt.io/articles/#!cloudbolt-latest-docs/api-conventions/a/h2__904191799
9+
* @returns {Promise} resolves with a list of existing Inbound Web Hooks
10+
*/
11+
list: (options) => crud.getItems(URL, options),
12+
13+
/**
14+
* Retrieve an existing Inbound Web Hook by id
15+
* @param {string} id or global_id
16+
* @returns {Promise} resolves with a cloudbolt API Response object of the Inbound Web Hook object
17+
*/
18+
get: (id) => crud.getItemById(URL, id),
19+
20+
/**
21+
* Export an existing Inbound Web Hook as a zipfile for a given id
22+
* @param {string} id or global_id
23+
* @param {object} InboundWebHookOptions
24+
* @param {string} [InboundWebHookOptions.password] password to the zip if it's password-protected
25+
* @param {boolean} [InboundWebHookOptions.instanceSpecificInfo=false] determines if the Inbound Web Hook should include info specific to the CloudBolt instance
26+
* @returns {Promise} resolves with a cloudbolt API Export Inbound Web Hook Success Response and zip file
27+
*/
28+
export: (id, InboundWebHookOptions) =>
29+
crud.downloadWithPayload(URL, id, InboundWebHookOptions),
30+
31+
/**
32+
* Run an Inbound Web Hook via POST
33+
* @param {string} id or global_id
34+
* @param {object} payload Inbound Web Hook object definition
35+
* @returns {Promise} resolves with a cloudbolt API Run Inbound Web Hook Success Response
36+
*/
37+
runPost: (id, payload) =>
38+
crud.postItem(`${URL}/${id}/run`, payload),
39+
40+
/**
41+
* Run an Inbound Web Hook via GET
42+
* @param {string} id or global_id
43+
* @param {object} options querystring name value pairs to be used as Action input values
44+
* @returns {Promise} resolves with a cloudbolt API Run Inbound Web Hook Success Response
45+
*/
46+
runGet: (id, options) =>
47+
crud.getItemByEndpoint(`${URL}/${id}/run`, options),
48+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { baseApi } from '../../../baseApi'
2+
import InboundWebHook from './InboundWebHookService'
3+
4+
test('list calls the correct endpoint', async () => {
5+
const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({
6+
data: { hello: 'world' }
7+
})
8+
await InboundWebHook.list()
9+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/inboundWebHooks/')
10+
})
11+
12+
test('get calls the correct endpoint', async () => {
13+
const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({
14+
data: { hello: 'world' }
15+
})
16+
await InboundWebHook.get('inboundWebHook-id')
17+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/inboundWebHooks/inboundWebHook-id/')
18+
})
19+
20+
test('export calls the correct endpoint', async () => {
21+
const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({
22+
data: { hello: 'world' },
23+
headers: {
24+
'content-disposition': 'attachment; filename=action.zip'
25+
}
26+
})
27+
28+
await InboundWebHook.export('inboundWebHook-id')
29+
expect(mockFn).toHaveBeenCalledWith(
30+
'/v3/cmp/inboundWebHooks/inboundWebHook-id/export/',
31+
{},
32+
{ responseType: 'blob' }
33+
)
34+
})
35+
36+
test('export with options calls the correct endpoint', async () => {
37+
const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({
38+
data: { hello: 'world' },
39+
headers: {
40+
'content-disposition': 'attachment; filename=action.zip'
41+
}
42+
})
43+
const mockinboundWebHookOptions = {
44+
password: 'worldinboundWebHook',
45+
instanceSpecificInfo: true
46+
}
47+
await InboundWebHook.export('inboundWebHook-id', mockinboundWebHookOptions)
48+
expect(mockFn).toHaveBeenCalledWith(
49+
'/v3/cmp/inboundWebHooks/inboundWebHook-id/export/',
50+
mockinboundWebHookOptions,
51+
{ responseType: 'blob' }
52+
)
53+
})
54+
55+
test('run calls the correct endpoint', async () => {
56+
const mockFn = jest.spyOn(baseApi, 'get').mockResolvedValue({
57+
data: { hello: 'world' }
58+
})
59+
const mockParameters = {
60+
param1: 'value1'
61+
}
62+
await InboundWebHook.runGet('inboundWebHook-id', mockParameters)
63+
expect(mockFn).toHaveBeenCalledWith(
64+
'/v3/cmp/inboundWebHooks/inboundWebHook-id/run/?param1=value1',
65+
)
66+
})
67+
68+
test('run calls the correct endpoint', async () => {
69+
const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({
70+
data: { hello: 'world' }
71+
})
72+
const mockPayload = {
73+
param1: 'value1'
74+
}
75+
await InboundWebHook.runPost('inboundWebHook-id', mockPayload)
76+
expect(mockFn).toHaveBeenCalledWith(
77+
'/v3/cmp/inboundWebHooks/inboundWebHook-id/run/',
78+
mockPayload
79+
)
80+
})

src/api/services/v3/cmp/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import EnvironmentsService from './EnvironmentsService'
1414
import EulaService from './EulaService'
1515
import GroupsService from './GroupsService'
1616
import HistoriesService from './HistoriesService'
17+
import InboundWebHookService from './InboundWebHookService'
1718
import JobsService from './JobsService'
1819
import LicensingService from './LicensingService'
1920
import LoggingService from './LoggingService'
@@ -60,6 +61,7 @@ export default {
6061
eula: EulaService,
6162
groups: GroupsService,
6263
histories: HistoriesService,
64+
inboundWebHooks: InboundWebHookService,
6365
jobs: JobsService,
6466
licensing: LicensingService,
6567
logging: LoggingService,

src/api/services/v3/cmp/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const services = [
2323
'eula',
2424
'groups',
2525
'histories',
26+
'inboundWebHooks',
2627
'jobs',
2728
'licensing',
2829
'licensing',

0 commit comments

Comments
 (0)