Skip to content

Commit

Permalink
test(camunda8): fix tests for migrateProcess over Rest
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Sep 18, 2024
1 parent bb7bcf2 commit f2d78ed
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 63 deletions.
42 changes: 21 additions & 21 deletions src/__tests__/c8/rest/restMigrateProcess.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'path'

import { C8JobWorker } from 'c8/lib/C8JobWorker'

import { C8RestClient } from '../../../c8/lib/C8RestClient'

import { LosslessDto } from './../../../lib'
Expand All @@ -18,22 +20,22 @@ test('RestClient can migrate a process instance', async () => {
'src',
'__tests__',
'testdata',
'MigrateProcess-Version-1.bpmn'
'MigrateProcess-Rest-Version-1.bpmn'
),
])

// Create an instance of the process model
const processInstance = await c8.createProcessInstance({
bpmnProcessId: 'migrant-work',
bpmnProcessId: 'migrant-work-rest',
variables: {},
})

let instanceKey = ''
let processVersion = 0

await new Promise((res) => {
await new Promise<C8JobWorker<LosslessDto, CustomHeaders>>((res) => {
const w = c8.createJobWorker({
type: 'migrant-worker-task-1',
type: 'migrant-rest-worker-task-1',
maxJobsToActivate: 10,
timeout: 30000,
pollIntervalMs: 1000,
Expand All @@ -42,21 +44,20 @@ test('RestClient can migrate a process instance', async () => {
jobHandler: async (job) => {
instanceKey = job.processInstanceKey
processVersion = job.customHeaders.ProcessVersion as number
return job.complete().then((outcome) => {
w.stop()
res(null)
return job.complete().then(async (outcome) => {
res(w)
return outcome
})
},
})
})
}).then((w) => w.stop())

expect(instanceKey).toBe(processInstance.processInstanceKey)
expect(processVersion).toBe('1')

// Deploy the updated process model
const res1 = await c8.deployResourcesFromFiles([
'./src/__tests__/testdata/MigrateProcess-Version-2.bpmn',
'./src/__tests__/testdata/MigrateProcess-Rest-Version-2.bpmn',
])

// Migrate the process instance to the updated process model
Expand All @@ -74,26 +75,25 @@ test('RestClient can migrate a process instance', async () => {

// Complete the job in the process instance

await new Promise((res) => {
await new Promise<C8JobWorker<LosslessDto, LosslessDto>>((res) => {
const w = c8.createJobWorker({
type: 'migration-checkpoint',
type: 'migration-rest-checkpoint',
worker: 'Migrant Checkpoint worker',
maxJobsToActivate: 10,
timeout: 10000,
pollIntervalMs: 1000,
jobHandler: async (job) => {
return job.complete().then((outcome) => {
w.stop()
res(null)
return job.complete().then(async (outcome) => {
res(w)
return outcome
})
},
})
})
}).then((w) => w.stop())

await new Promise((res) => {
await new Promise<C8JobWorker<LosslessDto, CustomHeaders>>((res) => {
const w = c8.createJobWorker({
type: 'migrant-worker-task-2',
type: 'migrant-rest-worker-task-2',
worker: 'Migrant Worker 2',
maxJobsToActivate: 10,
timeout: 30000,
Expand All @@ -102,14 +102,14 @@ test('RestClient can migrate a process instance', async () => {
jobHandler: async (job) => {
instanceKey = job.processInstanceKey
processVersion = job.customHeaders.ProcessVersion as number
return job.complete().then((outcome) => {
w.stop()
res(null)
return job.complete().then(async (outcome) => {
res(w)
return outcome
})
},
})
})
}).then((w) => w.stop())

expect(instanceKey).toBe(processInstance.processInstanceKey)
expect(processVersion).toBe('2')
})
91 changes: 91 additions & 0 deletions src/__tests__/testdata/MigrateProcess-Rest-Version-1.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1cfwunf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.27.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="migrant-work-rest" name="migrant-work" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start MigrationTest Process">
<bpmn:outgoing>Flow_167nn02</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_167nn02" sourceRef="StartEvent_1" targetRef="Activity_1fbznct" />
<bpmn:endEvent id="Event_0zwmdqk" name="End">
<bpmn:incoming>Flow_1r250pk</bpmn:incoming>
</bpmn:endEvent>
<bpmn:serviceTask id="Activity_1fbznct" name="Migrant Worker Task 1">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-rest-worker-task-1" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="1" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_167nn02</bpmn:incoming>
<bpmn:outgoing>Flow_04fsyv6</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1r250pk" sourceRef="Activity_0wjb7yn" targetRef="Event_0zwmdqk" />
<bpmn:sequenceFlow id="Flow_04fsyv6" sourceRef="Activity_1fbznct" targetRef="Activity_050vmrm" />
<bpmn:serviceTask id="Activity_0wjb7yn" name="Migrant Worker Task 2">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-rest-worker-task-2" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="1" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1igeic8</bpmn:incoming>
<bpmn:outgoing>Flow_1r250pk</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1igeic8" sourceRef="Activity_050vmrm" targetRef="Activity_0wjb7yn" />
<bpmn:serviceTask id="Activity_050vmrm" name="Migration Checkpoint">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migration-rest-checkpoint" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_04fsyv6</bpmn:incoming>
<bpmn:outgoing>Flow_1igeic8</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:message id="Message_2h617dg" name="MigrationFinished">
<bpmn:extensionElements>
<zeebe:subscription correlationKey="=messageCorrelationKey" />
</bpmn:extensionElements>
</bpmn:message>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="migrant-work-rest">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="164" y="142" width="66" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0zwmdqk_di" bpmnElement="Event_0zwmdqk">
<dc:Bounds x="822" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="830" y="142" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1rj9fgz_di" bpmnElement="Activity_1fbznct">
<dc:Bounds x="330" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0uo9rxu_di" bpmnElement="Activity_0wjb7yn">
<dc:Bounds x="600" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1io10nl_di" bpmnElement="Activity_050vmrm">
<dc:Bounds x="460" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_167nn02_di" bpmnElement="Flow_167nn02">
<di:waypoint x="215" y="117" />
<di:waypoint x="330" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r250pk_di" bpmnElement="Flow_1r250pk">
<di:waypoint x="700" y="117" />
<di:waypoint x="822" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_04fsyv6_di" bpmnElement="Flow_04fsyv6">
<di:waypoint x="430" y="117" />
<di:waypoint x="460" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1igeic8_di" bpmnElement="Flow_1igeic8">
<di:waypoint x="560" y="117" />
<di:waypoint x="600" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
91 changes: 91 additions & 0 deletions src/__tests__/testdata/MigrateProcess-Rest-Version-2.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1cfwunf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.27.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="migrant-work-rest" name="migrant-work" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start MigrationTest Process">
<bpmn:outgoing>Flow_167nn02</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_167nn02" sourceRef="StartEvent_1" targetRef="Activity_1fbznct" />
<bpmn:endEvent id="Event_0zwmdqk" name="End">
<bpmn:incoming>Flow_1r250pk</bpmn:incoming>
</bpmn:endEvent>
<bpmn:serviceTask id="Activity_1fbznct" name="Migrant Worker Task 1">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-rest-worker-task-1" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="2" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_167nn02</bpmn:incoming>
<bpmn:outgoing>Flow_04fsyv6</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1r250pk" sourceRef="Activity_0wjb7yn" targetRef="Event_0zwmdqk" />
<bpmn:sequenceFlow id="Flow_04fsyv6" sourceRef="Activity_1fbznct" targetRef="Activity_050vmrm" />
<bpmn:serviceTask id="Activity_0wjb7yn" name="Migrant Worker Task 2">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-rest-worker-task-2" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="2" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1igeic8</bpmn:incoming>
<bpmn:outgoing>Flow_1r250pk</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1igeic8" sourceRef="Activity_050vmrm" targetRef="Activity_0wjb7yn" />
<bpmn:serviceTask id="Activity_050vmrm" name="Migration Checkpoint">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migration-rest-checkpoint" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_04fsyv6</bpmn:incoming>
<bpmn:outgoing>Flow_1igeic8</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:message id="Message_2h617dg" name="MigrationFinished">
<bpmn:extensionElements>
<zeebe:subscription correlationKey="=messageCorrelationKey" />
</bpmn:extensionElements>
</bpmn:message>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="migrant-work-rest">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="164" y="142" width="66" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0zwmdqk_di" bpmnElement="Event_0zwmdqk">
<dc:Bounds x="822" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="830" y="142" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1rj9fgz_di" bpmnElement="Activity_1fbznct">
<dc:Bounds x="330" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0uo9rxu_di" bpmnElement="Activity_0wjb7yn">
<dc:Bounds x="600" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1io10nl_di" bpmnElement="Activity_050vmrm">
<dc:Bounds x="460" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_167nn02_di" bpmnElement="Flow_167nn02">
<di:waypoint x="215" y="117" />
<di:waypoint x="330" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r250pk_di" bpmnElement="Flow_1r250pk">
<di:waypoint x="700" y="117" />
<di:waypoint x="822" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_04fsyv6_di" bpmnElement="Flow_04fsyv6">
<di:waypoint x="430" y="117" />
<di:waypoint x="460" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1igeic8_di" bpmnElement="Flow_1igeic8">
<di:waypoint x="560" y="117" />
<di:waypoint x="600" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('deploys a Form', async () => {
})
expect(result.deployments[0].form).not.toBeNull()
})
test.only('deploys multiple resources', async () => {
test('deploys multiple resources', async () => {
const result = await zbc.deployResources([
{
processFilename: './src/__tests__/testdata/Client-DeployWorkflow.bpmn',
Expand Down
24 changes: 24 additions & 0 deletions src/c8/lib/C8Dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LosslessNumber } from 'lossless-json'

import { Int64String, LosslessDto } from '../../lib'
import { JSONDoc } from '../../zeebe/types'

export class RestApiJob<
Variables = LosslessDto,
Expand Down Expand Up @@ -168,3 +169,26 @@ export class BroadcastSignalResponse extends LosslessDto {
/** The tenant ID of the signal that was broadcast. */
tenantId!: string
}

export interface UpdateElementVariableRequest {
/**
* The key of the element instance to update the variables for.
* This can be the process instance key (as obtained during instance creation), or a given element,
* such as a service task (see the elementInstanceKey on the job message). */
elementInstanceKey: string
variables: JSONDoc | LosslessDto
/**
* Defaults to false.
* If set to true, the variables are merged strictly into the local scope (as specified by the elementInstanceKey). Otherwise, the variables are propagated to upper scopes and set at the outermost one.
* Let’s consider the following example:
* There are two scopes '1' and '2'. Scope '1' is the parent scope of '2'. The effective variables of the scopes are: 1 => { "foo" : 2 } 2 => { "bar" : 1 }
* An update request with elementInstanceKey as '2', variables { "foo" : 5 }, and local set to true leaves scope '1' unchanged and adjusts scope '2' to { "bar" : 1, "foo" 5 }.
* By default, with local set to false, scope '1' will be { "foo": 5 } and scope '2' will be { "bar" : 1 }.
*/
local?: boolean
/**
* A reference key chosen by the user that will be part of all records resulting from this operation.
* Must be > 0 if provided.
*/
operationReference?: number
}
Loading

0 comments on commit f2d78ed

Please sign in to comment.