Skip to content

Commit

Permalink
fix: time cycle expression error message
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Jul 24, 2023
1 parent 55a62ec commit f3f7f9d
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 42 deletions.
15 changes: 11 additions & 4 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {

import { getTypeString } from './types';

import { toSemverMinor } from './version';
import {
greaterOrEqual,
toSemverMinor
} from './version';

const TIMER_PROPERTIES = [
'timeCycle',
Expand Down Expand Up @@ -122,7 +125,7 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers
}

if (type === ERROR_TYPES.EXPRESSION_VALUE_NOT_ALLOWED) {
return getExpressionValueNotAllowedErrorMessage(report);
return getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
}

if (type === ERROR_TYPES.EXPRESSION_NOT_ALLOWED) {
Expand Down Expand Up @@ -507,7 +510,7 @@ function getExpressionRequiredErrorMessage(report) {
return message;
}

function getExpressionValueNotAllowedErrorMessage(report) {
function getExpressionValueNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion) {
const {
data,
message
Expand All @@ -522,7 +525,11 @@ function getExpressionValueNotAllowedErrorMessage(report) {
const typeString = getTypeString(parentNode || node);

if (is(node, 'bpmn:FormalExpression') && property === 'timeCycle') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer)`;
if (!greaterOrEqual(executionPlatformVersion, '8.1')) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron only supported by Camunda Platform 8.1 or newer)`;
} else {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression`;
}
}

if (is(node, 'bpmn:FormalExpression') && property === 'timeDate') {
Expand Down
13 changes: 11 additions & 2 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { is } from 'bpmnlint-utils';

import { ERROR_TYPES } from 'bpmnlint-plugin-camunda-compat/rules/utils/error-types';

import { greaterOrEqual } from './version';

const TIMER_PROPERTIES = [
'timeDate',
'timeDuration',
Expand Down Expand Up @@ -268,7 +270,10 @@ export function getEntryIds(report) {
}

export function getErrorMessage(id, report) {
const { data = {} } = report;
const {
data = {},
executionPlatformVersion
} = report;

// do not override FEEL message
if (data.type === ERROR_TYPES.FEEL_EXPRESSION_INVALID) {
Expand Down Expand Up @@ -397,7 +402,11 @@ export function getErrorMessage(id, report) {
const { property } = data;

if (property === 'timeCycle') {
return 'Must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer).';
if (!greaterOrEqual(executionPlatformVersion, '8.1')) {
return 'Must be an expression, an ISO 8601 repeating interval, or a cron expression (cron only supported by Camunda Platform 8.1 or newer).';
}

return 'Must be an expression, an ISO 8601 repeating interval, or a cron expression.';
}

if (property === 'timeDate') {
Expand Down
65 changes: 48 additions & 17 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1279,30 +1279,61 @@ describe('utils/error-messages', function() {

describe('expression value not allowed', function() {

it('should adjust (time cycle)', async function() {
describe('should adjust (time cycle)', async function() {

// given
const executionPlatformVersion = '1.0';
it('< Camunda 8.1', async function() {

const node = createElement('bpmn:BoundaryEvent', {
attachedToRef: createElement('bpmn:Task'),
cancelActivity: false,
eventDefinitions: [
createElement('bpmn:TimerEventDefinition', {
timeCycle: createElement('bpmn:FormalExpression', { body: 'invalid' })
})
]
// given
const executionPlatformVersion = '1.0';

const node = createElement('bpmn:BoundaryEvent', {
attachedToRef: createElement('bpmn:Task'),
cancelActivity: false,
eventDefinitions: [
createElement('bpmn:TimerEventDefinition', {
timeCycle: createElement('bpmn:FormalExpression', { body: 'invalid' })
})
]
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer');

const report = await getLintError(node, rule, { version: executionPlatformVersion });

// when
const errorMessage = getErrorMessage(report, 'Camunda Cloud', executionPlatformVersion);

// then
expect(errorMessage).to.equal('A <Timer Boundary Event> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron only supported by Camunda Platform 8.1 or newer)');
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer');

const report = await getLintError(node, rule, { version: executionPlatformVersion });
it('=> Camunda 8.1', async function() {

// when
const errorMessage = getErrorMessage(report);
// given
const executionPlatformVersion = '8.1';

const node = createElement('bpmn:BoundaryEvent', {
attachedToRef: createElement('bpmn:Task'),
cancelActivity: false,
eventDefinitions: [
createElement('bpmn:TimerEventDefinition', {
timeCycle: createElement('bpmn:FormalExpression', { body: 'invalid' })
})
]
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer');

const report = await getLintError(node, rule, { version: executionPlatformVersion });

// when
const errorMessage = getErrorMessage(report, 'Camunda Cloud', executionPlatformVersion);

// then
expect(errorMessage).to.equal('A <Timer Boundary Event> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression');
});

// then
expect(errorMessage).to.equal('A <Timer Boundary Event> <Time cycle> must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer)');
});


Expand Down
71 changes: 52 additions & 19 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,32 +1071,65 @@ describe('utils/properties-panel', function() {
});


it('invalid time cycle value', async function() {

// given
const node = createElement('bpmn:BoundaryEvent', {
attachedToRef: createElement('bpmn:Task'),
cancelActivity: false,
eventDefinitions: [
createElement('bpmn:TimerEventDefinition', {
timeCycle: createElement('bpmn:FormalExpression', {
body: '0 0 9-17 * * MON-FRI'
describe('invalid time cycle value', async function() {

it('< Camunda 8.1', async function() {

// given
const node = createElement('bpmn:BoundaryEvent', {
attachedToRef: createElement('bpmn:Task'),
cancelActivity: false,
eventDefinitions: [
createElement('bpmn:TimerEventDefinition', {
timeCycle: createElement('bpmn:FormalExpression', {
body: 'invalid'
})
})
})
]
]
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer');

const report = await getLintError(node, rule, { version: '1.0' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'timerEventDefinitionValue' ]);

expectErrorMessage(entryIds[ 0 ], 'Must be an expression, an ISO 8601 repeating interval, or a cron expression (cron only supported by Camunda Platform 8.1 or newer).', report);
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer');

const report = await getLintError(node, rule, { version: '1.0' });
it('=> Camunda 8.1', async function() {

// when
const entryIds = getEntryIds(report);
// given
const node = createElement('bpmn:BoundaryEvent', {
attachedToRef: createElement('bpmn:Task'),
cancelActivity: false,
eventDefinitions: [
createElement('bpmn:TimerEventDefinition', {
timeCycle: createElement('bpmn:FormalExpression', {
body: 'invalid'
})
})
]
});

// then
expect(entryIds).to.eql([ 'timerEventDefinitionValue' ]);
const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/timer');

const report = await getLintError(node, rule, { version: '8.1' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'timerEventDefinitionValue' ]);

expectErrorMessage(entryIds[ 0 ], 'Must be an expression, an ISO 8601 repeating interval, or a cron expression.', report);
});

expectErrorMessage(entryIds[ 0 ], 'Must be an expression, an ISO 8601 repeating interval, or a cron expression (cron requires Camunda Platform 8.1 or newer).', report);
});


Expand Down

0 comments on commit f3f7f9d

Please sign in to comment.