From feed0298c4f94468edbe92e0c1345d76341e6529 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Fri, 13 Dec 2024 17:12:26 +0100 Subject: [PATCH] fix: accept empty script expression without error Related to https://github.com/camunda/camunda-modeler/issues/4759 --- lib/zeebe/util/feelUtility.js | 4 +- .../script-task-empty-expression.bpmn | 17 +++++ test/fixtures/zeebe/mappings/script-task.bpmn | 4 +- test/spec/zeebe/Mappings.spec.js | 62 +++++++++++++------ 4 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn diff --git a/lib/zeebe/util/feelUtility.js b/lib/zeebe/util/feelUtility.js index f140dc2..57c89b5 100644 --- a/lib/zeebe/util/feelUtility.js +++ b/lib/zeebe/util/feelUtility.js @@ -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; } diff --git a/test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn b/test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn new file mode 100644 index 0000000..64cd8c4 --- /dev/null +++ b/test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/zeebe/mappings/script-task.bpmn b/test/fixtures/zeebe/mappings/script-task.bpmn index a5cc86a..9fc5421 100644 --- a/test/fixtures/zeebe/mappings/script-task.bpmn +++ b/test/fixtures/zeebe/mappings/script-task.bpmn @@ -1,7 +1,7 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/test/spec/zeebe/Mappings.spec.js b/test/spec/zeebe/Mappings.spec.js index 475f89e..9d88f81 100644 --- a/test/spec/zeebe/Mappings.spec.js +++ b/test/spec/zeebe/Mappings.spec.js @@ -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'; @@ -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' + } + ]); + })); + }); }); });