Skip to content

Commit 57e5c91

Browse files
cedricmessiantCédric Messiant
authored andcommitted
feat(stack): Expose JobCollection via client.collection('io.cozy.jobs')
1 parent 66dfdd7 commit 57e5c91

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/cozy-stack-client/src/CozyStackClient.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import AppCollection, { APPS_DOCTYPE } from './AppCollection'
22
import AppToken from './AppToken'
33
import DocumentCollection from './DocumentCollection'
44
import FileCollection from './FileCollection'
5+
import JobCollection, { JOBS_DOCTYPE } from './JobCollection'
56
import KonnectorCollection, { KONNECTORS_DOCTYPE } from './KonnectorCollection'
67
import SharingCollection from './SharingCollection'
78
import PermissionCollection from './PermissionCollection'
89
import TriggerCollection, { TRIGGERS_DOCTYPE } from './TriggerCollection'
9-
import JobCollection from './JobCollection'
1010
import getIconURL from './getIconURL'
1111
import logDeprecate from './logDeprecate'
1212
import errors from './errors'
@@ -57,6 +57,8 @@ class CozyStackClient {
5757
return new PermissionCollection(doctype, this)
5858
case TRIGGERS_DOCTYPE:
5959
return new TriggerCollection(this)
60+
case JOBS_DOCTYPE:
61+
return new JobCollection(this)
6062
default:
6163
return new DocumentCollection(doctype, this)
6264
}

packages/cozy-stack-client/src/JobCollection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const JOB_DOCTYPE = 'io.cozy.jobs'
1+
export const JOBS_DOCTYPE = 'io.cozy.jobs'
22

33
class JobCollection {
44
constructor(stackClient) {
@@ -11,7 +11,7 @@ class JobCollection {
1111
create(workerType, args, options) {
1212
return this.stackClient.fetchJSON('POST', `/jobs/queue/${workerType}`, {
1313
data: {
14-
type: JOB_DOCTYPE,
14+
type: JOBS_DOCTYPE,
1515
attributes: {
1616
arguments: args || {},
1717
options: options || {}

packages/cozy-stack-client/src/__tests__/CozyStackClient.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import CozyStackClient, { FetchError } from '../CozyStackClient'
55
import DocumentCollection from '../DocumentCollection'
6+
import JobCollection from '../JobCollection'
67
import KonnectorCollection from '../KonnectorCollection'
78
import jestFetchMock from 'jest-fetch-mock'
89

@@ -60,6 +61,10 @@ describe('CozyStackClient', () => {
6061
)
6162
})
6263

64+
it('should return a JobCollection for io.cozy.jobs doctype', () => {
65+
expect(client.collection('io.cozy.jobs')).toBeInstanceOf(JobCollection)
66+
})
67+
6368
it('should throw if the doctype is undefined', () => {
6469
expect(() => client.collection()).toThrow()
6570
})

0 commit comments

Comments
 (0)