@@ -21,7 +21,65 @@ describe('#compileStateMachines', () => {
2121 serverlessStepFunctions = new ServerlessStepFunctions ( serverless ) ;
2222 } ) ;
2323
24- it ( 'should create corresponding resources when definition property is given' , ( ) => {
24+ it ( 'should create corresponding resources when definition and name property is given' , ( ) => {
25+ serverless . service . stepFunctions = {
26+ stateMachines : {
27+ myStateMachine1 : {
28+ name : 'stateMachineBeta1' ,
29+ definition : 'definition1' ,
30+ } ,
31+ myStateMachine2 : {
32+ name : 'stateMachineBeta2' ,
33+ definition : 'definition2' ,
34+ } ,
35+ } ,
36+ } ;
37+
38+ serverlessStepFunctions . compileStateMachines ( ) ;
39+
40+ expect ( serverlessStepFunctions . serverless . service
41+ . provider . compiledCloudFormationTemplate . Resources
42+ . StateMachineBeta1 . Type
43+ ) . to . equal ( 'AWS::StepFunctions::StateMachine' ) ;
44+ expect ( serverlessStepFunctions . serverless . service
45+ . provider . compiledCloudFormationTemplate . Resources
46+ . StateMachineBeta2 . Type
47+ ) . to . equal ( 'AWS::StepFunctions::StateMachine' ) ;
48+ expect ( serverlessStepFunctions . serverless . service
49+ . provider . compiledCloudFormationTemplate . Resources
50+ . StateMachineBeta1 . Properties . DefinitionString
51+ ) . to . equal ( '"definition1"' ) ;
52+ expect ( serverlessStepFunctions . serverless . service
53+ . provider . compiledCloudFormationTemplate . Resources
54+ . StateMachineBeta2 . Properties . DefinitionString
55+ ) . to . equal ( '"definition2"' ) ;
56+ expect ( serverlessStepFunctions . serverless . service
57+ . provider . compiledCloudFormationTemplate . Resources
58+ . StateMachineBeta1 . Properties . RoleArn [ 'Fn::GetAtt' ] [ 0 ]
59+ ) . to . equal ( 'IamRoleStateMachineExecution' ) ;
60+ expect ( serverlessStepFunctions . serverless . service
61+ . provider . compiledCloudFormationTemplate . Resources
62+ . StateMachineBeta2 . Properties . RoleArn [ 'Fn::GetAtt' ] [ 0 ]
63+ ) . to . equal ( 'IamRoleStateMachineExecution' ) ;
64+ expect ( serverlessStepFunctions . serverless . service
65+ . provider . compiledCloudFormationTemplate . Resources
66+ . StateMachineBeta1 . DependsOn
67+ ) . to . equal ( 'IamRoleStateMachineExecution' ) ;
68+ expect ( serverlessStepFunctions . serverless . service
69+ . provider . compiledCloudFormationTemplate . Resources
70+ . StateMachineBeta2 . DependsOn
71+ ) . to . equal ( 'IamRoleStateMachineExecution' ) ;
72+ expect ( serverlessStepFunctions . serverless . service
73+ . provider . compiledCloudFormationTemplate . Outputs
74+ . StateMachineBeta1Arn . Value . Ref
75+ ) . to . equal ( 'StateMachineBeta1' ) ;
76+ expect ( serverlessStepFunctions . serverless . service
77+ . provider . compiledCloudFormationTemplate . Outputs
78+ . StateMachineBeta2Arn . Value . Ref
79+ ) . to . equal ( 'StateMachineBeta2' ) ;
80+ } ) ;
81+
82+ it ( 'should create corresponding resources when definition property is given and no name' , ( ) => {
2583 serverless . service . stepFunctions = {
2684 stateMachines : {
2785 myStateMachine1 : {
@@ -129,10 +187,12 @@ describe('#compileStateMachines', () => {
129187 serverless . service . stepFunctions = {
130188 stateMachines : {
131189 myStateMachine1 : {
190+ name : 'stateMachineBeta1' ,
132191 definition : 'definition1' ,
133192 role : 'arn:aws:role1' ,
134193 } ,
135194 myStateMachine2 : {
195+ name : 'stateMachineBeta2' ,
136196 definition : 'definition2' ,
137197 role : 'arn:aws:role2' ,
138198 } ,
@@ -142,36 +202,36 @@ describe('#compileStateMachines', () => {
142202 serverlessStepFunctions . compileStateMachines ( ) ;
143203 expect ( serverlessStepFunctions . serverless . service
144204 . provider . compiledCloudFormationTemplate . Resources
145- . MyStateMachine1StepFunctionsStateMachine . Type
205+ . StateMachineBeta1 . Type
146206 ) . to . equal ( 'AWS::StepFunctions::StateMachine' ) ;
147207 expect ( serverlessStepFunctions . serverless . service
148208 . provider . compiledCloudFormationTemplate . Resources
149- . MyStateMachine2StepFunctionsStateMachine . Type
209+ . StateMachineBeta2 . Type
150210 ) . to . equal ( 'AWS::StepFunctions::StateMachine' ) ;
151211 expect ( serverlessStepFunctions . serverless . service
152212 . provider . compiledCloudFormationTemplate . Resources
153- . MyStateMachine1StepFunctionsStateMachine . Properties . DefinitionString
213+ . StateMachineBeta1 . Properties . DefinitionString
154214 ) . to . equal ( '"definition1"' ) ;
155215 expect ( serverlessStepFunctions . serverless . service
156216 . provider . compiledCloudFormationTemplate . Resources
157- . MyStateMachine2StepFunctionsStateMachine . Properties . DefinitionString
217+ . StateMachineBeta2 . Properties . DefinitionString
158218 ) . to . equal ( '"definition2"' ) ;
159219 expect ( serverlessStepFunctions . serverless . service
160220 . provider . compiledCloudFormationTemplate . Resources
161- . MyStateMachine1StepFunctionsStateMachine . Properties . RoleArn
221+ . StateMachineBeta1 . Properties . RoleArn
162222 ) . to . equal ( 'arn:aws:role1' ) ;
163223 expect ( serverlessStepFunctions . serverless . service
164224 . provider . compiledCloudFormationTemplate . Resources
165- . MyStateMachine2StepFunctionsStateMachine . Properties . RoleArn
225+ . StateMachineBeta2 . Properties . RoleArn
166226 ) . to . equal ( 'arn:aws:role2' ) ;
167227 expect ( serverlessStepFunctions . serverless . service
168228 . provider . compiledCloudFormationTemplate . Outputs
169- . MyStateMachine1StepFunctionsStateMachineArn . Value . Ref
170- ) . to . equal ( 'MyStateMachine1StepFunctionsStateMachine ' ) ;
229+ . StateMachineBeta1Arn . Value . Ref
230+ ) . to . equal ( 'StateMachineBeta1 ' ) ;
171231 expect ( serverlessStepFunctions . serverless . service
172232 . provider . compiledCloudFormationTemplate . Outputs
173- . MyStateMachine2StepFunctionsStateMachineArn . Value . Ref
174- ) . to . equal ( 'MyStateMachine2StepFunctionsStateMachine ' ) ;
233+ . StateMachineBeta2Arn . Value . Ref
234+ ) . to . equal ( 'StateMachineBeta2 ' ) ;
175235 } ) ;
176236
177237 it ( 'should throw error when definition property is not given' , ( ) => {
@@ -188,9 +248,11 @@ describe('#compileStateMachines', () => {
188248 serverless . service . stepFunctions = {
189249 stateMachines : {
190250 myStateMachine1 : {
251+ name : 'stateMachineBeta1' ,
191252 definition : 'definition1\n' ,
192253 } ,
193254 myStateMachine2 : {
255+ name : 'stateMachineBeta2' ,
194256 definition : 'definition2\n' ,
195257 } ,
196258 } ,
@@ -199,19 +261,19 @@ describe('#compileStateMachines', () => {
199261 serverlessStepFunctions . compileStateMachines ( ) ;
200262 expect ( serverlessStepFunctions . serverless . service
201263 . provider . compiledCloudFormationTemplate . Resources
202- . MyStateMachine1StepFunctionsStateMachine . Type
264+ . StateMachineBeta1 . Type
203265 ) . to . equal ( 'AWS::StepFunctions::StateMachine' ) ;
204266 expect ( serverlessStepFunctions . serverless . service
205267 . provider . compiledCloudFormationTemplate . Resources
206- . MyStateMachine2StepFunctionsStateMachine . Type
268+ . StateMachineBeta2 . Type
207269 ) . to . equal ( 'AWS::StepFunctions::StateMachine' ) ;
208270 expect ( serverlessStepFunctions . serverless . service
209271 . provider . compiledCloudFormationTemplate . Resources
210- . MyStateMachine1StepFunctionsStateMachine . Properties . DefinitionString
272+ . StateMachineBeta1 . Properties . DefinitionString
211273 ) . to . equal ( '"definition1"' ) ;
212274 expect ( serverlessStepFunctions . serverless . service
213275 . provider . compiledCloudFormationTemplate . Resources
214- . MyStateMachine2StepFunctionsStateMachine . Properties . DefinitionString
276+ . StateMachineBeta2 . Properties . DefinitionString
215277 ) . to . equal ( '"definition2"' ) ;
216278 } ) ;
217279
@@ -221,6 +283,7 @@ describe('#compileStateMachines', () => {
221283 myStateMachine1 : {
222284 definition : 'definition1' ,
223285 role : 'srn:aws:role1' ,
286+ name : 'stateMachineBeta1' ,
224287 } ,
225288 } ,
226289 } ;
@@ -231,6 +294,7 @@ describe('#compileStateMachines', () => {
231294 serverless . service . stepFunctions = {
232295 stateMachines : {
233296 myStateMachine1 : {
297+ name : 'stateMachineBeta1' ,
234298 definition : 'definition1' ,
235299 role : { 'arn:aws:role1' : 'ss' } ,
236300 } ,
@@ -241,6 +305,7 @@ describe('#compileStateMachines', () => {
241305 serverless . service . stepFunctions = {
242306 stateMachines : {
243307 myStateMachine1 : {
308+ name : 'stateMachineBeta2' ,
244309 definition : 'definition1' ,
245310 role : [ 'arn:aws:role1' ] ,
246311 } ,
0 commit comments