@@ -790,9 +790,7 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
790790 const withUsedBy = variables . filter ( v => v . usedBy && v . usedBy . length > 0 ) ;
791791 const names = withUsedBy . map ( v => v . name ) ;
792792
793- // then - input requirements should come from input mapping expressions only;
794- // localA and localB are provided by the input mappings, so the script's
795- // references to them should NOT produce input requirements
793+ // then
796794 expect ( names ) . to . include ( 'processVar1' ) ;
797795 expect ( names ) . to . include ( 'processVar2' ) ;
798796 expect ( names ) . to . not . include ( 'localA' ) ;
@@ -807,11 +805,56 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
807805 const withUsedBy = variables . filter ( v => v . usedBy && v . usedBy . length > 0 ) ;
808806 const names = withUsedBy . map ( v => v . name ) ;
809807
810- // then - the second script task has no input mappings, so its script variables should be extracted
808+ // then
811809 expect ( names ) . to . include ( 'x' ) ;
812810 expect ( names ) . to . include ( 'y' ) ;
813811 } ) ) ;
814812
813+
814+ it ( 'should not require locally provided variable when chained input mapping references earlier target' , inject ( async function ( variableResolver ) {
815+
816+ // when
817+ const variables = ( await variableResolver . getVariables ( ) ) [ 'Process_1' ] ;
818+ const chainedReqs = variables . filter ( v =>
819+ v . usedBy && v . usedBy . length > 0 && v . origin [ 0 ] . id === 'chainedInputMappings'
820+ ) ;
821+ const names = chainedReqs . map ( v => v . name ) ;
822+
823+ // then
824+ expect ( names ) . to . include ( 'processVar3' ) ;
825+ expect ( names ) . to . not . include ( 'localC' ) ;
826+ expect ( names ) . to . not . include ( 'localD' ) ;
827+ } ) ) ;
828+
829+
830+ it ( 'should keep shadowed variable as input requirement when mapping a to a' , inject ( async function ( variableResolver ) {
831+
832+ // when
833+ const variables = ( await variableResolver . getVariables ( ) ) [ 'Process_1' ] ;
834+ const shadowReqs = variables . filter ( v =>
835+ v . usedBy && v . usedBy . length > 0 && v . origin [ 0 ] . id === 'shadowingTask'
836+ ) ;
837+ const names = shadowReqs . map ( v => v . name ) ;
838+
839+ // then
840+ expect ( names ) . to . include ( 'a' ) ;
841+ } ) ) ;
842+
843+
844+ it ( 'should handle shadowing with chaining correctly' , inject ( async function ( variableResolver ) {
845+
846+ // when
847+ const variables = ( await variableResolver . getVariables ( ) ) [ 'Process_1' ] ;
848+ const reqs = variables . filter ( v =>
849+ v . usedBy && v . usedBy . length > 0 && v . origin [ 0 ] . id === 'shadowingChainedTask'
850+ ) ;
851+ const names = reqs . map ( v => v . name ) ;
852+
853+ // then
854+ expect ( names ) . to . include ( 'a' ) ;
855+ expect ( names ) . to . not . include ( 'b' ) ;
856+ } ) ) ;
857+
815858 } ) ;
816859
817860
@@ -978,14 +1021,12 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
9781021
9791022 it ( 'should only return process variables as input requirements, not locally mapped ones' , inject ( async function ( variableResolver , elementRegistry ) {
9801023
981- // given
982- const task = elementRegistry . get ( 'scriptWithInputs' ) ;
983-
9841024 // when
985- const requirements = await variableResolver . getInputRequirementsForElement ( task ) ;
1025+ const requirements = await variableResolver . getInputRequirementsForElement (
1026+ elementRegistry . get ( 'scriptWithInputs' )
1027+ ) ;
9861028
987- // then - only processVar1 and processVar2 (from input mapping sources) should
988- // be requirements, not localA and localB (input mapping targets used in the script)
1029+ // then
9891030 const names = requirements . map ( v => v . name ) ;
9901031 expect ( names ) . to . include ( 'processVar1' ) ;
9911032 expect ( names ) . to . include ( 'processVar2' ) ;
@@ -997,11 +1038,10 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
9971038
9981039 it ( 'should return all script variables for task without input mappings' , inject ( async function ( variableResolver , elementRegistry ) {
9991040
1000- // given
1001- const task = elementRegistry . get ( 'scriptWithoutInputs' ) ;
1002-
10031041 // when
1004- const requirements = await variableResolver . getInputRequirementsForElement ( task ) ;
1042+ const requirements = await variableResolver . getInputRequirementsForElement (
1043+ elementRegistry . get ( 'scriptWithoutInputs' )
1044+ ) ;
10051045
10061046 // then
10071047 const names = requirements . map ( v => v . name ) ;
@@ -1010,6 +1050,51 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
10101050 expect ( requirements ) . to . have . length ( 2 ) ;
10111051 } ) ) ;
10121052
1053+
1054+ it ( 'should handle chained input mappings respecting order' , inject ( async function ( variableResolver , elementRegistry ) {
1055+
1056+ // when
1057+ const requirements = await variableResolver . getInputRequirementsForElement (
1058+ elementRegistry . get ( 'chainedInputMappings' )
1059+ ) ;
1060+
1061+ // then
1062+ const names = requirements . map ( v => v . name ) ;
1063+ expect ( names ) . to . include ( 'processVar3' ) ;
1064+ expect ( names ) . to . not . include ( 'localC' ) ;
1065+ expect ( names ) . to . not . include ( 'localD' ) ;
1066+ expect ( requirements ) . to . have . length ( 1 ) ;
1067+ } ) ) ;
1068+
1069+
1070+ it ( 'should keep shadowed variable as requirement when mapping a to a' , inject ( async function ( variableResolver , elementRegistry ) {
1071+
1072+ // when
1073+ const requirements = await variableResolver . getInputRequirementsForElement (
1074+ elementRegistry . get ( 'shadowingTask' )
1075+ ) ;
1076+
1077+ // then
1078+ const names = requirements . map ( v => v . name ) ;
1079+ expect ( names ) . to . include ( 'a' ) ;
1080+ expect ( requirements ) . to . have . length ( 1 ) ;
1081+ } ) ) ;
1082+
1083+
1084+ it ( 'should handle shadowing with chained mappings' , inject ( async function ( variableResolver , elementRegistry ) {
1085+
1086+ // when
1087+ const requirements = await variableResolver . getInputRequirementsForElement (
1088+ elementRegistry . get ( 'shadowingChainedTask' )
1089+ ) ;
1090+
1091+ // then
1092+ const names = requirements . map ( v => v . name ) ;
1093+ expect ( names ) . to . include ( 'a' ) ;
1094+ expect ( names ) . to . not . include ( 'b' ) ;
1095+ expect ( requirements ) . to . have . length ( 1 ) ;
1096+ } ) ) ;
1097+
10131098 } ) ;
10141099
10151100
0 commit comments