diff --git a/src/__tests__/c8/rest/getVariable.rest.spec.ts b/src/__tests__/c8/rest/getVariable.rest.spec.ts new file mode 100644 index 00000000..d1f4b1c4 --- /dev/null +++ b/src/__tests__/c8/rest/getVariable.rest.spec.ts @@ -0,0 +1,51 @@ +import path from 'node:path' + +import { CamundaRestClient } from '../../../c8/lib/CamundaRestClient' + +let processDefinitionId: string +const restClient = new CamundaRestClient() + +beforeAll(async () => { + const res = await restClient.deployResourcesFromFiles([ + path.join('.', 'src', '__tests__', 'testdata', 'rest-get-variable.bpmn'), + ]) + processDefinitionId = res.processes[0].processDefinitionId +}) + +test('Can get a variable', (done) => { + restClient.createProcessInstance({ + processDefinitionId, + variables: { + someNumberField: 8, + }, + }) + restClient.createJobWorker({ + type: 'get-variable', + jobHandler: async (job) => { + // query variables to get the variable key + const variableKey = '' + + const variable = await restClient.getVariable({ + variableKey, + }) + expect(variable.fullValue).toBe(8) + return job.complete().then((res) => { + done() + return res + }) + }, + worker: 'get-variable-worker', + timeout: 10000, + maxJobsToActivate: 10, + }) + // .then(() => { + // restClient + // .getVariable({ + // variableKey: 'someNumberField', + // }) + // .then((variable) => { + // expect(variable).toBe(8) + // done() + // }) + // }) +}) diff --git a/src/__tests__/testdata/rest-get-variable.bpmn b/src/__tests__/testdata/rest-get-variable.bpmn new file mode 100644 index 00000000..32a28407 --- /dev/null +++ b/src/__tests__/testdata/rest-get-variable.bpmn @@ -0,0 +1,48 @@ + + + + + Flow_0xxocbj + + + + Flow_0fc59wl + + + + + + + Flow_0xxocbj + Flow_0fc59wl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/c8/lib/C8Dto.ts b/src/c8/lib/C8Dto.ts index b09278c1..39a69b6a 100644 --- a/src/c8/lib/C8Dto.ts +++ b/src/c8/lib/C8Dto.ts @@ -353,3 +353,14 @@ export interface RestJob< */ readonly tenantId: string } + +export class GetVariableResponse { + variableKey!: string + scopeKey!: string + processInstanceKey!: string + name!: string + value!: string + fullValue!: string + tenantId!: string + isTruncated!: boolean +} diff --git a/src/c8/lib/CamundaRestClient.ts b/src/c8/lib/CamundaRestClient.ts index 56d6f4d8..7bc2388a 100644 --- a/src/c8/lib/CamundaRestClient.ts +++ b/src/c8/lib/CamundaRestClient.ts @@ -46,6 +46,7 @@ import { DeployResourceResponse, DeployResourceResponseDto, FormDeployment, + GetVariableResponse, JobUpdateChangeset, MigrationRequest, NewUserInfo, @@ -931,6 +932,15 @@ export class CamundaRestClient { ) } + public async getVariable(req: { + variableKey: string + }): Promise { + const headers = await this.getHeaders() + return this.rest.then((rest) => + rest.get(`variables/${req.variableKey}`, { headers }).json() + ) as Promise + } + private addJobMethods = ( job: RestJob ): RestJob &