Skip to content

Commit

Permalink
fix: accept empty script expression without error
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Dec 13, 2024
1 parent e6f589f commit feed029
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/zeebe/util/feelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ function getIoExpression(variable, origin) {
*
* @param {ProcessVariable} variable
* @param {djs.model.Base} origin
* @returns { expression: String}
* @returns {string}
*/
function getScriptExpression(variable, origin) {
const script = getExtensionElementsList(origin, 'zeebe:Script')[0];

if (!script) {
if (!script || !script.expression) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0qieuld" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:scriptTask id="ScriptTask" name="Script Task">
<bpmn:extensionElements>
<zeebe:script resultVariable="scriptResult" />
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_1g8b868_di" bpmnElement="ScriptTask">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
4 changes: 2 additions & 2 deletions test/fixtures/zeebe/mappings/script-task.bpmn
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0qieuld" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:scriptTask id="Activity_0kxqawv" name="Script Task">
<bpmn:scriptTask id="ScriptTask" name="Script Task">
<bpmn:extensionElements>
<zeebe:script expression="={&#10; foo: 123&#10;}" resultVariable="scriptResult" />
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_1g8b868_di" bpmnElement="Activity_0kxqawv">
<bpmndi:BPMNShape id="Activity_1g8b868_di" bpmnElement="ScriptTask">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
Expand Down
62 changes: 44 additions & 18 deletions test/spec/zeebe/Mappings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import primitivesXML from 'test/fixtures/zeebe/mappings/primitives.bpmn';
import mergingXML from 'test/fixtures/zeebe/mappings/merging.bpmn';
import scopeXML from 'test/fixtures/zeebe/mappings/scope.bpmn';
import scriptTaskXML from 'test/fixtures/zeebe/mappings/script-task.bpmn';
import scriptTaskEmptyExpressionXML from 'test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn';

import VariableProvider from 'lib/VariableProvider';

Expand Down Expand Up @@ -320,30 +321,55 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {

describe('Script Task', function() {

beforeEach(bootstrap(scriptTaskXML));
describe('valid', function() {

beforeEach(bootstrap(scriptTaskXML));

it('should add type annotation for script tasks', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Process_1');
it('should add type annotation for script tasks', inject(async function(variableResolver, elementRegistry) {

// when
const variables = await variableResolver.getVariablesForElement(root.businessObject);
// given
const element = elementRegistry.get('ScriptTask');

// then
expect(variables).to.variableEqual([
{
name: 'scriptResult',
type: 'Context',
info: '',
entries: [
{ name: 'foo', type: 'Number', info: '123', entries: [] },
]
}
]);
}));
// when
const variables = await variableResolver.getVariablesForElement(element.businessObject);

// then
expect(variables).to.variableEqual([
{
name: 'scriptResult',
type: 'Context',
info: '',
entries: [
{ name: 'foo', type: 'Number', info: '123', entries: [] },
]
}
]);
}));
});


describe('empty expression', function() {

beforeEach(bootstrap(scriptTaskEmptyExpressionXML));


it('should NOT error for empty expression', inject(async function(variableResolver, elementRegistry) {

// given
const element = elementRegistry.get('ScriptTask');

// when
const variables = await variableResolver.getVariablesForElement(element.businessObject);

// then
expect(variables).to.variableEqual([
{
name: 'scriptResult'
}
]);
}));
});
});

});
Expand Down

0 comments on commit feed029

Please sign in to comment.