Skip to content

Commit

Permalink
feat: adjust link-event error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 29, 2023
1 parent 9e31249 commit 0c7401c
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers
return getElementCollapsedNotAllowedErrorMessage(report);
}

if (type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED) {
return getElementPropertyValueDuplicatedErrorMessage(report);
}

if (type === ERROR_TYPES.ELEMENT_TYPE_NOT_ALLOWED) {
return getElementTypeNotAllowedErrorMessage(report, executionPlatform, executionPlatformVersion);
}
Expand Down Expand Up @@ -498,6 +502,10 @@ function getPropertyRequiredErrorMessage(report, executionPlatform, executionPla
return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined <History time to live>`;
}

if (is(node, 'bpmn:LinkEventDefinition') && requiredProperty === 'name') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined <Name>`;
}

return message;
}

Expand Down Expand Up @@ -631,4 +639,26 @@ function getSecretExpressionInvalidErrorMessage(report) {
const { property } = data;

return `Property <${ property }> is not a valid secret`;
}

function getElementPropertyValueDuplicatedErrorMessage(report) {
const {
data,
message
} = report;

const {
node,
parentNode,
duplicatedProperty,
duplicatedPropertyValue
} = data;

const typeString = getTypeString(parentNode || node);

if (is(node, 'bpmn:LinkEventDefinition') && duplicatedProperty === 'name') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with the same <Name> (${ duplicatedPropertyValue }) as another is not supported`;
}

return message;
}
19 changes: 19 additions & 0 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ export function getEntryIds(report) {
return [ 'propagateAllParentVariables' ];
}

if (isPropertyError(data, 'name', 'bpmn:LinkEventDefinition')
|| isElementPropertyValueDuplicated(data, 'name', 'bpmn:LinkEventDefinition')) {
return [ 'linkName' ];
}

return [];
}

Expand Down Expand Up @@ -458,6 +463,14 @@ export function getErrorMessage(id, report) {
if (id === 'propagateAllParentVariables') {
return 'Not supported.';
}

if (id === 'linkName') {
if (data.type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED) {
return 'Must be unique.';
} else {
return 'Must be defined.';
}
}
}

function isExtensionElementNotAllowedError(data, extensionElement, type) {
Expand Down Expand Up @@ -520,6 +533,12 @@ function isExpressionValueNotAllowedError(data, propertyName, type) {
&& (!type || is(data.node, type));
}

function isElementPropertyValueDuplicated(data, propertyName, type) {
return data.type === ERROR_TYPES.ELEMENT_PROPERTY_VALUE_DUPLICATED
&& data.duplicatedProperty === propertyName
&& (!type || is(data.node, type));
}

function getBusinessObject(element) {
return element.businessObject || element;
}
62 changes: 62 additions & 0 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,47 @@ describe('utils/error-messages', function() {
});


describe('element property value duplicated', function() {

it('should adjust (link name)', async function() {

// given
const node = createElement('bpmn:Process', {
flowElements: [
createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:LinkEventDefinition', {
name: 'foo'
})
]
}),
createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:LinkEventDefinition', {
name: 'foo'
})
]
})
]
});

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

const reports = await getLintErrors(node, rule);

// when
reports.forEach(report => {
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to
.equal('A <Link Intermediate Catch Event> with the same <Name> (foo) as another is not supported');
});
});

});


describe('extension element not allowed', function() {

it('should adjust (business rule task with called decision)', async function() {
Expand Down Expand Up @@ -1299,6 +1340,27 @@ describe('utils/error-messages', function() {
expect(errorMessage).to.equal('A <Script Task> with <Implementation: Job worker> must have a defined <Task definition type>');
});


it('should adjust (link name)', async function() {

// given
const node = createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:LinkEventDefinition')
]
});

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

const report = await getLintError(node, rule);

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('A <Link Intermediate Catch Event> must have a defined <Name>');
});

});


Expand Down
65 changes: 65 additions & 0 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,71 @@ describe('utils/properties-panel', function() {

});


describe('link event - Name', async function() {

it('required', async function() {

// given
const node = createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:LinkEventDefinition')
]
});

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

const report = await getLintError(node, rule);

// when
const entryIds = getEntryIds(report);

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

expectErrorMessage(entryIds[ 0 ], 'Must be defined.', report);
});


it('duplicated', async function() {

// given
const node = createElement('bpmn:Process', {
flowElements: [
createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:LinkEventDefinition', {
name: 'foo'
})
]
}),
createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:LinkEventDefinition', {
name: 'foo'
})
]
})
]
});

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

const reports = await getLintErrors(node, rule);

// when
reports.forEach(report => {
const entryIds = getEntryIds(report);

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

expectErrorMessage(entryIds[ 0 ], 'Must be unique.', report);
});
});

});

});


Expand Down

0 comments on commit 0c7401c

Please sign in to comment.