44 type FormattedWorkflowExecutionFailedEvent ,
55 type FormattedWorkflowExecutionTerminatedEvent ,
66 type FormattedWorkflowExecutionTimedOutEvent ,
7+ type FormattedWorkflowExecutionContinuedAsNewEvent ,
8+ type FormattedTimerFiredEvent ,
79} from '@/utils/data-formatters/schema/format-history-event-schema' ;
810
911import getWorkflowResultJson from '../get-workflow-result-json' ;
@@ -20,7 +22,7 @@ describe('getWorkflowResultJson', () => {
2022 expect ( getWorkflowResultJson ( formattedEvent ) ) . toBe ( 'canceled details' ) ;
2123 } ) ;
2224
23- it ( 'should return details for WorkflowExecutionFailed event' , ( ) => {
25+ it ( 'should return details and reason for WorkflowExecutionFailed event' , ( ) => {
2426 const formattedEvent : FormattedWorkflowExecutionFailedEvent = {
2527 eventType : 'WorkflowExecutionFailed' ,
2628 reason : 'cadenceInternal:Generic' ,
@@ -29,7 +31,10 @@ describe('getWorkflowResultJson', () => {
2931 timestamp : null ,
3032 decisionTaskCompletedEventId : '1' ,
3133 } ;
32- expect ( getWorkflowResultJson ( formattedEvent ) ) . toBe ( 'failed details' ) ;
34+ expect ( getWorkflowResultJson ( formattedEvent ) ) . toEqual ( {
35+ reason : 'cadenceInternal:Generic' ,
36+ details : 'failed details' ,
37+ } ) ;
3338 } ) ;
3439
3540 it ( 'should return details for WorkflowExecutionTerminated event' , ( ) => {
@@ -41,7 +46,11 @@ describe('getWorkflowResultJson', () => {
4146 timestamp : null ,
4247 identity : '1111' ,
4348 } ;
44- expect ( getWorkflowResultJson ( formattedEvent ) ) . toBe ( 'terminated details' ) ;
49+ expect ( getWorkflowResultJson ( formattedEvent ) ) . toEqual ( {
50+ reason : 'cadenceInternal:Generic' ,
51+ details : 'terminated details' ,
52+ identity : '1111' ,
53+ } ) ;
4554 } ) ;
4655
4756 it ( 'should return result for WorkflowExecutionCompleted event' , ( ) => {
@@ -55,13 +64,55 @@ describe('getWorkflowResultJson', () => {
5564 expect ( getWorkflowResultJson ( formattedEvent ) ) . toBe ( 'completed result' ) ;
5665 } ) ;
5766
58- it ( 'should return undefined for other eventType ' , ( ) => {
67+ it ( 'should return timeoutType for WorkflowExecutionTimedOut event ' , ( ) => {
5968 const formattedEvent : FormattedWorkflowExecutionTimedOutEvent = {
6069 eventType : 'WorkflowExecutionTimedOut' ,
6170 eventId : 1 ,
6271 timeoutType : 'TIMEOUT_TYPE_HEARTBEAT' ,
6372 timestamp : null ,
6473 } ;
74+ expect ( getWorkflowResultJson ( formattedEvent ) ) . toEqual ( {
75+ timeoutType : 'TIMEOUT_TYPE_HEARTBEAT' ,
76+ } ) ;
77+ } ) ;
78+
79+ it ( 'should return correct fields for WorkflowExecutionContinuedAsNew event' , ( ) => {
80+ const formattedEvent : FormattedWorkflowExecutionContinuedAsNewEvent = {
81+ backoffStartIntervalInSeconds : 0 ,
82+ decisionTaskCompletedEventId : '' ,
83+ eventId : 1 ,
84+ eventType : 'WorkflowExecutionContinuedAsNew' ,
85+ executionStartToCloseTimeoutSeconds : 0 ,
86+ workflowType : null ,
87+ timestamp : null ,
88+ header : { fields : { } } ,
89+ input : [ ] ,
90+ memo : { fields : { } } ,
91+ searchAttributes : { indexedFields : '' } ,
92+ taskList : { kind : 'NORMAL' , name : '' } ,
93+ taskStartToCloseTimeoutSeconds : 0 ,
94+ newExecutionRunId : '' ,
95+ initiator : 'CRON_SCHEDULE' ,
96+ failureDetails : 'Failure Details' ,
97+ failureReason : 'Failure Reason' ,
98+ lastCompletionResult : null ,
99+ } ;
100+ expect ( getWorkflowResultJson ( formattedEvent ) ) . toEqual ( {
101+ initiator : 'CRON_SCHEDULE' ,
102+ failureDetails : 'Failure Details' ,
103+ failureReason : 'Failure Reason' ,
104+ lastCompletionResult : null ,
105+ } ) ;
106+ } ) ;
107+
108+ it ( 'should return undefined for other eventType' , ( ) => {
109+ const formattedEvent : FormattedTimerFiredEvent = {
110+ eventType : 'TimerFired' ,
111+ eventId : 3 ,
112+ timestamp : null ,
113+ startedEventId : 2 ,
114+ timerId : '1' ,
115+ } ;
65116 expect ( getWorkflowResultJson ( formattedEvent ) ) . toBeUndefined ( ) ;
66117 } ) ;
67118
0 commit comments