Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 338 #365

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# CAMUNDA_CONNECTORS_VERSION=0.23.2
CAMUNDA_CONNECTORS_VERSION=8.5.0
CAMUNDA_OPTIMIZE_VERSION=8.5.0
CAMUNDA_PLATFORM_VERSION=8.6.0
CAMUNDA_ZEEBE_VERSION=8.6.3
CAMUNDA_PLATFORM_VERSION=8.7.0-alpha3
CAMUNDA_ZEEBE_VERSION=8.7.0-alpha3
CAMUNDA_WEB_MODELER_VERSION=8.5.0
ELASTIC_VERSION=8.9.0
KEYCLOAK_SERVER_VERSION=22.0.3
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose-multitenancy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ services:
- SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI=http://keycloak:8080/auth/realms/camunda-platform/protocol/openid-connect/certs
- CAMUNDA_TASKLIST_IDENTITY_RESOURCE_PERMISSIONS_ENABLED=${RESOURCE_AUTHORIZATIONS_ENABLED}
- CAMUNDA_TASKLIST_MULTITENANCY_ENABLED=true
- CAMUNDA_TASKLIST_ZEEBE_COMPATIBILITY_ENABLED=true # 8.7.0-alpha3 change
- CAMUNDA_DATABASE_URL=http://elasticsearch:9200 # 8.7.0-alpha3 change
- management.endpoints.web.exposure.include=health
- management.endpoint.health.probes.enabled=true
healthcheck:
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ services:
- SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI=http://keycloak:8080/auth/realms/camunda-platform
- SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI=http://keycloak:8080/auth/realms/camunda-platform/protocol/openid-connect/certs
- CAMUNDA_TASKLIST_IDENTITY_RESOURCE_PERMISSIONS_ENABLED=${RESOURCE_AUTHORIZATIONS_ENABLED}
- CAMUNDA_TASKLIST_ZEEBE_COMPATIBILITY_ENABLED=true # 8.7.0-alpha3 change
- CAMUNDA_DATABASE_URL=http://elasticsearch:9200 # 8.7.0-alpha3 change
- management.endpoints.web.exposure.include=health
- management.endpoint.health.probes.enabled=true
healthcheck:
Expand Down
44 changes: 44 additions & 0 deletions src/__tests__/c8/rest/getUserTask.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { randomUUID } from 'crypto'

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

const c8 = new CamundaRestClient()

jest.setTimeout(30000)
test('It can retrieve a user task', async () => {
const res = await c8.deployResourcesFromFiles([
'./src/__tests__/testdata/test-tasks-query.bpmn',
'./src/__tests__/testdata/form/test-basic-form.form',
])
const key = res.processes[0].processDefinitionKey
const id = res.processes[0].processDefinitionId
const uuid = randomUUID()
const wfi = await c8.createProcessInstance({
processDefinitionId: id,
variables: {
queryTag: uuid,
},
})
expect(wfi.processDefinitionKey).toBe(key)
await new Promise((r) => setTimeout(r, 5000))
// Search user tasks
const tasks = await c8.findUserTasks({
page: {
from: 0,
limit: 10,
searchAfter: [],
searchBefore: [],
},
filter: {
state: 'CREATED',
},
sort: [
{
field: 'creationDate',
},
],
})
expect(tasks.items[0].processInstanceKey).toBe(wfi.processInstanceKey)
const task = await c8.getUserTask(tasks.items[0].userTaskKey)
expect(task.processInstanceKey).toBe(wfi.processInstanceKey)
})
49 changes: 49 additions & 0 deletions src/__tests__/c8/rest/getUserTaskVariables.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { randomUUID } from 'crypto'

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

const c8 = new CamundaRestClient()

jest.setTimeout(30000)
test('It can retrieve the variables for a user task', async () => {
const res = await c8.deployResourcesFromFiles([
'./src/__tests__/testdata/test-tasks-query.bpmn',
'./src/__tests__/testdata/form/test-basic-form.form',
])
const key = res.processes[0].processDefinitionKey
const id = res.processes[0].processDefinitionId
const uuid = randomUUID()
const wfi = await c8.createProcessInstance({
processDefinitionId: id,
variables: {
queryTag: uuid,
},
})
expect(wfi.processDefinitionKey).toBe(key)
await new Promise((r) => setTimeout(r, 5000))
// Search user tasks
const tasks = await c8.findUserTasks({
page: {
from: 0,
limit: 10,
searchAfter: [],
searchBefore: [],
},
filter: {
state: 'CREATED',
},
sort: [
{
field: 'creationDate',
},
],
})
expect(tasks.items[0].processInstanceKey).toBe(wfi.processInstanceKey)
const task = await c8.getUserTask(tasks.items[0].userTaskKey)
expect(task.processInstanceKey).toBe(wfi.processInstanceKey)
const variables = await c8.getUserTaskVariables({
userTaskKey: tasks.items[0].userTaskKey,
sort: [{ field: 'name', order: 'ASC' }],
})
expect(variables.items[0].value).toBe(`"${uuid}"`)
})
43 changes: 43 additions & 0 deletions src/__tests__/c8/rest/queryUserTasks.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { randomUUID } from 'crypto'

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

const c8 = new CamundaRestClient()

