@@ -169,24 +169,60 @@ describe('ServerlessStepFunctions', () => {
169169
170170 describe ( '#stateMachineInvoke()' , ( ) => {
171171 it ( 'should run promise chain in order' , ( ) => {
172+ const parseInputdateStub = sinon
173+ . stub ( serverlessStepFunctions , 'parseInputdate' ) . returns ( BbPromise . resolve ( ) ) ;
172174 const getStateMachineArnStub = sinon
173175 . stub ( serverlessStepFunctions , 'getStateMachineArn' ) . returns ( BbPromise . resolve ( ) ) ;
174176 const startExecutionStub = sinon
175177 . stub ( serverlessStepFunctions , 'startExecution' ) . returns ( BbPromise . resolve ( ) ) ;
176178 const describeExecutionStub = sinon
177- . stub ( serverlessStepFunctions , 'describeExecution' ) . returns ( BbPromise . resolve ( ) ) ;
179+ . stub ( serverlessStepFunctions , 'describeExecution' ) . returns ( BbPromise . resolve ( { status : 'SUCCEED' } ) ) ;
178180
179181 return serverlessStepFunctions . stateMachineInvoke ( )
180182 . then ( ( ) => {
181- expect ( getStateMachineArnStub . calledOnce ) . to . be . equal ( true ) ;
183+ expect ( parseInputdateStub . calledOnce ) . to . be . equal ( true ) ;
184+ expect ( getStateMachineArnStub . calledAfter ( parseInputdateStub ) ) . to . be . equal ( true ) ;
182185 expect ( startExecutionStub . calledAfter ( getStateMachineArnStub ) ) . to . be . equal ( true ) ;
183186 expect ( describeExecutionStub . calledAfter ( startExecutionStub ) ) . to . be . equal ( true ) ;
184187
188+ serverlessStepFunctions . parseInputdate . restore ( ) ;
185189 serverlessStepFunctions . getStateMachineArn . restore ( ) ;
186190 serverlessStepFunctions . startExecution . restore ( ) ;
187191 serverlessStepFunctions . describeExecution . restore ( ) ;
188192 } ) ;
189193 } ) ;
194+
195+ it ( 'should run promise chain in order when invocation error occurs' , ( ) => {
196+ const parseInputdateStub = sinon
197+ . stub ( serverlessStepFunctions , 'parseInputdate' ) . returns ( BbPromise . resolve ( ) ) ;
198+ const getStateMachineArnStub = sinon
199+ . stub ( serverlessStepFunctions , 'getStateMachineArn' ) . returns ( BbPromise . resolve ( ) ) ;
200+ const startExecutionStub = sinon
201+ . stub ( serverlessStepFunctions , 'startExecution' ) . returns ( BbPromise . resolve ( ) ) ;
202+ const describeExecutionStub = sinon
203+ . stub ( serverlessStepFunctions , 'describeExecution' ) . returns ( BbPromise . resolve ( { status : 'FAILED' } ) ) ;
204+ const getExecutionHistoryStub = sinon
205+ . stub ( serverlessStepFunctions , 'getExecutionHistory' ) . returns ( BbPromise . resolve ( {
206+ events : [ {
207+ executionFailedEventDetails : '' ,
208+ } ] ,
209+ } ) ) ;
210+
211+ return serverlessStepFunctions . stateMachineInvoke ( )
212+ . then ( ( ) => {
213+ expect ( parseInputdateStub . calledOnce ) . to . be . equal ( true ) ;
214+ expect ( getStateMachineArnStub . calledAfter ( parseInputdateStub ) ) . to . be . equal ( true ) ;
215+ expect ( startExecutionStub . calledAfter ( getStateMachineArnStub ) ) . to . be . equal ( true ) ;
216+ expect ( describeExecutionStub . calledAfter ( startExecutionStub ) ) . to . be . equal ( true ) ;
217+ expect ( getExecutionHistoryStub . calledAfter ( describeExecutionStub ) ) . to . be . equal ( true ) ;
218+
219+ serverlessStepFunctions . parseInputdate . restore ( ) ;
220+ serverlessStepFunctions . getStateMachineArn . restore ( ) ;
221+ serverlessStepFunctions . startExecution . restore ( ) ;
222+ serverlessStepFunctions . describeExecution . restore ( ) ;
223+ serverlessStepFunctions . getExecutionHistory . restore ( ) ;
224+ } ) ;
225+ } ) ;
190226 } ) ;
191227
192228 describe ( '#getIamRoleName' , ( ) => {
@@ -490,31 +526,6 @@ describe('ServerlessStepFunctions', () => {
490526 serverlessStepFunctions . provider . request . restore ( ) ;
491527 } ) ;
492528 } ) ;
493-
494- it ( 'should describeExecution with status FAILED' , ( ) => {
495- describeExecutionStub = sinon . stub ( serverlessStepFunctions . provider , 'request' )
496- . returns ( BbPromise . resolve ( { status : 'FAILED' } ) ) ;
497- const getExecutionHistoryStub = sinon
498- . stub ( serverlessStepFunctions , 'getExecutionHistory' )
499- . returns ( BbPromise . resolve ( { events : [ { executionFailedEventDetails : 'error' } ] } ) ) ;
500-
501- serverlessStepFunctions . describeExecution ( )
502- . then ( ( ) => {
503- expect ( describeExecutionStub . calledOnce ) . to . be . equal ( true ) ;
504- expect ( describeExecutionStub . calledWithExactly (
505- 'StepFunctions' ,
506- 'describeExecution' ,
507- {
508- executionArn : serverlessStepFunctions . executionArn ,
509- } ,
510- serverlessStepFunctions . options . stage ,
511- serverlessStepFunctions . options . region
512- ) ) . to . be . equal ( true ) ;
513- expect ( getExecutionHistoryStub . calledOnce ) . to . be . equal ( true ) ;
514- serverlessStepFunctions . provider . request . restore ( ) ;
515- serverlessStepFunctions . getExecutionHistory . restore ( ) ;
516- } ) ;
517- } ) ;
518529 } ) ;
519530
520531 describe ( '#getExecutionHistory()' , ( ) => {
0 commit comments