@@ -106,11 +106,39 @@ describe('action_status', () => {
106106 } ;
107107 } ) ;
108108
109- it ( `correctly calculates ACTION_STATES.ERROR` , ( ) => {
110- upstreamJson . actionStatusJson . last_execution . successful = false ;
111- const actionStatus = ActionStatus . fromUpstreamJson ( upstreamJson ) ;
109+ describe ( `correctly calculates ACTION_STATES.ERROR` , ( ) => {
110+ it ( 'lastExecutionSuccessful is equal to false' , ( ) => {
111+ upstreamJson . actionStatusJson . last_execution . successful = false ;
112+ const actionStatus = ActionStatus . fromUpstreamJson ( upstreamJson ) ;
113+ expect ( actionStatus . state ) . to . be ( ACTION_STATES . ERROR ) ;
114+ } ) ;
112115
113- expect ( actionStatus . state ) . to . be ( ACTION_STATES . ERROR ) ;
116+ it ( 'action is acked and lastAcknowledged is less than lastExecution' , ( ) => {
117+ const actionStatus = ActionStatus . fromUpstreamJson ( {
118+ ...upstreamJson ,
119+ actionStatusJson : {
120+ ack : {
121+ state : 'acked' ,
122+ timestamp : '2017-03-01T00:00:00.000Z' ,
123+ } ,
124+ last_execution : {
125+ timestamp : '2017-03-02T00:00:00.000Z' ,
126+ } ,
127+ } ,
128+ } ) ;
129+ expect ( actionStatus . state ) . to . be ( ACTION_STATES . ERROR ) ;
130+ } ) ;
131+
132+ it ( 'action is ackable and lastSuccessfulExecution is less than lastExecution' , ( ) => {
133+ delete upstreamJson . actionStatusJson . last_throttle ;
134+ upstreamJson . actionStatusJson . ack . state = 'ackable' ;
135+ upstreamJson . actionStatusJson . last_successful_execution . timestamp =
136+ '2017-03-01T00:00:00.000Z' ;
137+ upstreamJson . actionStatusJson . last_execution . timestamp = '2017-03-02T00:00:00.000Z' ;
138+ const actionStatus = ActionStatus . fromUpstreamJson ( upstreamJson ) ;
139+
140+ expect ( actionStatus . state ) . to . be ( ACTION_STATES . ERROR ) ;
141+ } ) ;
114142 } ) ;
115143
116144 it ( 'correctly calculates ACTION_STATES.CONFIG_ERROR' , ( ) => {
@@ -192,18 +220,7 @@ describe('action_status', () => {
192220 } ) ;
193221 } ) ;
194222
195- it ( `correctly calculates ACTION_STATES.ERROR` , ( ) => {
196- delete upstreamJson . actionStatusJson . last_throttle ;
197- upstreamJson . actionStatusJson . ack . state = 'ackable' ;
198- upstreamJson . actionStatusJson . last_successful_execution . timestamp =
199- '2017-03-01T00:00:00.000Z' ;
200- upstreamJson . actionStatusJson . last_execution . timestamp = '2017-03-02T00:00:00.000Z' ;
201- const actionStatus = ActionStatus . fromUpstreamJson ( upstreamJson ) ;
202-
203- expect ( actionStatus . state ) . to . be ( ACTION_STATES . ERROR ) ;
204- } ) ;
205-
206- it ( `throws an error if it can not determine ACTION_STATE` , ( ) => {
223+ it ( `correctly calculates ACTION_STATES.UNKNOWN if it can not determine state` , ( ) => {
207224 upstreamJson = {
208225 id : 'my-action' ,
209226 actionStatusJson : {
@@ -213,9 +230,7 @@ describe('action_status', () => {
213230 } ;
214231 const actionStatus = ActionStatus . fromUpstreamJson ( upstreamJson ) ;
215232
216- expect ( ( ) => {
217- actionStatus . state ;
218- } ) . to . throwError ( / c o u l d n o t d e t e r m i n e a c t i o n s t a t u s / i) ;
233+ expect ( actionStatus . state ) . to . be ( ACTION_STATES . UNKNOWN ) ;
219234 } ) ;
220235 } ) ;
221236
0 commit comments