jest.setTimeout(30000)
test('It can query user tasks', async () => {
const res = await c8.deployResourcesFromFiles([
'./src/__tests__/testdata/test-tasks-query.bpmn',
'./src/__tests__/testdata/form/test-basic-form.form',
])
const key = res.processes[0].processDefinitionKey
const id = res.processes[0].processDefinitionId
const uuid = randomUUID()
const wfi = await c8.createProcessInstance({
processDefinitionId: id,
variables: {
queryTag: uuid,
},
})
expect(wfi.processDefinitionKey).toBe(key)
await new Promise((r) => setTimeout(r, 5000))
// Do we need to wait for the process instance to be started and arrive at the user task?
// Search user tasks
const tasks = await c8.findUserTasks({
page: {
from: 0,
limit: 10,
searchAfter: [],
searchBefore: [],
},
filter: {
state: 'CREATED',
},
sort: [
{
field: 'creationDate',
},
],
})
expect(tasks.items[0].processInstanceKey).toBe(wfi.processInstanceKey)
})
61 changes: 61 additions & 0 deletions src/__tests__/c8/rest/queryVariables.rest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import path from 'node:path'

import { CamundaJobWorker } from 'c8/lib/CamundaJobWorker'
import { LosslessDto } from 'lib'

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

jest.setTimeout(10000)
let processDefinitionId: string
const restClient = new CamundaRestClient()
let w: CamundaJobWorker<LosslessDto, LosslessDto>

beforeAll(async () => {
const res = await restClient.deployResourcesFromFiles([
path.join('.', 'src', '__tests__', 'testdata', 'rest-query-variables.bpmn'),
])
processDefinitionId = res.processes[0].processDefinitionId
})

afterEach(async () => {
if (w) {
await w.stop()
}
})

test('Can query variables', (done) => {
restClient.createProcessInstance({
processDefinitionId,
variables: {
someNumberField: 8,
},
})
w = restClient.createJobWorker({
type: 'query-variables',
jobHandler: async (job) => {
await new Promise((res) => setTimeout(() => res(null), 5000))
const variables = await restClient.queryVariables({
filter: {
processInstanceKey: job.processInstanceKey,
},
})
expect(variables.items.length).toBe(1)
const res = await job.complete()
done()
return res
},
worker: 'query-variables-worker',
timeout: 10000,
maxJobsToActivate: 10,
})
// .then(() => {
// restClient
// .getVariable({
// variableKey: 'someNumberField',
// })
// .then((variable) => {
// expect(variable).toBe(8)
// done()
// })
// })
})
29 changes: 29 additions & 0 deletions src/__tests__/c8/rest/searchProcessInstances.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { randomUUID } from 'crypto'

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

const c8 = new CamundaRestClient()

jest.setTimeout(30000)
test('It can retrieve a user task', async () => {
const res = await c8.deployResourcesFromFiles([
'./src/__tests__/testdata/test-tasks-query.bpmn',
'./src/__tests__/testdata/form/test-basic-form.form',
])
const key = res.processes[0].processDefinitionKey
const id = res.processes[0].processDefinitionId
const uuid = randomUUID()
const wfi = await c8.createProcessInstance({
processDefinitionId: id,
variables: {
queryTag: uuid,
},
})
expect(wfi.processDefinitionKey).toBe(key)
await new Promise((r) => setTimeout(r, 5000))
const instances = await c8.searchProcessInstances({
sort: [{ field: 'state', order: 'ASC' }],
filter: { state: 'ACTIVE' },
})
expect(instances.items[0].processInstanceKey).toBe(wfi.processInstanceKey)
})
37 changes: 37 additions & 0 deletions src/__tests__/c8/rest/searchUsers.rest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// import { randomUUID } from 'crypto'

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

const c8 = new CamundaRestClient()

jest.setTimeout(10000)
test('It can search users', async () => {
// const uuid = randomUUID()
await c8
.createUser({
email: `[email protected]`,
name: 'John Doe',
username: 'jdoe',
password: 'password123',
})
.catch((e) => e) // throws 409 if user already exists
await new Promise((r) => setTimeout(r, 5000))

const users = await c8.searchUsers({
page: {
from: 0,
limit: 10,
searchAfter: [],
searchBefore: [],
},
filter: {
username: 'jdoe',
},
sort: [
{
field: 'name',
},
],
})
expect(users.items[0].email).toBe('[email protected]')
})
2 changes: 2 additions & 0 deletions src/__tests__/config/jest.cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const cleanUp = async () => {
const files = fs
.readdirSync(filePath)
.map((file) => path.join(filePath, file))
.filter((file) => fs.statSync(file).isFile())

const bpmn = BpmnParser.parseBpmn(files)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const processIds = (bpmn as any[]).map(
Expand Down
15 changes: 11 additions & 4 deletions src/__tests__/lib/LosslessJsonParser.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ test('LosslessJsonParser is ok with missing optional fields at runtime', () => {
expect((parsedDto as any).age).toBe(42)
})

test('LosslessJsonParser will throw if an unexpected type is encountered at runtime', () => {
/**
* In versions prior to 8.7, entity keys were transmitted as JSON number values.
* In 8.7, they are transmitted as JSON strings.
* This test ensures that the parser can handle both cases.
*/
test('LosslessJsonParser will not throw if a string type is encountered in an int64String annotated field at runtime', () => {
class InputVariables extends LosslessDto {
name!: string
@Int64String
Expand All @@ -195,13 +200,15 @@ test('LosslessJsonParser will throw if an unexpected type is encountered at runt
"optionalKey": "optional"
}`
let threw = false
let parsed: InputVariables
try {
losslessParse(json, InputVariables)
parsed = losslessParse(json, InputVariables)
expect(parsed.key).toBe('12345678901234567890')
expect(parsed.optionalKey).toBe('optional')
} catch (e) {
expect((e as Error).message.includes('Unexpected type')).toBe(true)
threw = true
}
expect(threw).toBe(true)
expect(threw).toBe(false)
})

test('LosslessJsonParser throws for unexpected unsafe numbers at runtime', () => {
Expand Down
Loading