Skip to content

Commit 80c3b2e

Browse files
authored
Merge pull request #61 from CloudBoltSoftware/feature/ENG-24390-jobs-api-actions
Feature/eng 24390 jobs api actions
2 parents 547cb7a + 149cc55 commit 80c3b2e

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-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.7",
3+
"version": "0.5.8",
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/JobsService.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,35 @@ export default {
1010
*/
1111
list: (options) => crud.getItems(URL, options),
1212

13+
/**
14+
* Cancel one or more jobs
15+
* @param {object} payload
16+
* @param {array} payload.jobs List of Job hrefs to clone
17+
* @returns {Promise} resolves with a cloudbolt API Response object of Job objects
18+
*/
19+
cancel: (payload) => crud.postItem(URL, payload),
20+
1321
/**
1422
* Retrieve an existing job
1523
* @param {string} id or global_id
1624
* @param options anything parsable by URLSearchParams. See useful options here https://docs.cloudbolt.io/articles/#!cloudbolt-latest-docs/api-conventions/a/h2__904191799
1725
* @returns {Promise} resolves with a cloudbolt API Response object of Job objects
1826
*/
19-
get: (id, options) => crud.getItemById(URL, id, options)
27+
get: (id, options) => crud.getItemById(URL, id, options),
28+
29+
/**
30+
* Clone (re-run) a job
31+
* @param {string} id or global_id
32+
* @returns {Promise} resolves with a cloudbolt API Response object of Job object
33+
*/
34+
clone: (id) => crud.postItem(`${URL}/${id}/clone`, null),
35+
36+
/**
37+
* Resume a paused job
38+
* @param {string} id or global_id
39+
* @param {object} payload
40+
* @param {'STEP' | 'NEXT' | 'RETURN' | 'RUNNING'} payload.resume_type Job href to resume
41+
*/
42+
resume: (id, payload) =>
43+
crud.patchItemById(`${URL}/${id}/resume`, null, payload)
2044
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,29 @@ test('get calls the correct endpoint', async () => {
1616
await JobsService.get('job-id')
1717
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/jobs/job-id/')
1818
})
19+
20+
test('cancel calls the correct endpoint', async () => {
21+
const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue()
22+
23+
const payload = {
24+
jobs: ['/v3/cmp/jobs/job-id/']
25+
}
26+
await JobsService.cancel(payload)
27+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/jobs/', payload)
28+
})
29+
30+
test('clone calls the correct endpoint', async () => {
31+
const mockFn = jest.spyOn(baseApi, 'post').mockResolvedValue()
32+
33+
await JobsService.clone('job-id')
34+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/jobs/job-id/clone/', null)
35+
})
36+
37+
test('resume calls the correct endpoint', async () => {
38+
const mockFn = jest.spyOn(baseApi, 'patch').mockResolvedValue()
39+
const payload = {
40+
resume_type: 'STEP'
41+
}
42+
await JobsService.resume('job-id', payload)
43+
expect(mockFn).toHaveBeenCalledWith('/v3/cmp/jobs/job-id/resume/', payload)
44+
})

0 commit comments

Comments
 (0)