Skip to content

Commit 220fd8d

Browse files
authored
Merge pull request #53 from CloudBoltSoftware/feature/ENG-23580-api-helper-custom-forms-phase1
Feature/eng 23580 api helper custom forms phase1.1
2 parents 21952c7 + 3659c44 commit 220fd8d

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudbolt/cb-api-helper",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"scripts": {
55
"co:login": "aws sso login && aws codeartifact login --tool npm --repository cloudbolt-npm --domain cloudbolt --domain-owner 499620025628",
66
"husky:install": "husky install",

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,20 @@ export default {
1515
* @param {string} id or global_id
1616
* @returns {Promise} resolves with a cloudbolt API Response object of the Custom Form object
1717
*/
18-
get: (id) => crud.getItemById(URL, id)
18+
get: (id) => crud.getItemById(URL, id),
19+
20+
/**
21+
* Submit an order through Custom Forms
22+
* @param {string} id or global_id
23+
* @param {object} order order JSON generated through SurveyJS
24+
* @returns {Promise} resolves with an Custom Form order success object with all server-filled fields
25+
*/
26+
submitOrder: (id, order) => crud.createNewItem(`${URL}/${id}/submit`, order),
27+
28+
/**
29+
* Delete an existing Custom Form for a given id
30+
* @param {string} id or global_id
31+
* @returns {Promise} resolves with a cloudbolt API Success Response
32+
*/
33+
delete: (id) => crud.deleteItemById(URL, id)
1934
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,24 @@ test('get calls the correct endpoint', async () => {
1616
await CustomFormsService.get('customForm-id')
1717
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/customForms/customForm-id/')
1818
})
19+
20+
test('submit order calls the correct endpoint', async () => {
21+
const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue({
22+
data: { hello: 'world' }
23+
})
24+
const mockCustomFormOrder = {
25+
group: 'admin',
26+
imput_1: 'category world'
27+
}
28+
await CustomFormsService.submitOrder('customForm-id', mockCustomFormOrder)
29+
expect(mockFn).toHaveBeenCalledWith(
30+
'/v3/cmp/customForms/customForm-id/submit/',
31+
mockCustomFormOrder
32+
)
33+
})
34+
35+
test('delete calls the correct endpoint', async () => {
36+
const mockFn = jest.spyOn(baseApi, 'delete').mockResolvedValue({})
37+
await CustomFormsService.delete('customForm-id')
38+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/customForms/customForm-id/')
39+
})

0 commit comments

Comments
 (0)