Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #322 from camunda-community-hub/test-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf authored Jun 19, 2023
2 parents 1d718de + 06b52a3 commit 154f8f7
Show file tree
Hide file tree
Showing 27 changed files with 539 additions and 583 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['node_modules', 'dist'],
collectCoverageFrom: ['!src/__tests__/lib/cancelProcesses.ts']
}
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"jest": "^27.2.3",
"jest-environment-node-debug": "^2.0.0",
"lint-staged": "^11.0.0",
"operate-api-client": "^1.1.3",
"prettier": "^1.19.1",
"remark": "^13.0.0",
"remark-cli": "^9.0.0",
Expand Down
20 changes: 14 additions & 6 deletions src/__tests__/integration/Client-BroadcastSignal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient } from '../..'
// import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
import { CreateProcessInstanceResponse } from '../../lib/interfaces-grpc-1.0'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(60000)


let zbc: ZBClient
const zbc = new ZBClient()
let pid: string
let wf: CreateProcessInstanceResponse | undefined

beforeEach(() => {
zbc = new ZBClient()
beforeAll(async () => {
const res = await zbc.deployResource({
processFilename: `./src/__tests__/testdata/Signal.bpmn`
})
pid = res.deployments[0].process.bpmnProcessId
await cancelProcesses(pid)
})

afterEach(async () => {
Expand All @@ -20,11 +25,14 @@ afterEach(async () => {
}
} catch (e: any) {
// console.log('Caught NOT FOUND') // @DEBUG
} finally {
await zbc.close() // Makes sure we don't forget to close connection
}
})

afterAll(async () => {
await zbc.close()
await cancelProcesses(pid)
})

test('Can start a process with a signal', () => new Promise(async resolve => {
zbc.createWorker({
taskType: 'signal-service-task',
Expand Down
8 changes: 2 additions & 6 deletions src/__tests__/integration/Client-BrokenBpmn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import { ZBClient } from '../..'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'

let zbc: ZBClient
const zbc = new ZBClient()

beforeEach(async () => {
zbc = new ZBClient()
})

afterEach(async () => {
afterAll(async () => {
await zbc.close() // Makes sure we don't forget to close connection
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
import { ZBClient } from '../..'
import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { DeployProcessResponse, ZBClient } from '../..'

process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(25000)

let zbc: ZBClient
const zbc = new ZBClient()
let test1: DeployProcessResponse
let test2: DeployProcessResponse
let test3: DeployProcessResponse

beforeEach(async () => {
zbc = new ZBClient()
beforeAll(async () => {
test1 = await zbc.deployProcess('./src/__tests__/testdata/await-outcome.bpmn')
test2 = await zbc.deployProcess('./src/__tests__/testdata/await-outcome-long.bpmn')
test3 = await zbc.deployProcess('./src/__tests__/testdata/await-outcome.bpmn')
await cancelProcesses(test1.processes[0].bpmnProcessId)
await cancelProcesses(test2.processes[0].bpmnProcessId)
await cancelProcesses(test3.processes[0].bpmnProcessId)
})

afterEach(async () => {
afterAll(async () => {
await zbc.close() // Makes sure we don't forget to close connection
await cancelProcesses(test1.processes[0].bpmnProcessId)
await cancelProcesses(test2.processes[0].bpmnProcessId)
await cancelProcesses(test3.processes[0].bpmnProcessId)
})

test('Awaits a process outcome', async () => {
const { processId, bpmn } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/await-outcome.bpmn',
messages: [],
taskTypes: [],
})
await zbc.deployProcess({
definition: bpmn,
name: `Await-outcome-${processId}.bpmn`,
})
const processId = test1.processes[0].bpmnProcessId
const result = await zbc.createProcessInstanceWithResult(processId, {
sourceValue: 5,
})
expect(result.variables.sourceValue).toBe(5)
})

test('can override the gateway timeout', async () => {
const { bpmn, processId } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/await-outcome-long.bpmn',
messages: [],
taskTypes: [],
})
await zbc.deployProcess({
definition: bpmn,
name: `Await-outcome-long-${processId}.bpmn`,
})
const processId = test2.processes[0].bpmnProcessId
const result = await zbc.createProcessInstanceWithResult({
bpmnProcessId: processId,
requestTimeout: 25000,
Expand All @@ -52,16 +47,7 @@ test('can override the gateway timeout', async () => {
})

test('fetches a subset of variables', async () => {
zbc = new ZBClient()
const { bpmn, processId } = createUniqueTaskType({
bpmnFilePath: './src/__tests__/testdata/await-outcome.bpmn',
messages: [],
taskTypes: [],
})
await zbc.deployProcess({
definition: bpmn,
name: `Await-outcome-${processId}.bpmn`,
})
const processId = test3.processes[0].bpmnProcessId
const result = await zbc.createProcessInstanceWithResult({
bpmnProcessId: processId,
fetchVariables: ['otherValue'],
Expand All @@ -70,7 +56,6 @@ test('fetches a subset of variables', async () => {
sourceValue: 5,
},
})
// @TODO - uncomment when https://github.com/zeebe-io/zeebe/pull/3253 gets merged
expect(result.variables.sourceValue).toBe(undefined)
expect(result.variables.otherValue).toBe('rome')
})
14 changes: 3 additions & 11 deletions src/__tests__/integration/Client-DeployProcess.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import { ZBClient } from '../../index'
import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(20000)

test('deploys a process', async () => {
const zbc = new ZBClient()
const { bpmn, processId } = createUniqueTaskType({
bpmnFilePath: `./src/__tests__/testdata/Client-DeployWorkflow.bpmn`,
messages: [],
taskTypes: [],
})
const result = await zbc.deployProcess({
definition: bpmn,
name: `Client-DeployProcess-${processId}.bpmn`,
})
const result = await zbc.deployProcess(`./src/__tests__/testdata/Client-DeployWorkflow.bpmn`)
await zbc.close()
expect(result.processes[0].bpmnProcessId).toBe(processId)
expect(result.processes[0].bpmnProcessId).toBeTruthy()
})
36 changes: 18 additions & 18 deletions src/__tests__/integration/Client-DeployResource.spec.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { ZBClient } from '../../index'
import { createUniqueTaskType } from '../../lib/createUniqueTaskType'
import { cancelProcesses } from '../../lib/cancelProcesses'
import { ZBClient, BpmnParser } from '../../index'
import fs from 'fs'
process.env.ZEEBE_NODE_LOG_LEVEL = process.env.ZEEBE_NODE_LOG_LEVEL || 'NONE'
jest.setTimeout(20000)

const zbc = new ZBClient()
const bpmnString = fs.readFileSync(`./src/__tests__/testdata/Client-DeployWorkflow.bpmn`, 'utf8')
const expectedPid = BpmnParser.getProcessId(bpmnString)

beforeAll(async () =>
await cancelProcesses(expectedPid)
)

afterAll(async () =>
await zbc.close()
)

test('deploys a process', async () => {
const zbc = new ZBClient()
const { bpmn, processId } = createUniqueTaskType({
bpmnFilePath: `./src/__tests__/testdata/Client-DeployWorkflow.bpmn`,
messages: [],
taskTypes: [],
})
const result = await zbc.deployResource({
process: bpmn,
name: `Client-DeployProcess-${processId}.bpmn`,
process: Buffer.from(bpmnString),
name: `Client-DeployWorkflow.bpmn`,
})
await zbc.close()
expect(result.deployments[0].process.bpmnProcessId).toBe(processId)
expect(result.deployments[0].process.bpmnProcessId).toBe(expectedPid)
})
test('deploys a process from a file', async () => {
const zbc = new ZBClient()
const result = await zbc.deployResource({
processFilename: `./src/__tests__/testdata/Client-DeployWorkflow.bpmn`,
})
await zbc.close()
expect(result.deployments[0].process.version).toBeGreaterThanOrEqual(1)
})
test('deploys a DMN table from a filename', async () => {
const zbc = new ZBClient()
const result = await zbc.deployResource({
decisionFilename: './src/__tests__/testdata/quarantine-duration.dmn',
})
await zbc.close()
expect(result.deployments[0].decision.decisionKey).not.toBeNull()
})
test('deploys a DMN table', async () => {
const zbc = new ZBClient()
const decision = fs.readFileSync(
'./src/__tests__/testdata/quarantine-duration.dmn'
)
const result = await zbc.deployResource({
decision,
name: 'quarantine-duration.dmn',
})
await zbc.close()
expect(result.deployments[0].decision.decisionKey).not.toBeNull()
})
Loading

0 comments on commit 154f8f7

Please sign in to comment.