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 02435fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 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
4 changes: 2 additions & 2 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,10 @@ describe('utils/error-messages', function() {
const report = await getLintError(node, rule, { version: executionPlatformVersion });

// when
const errorMessage = getErrorMessage(report);
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 requires Camunda Platform 8.1 or newer)');
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)');
});


Expand Down
2 changes: 1 addition & 1 deletion test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ describe('utils/properties-panel', function() {
// then
expect(entryIds).to.eql([ 'timerEventDefinitionValue' ]);

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);
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);
});


Expand Down

0 comments on commit 02435fa

Please sign in to comment.