Skip to content

Commit 8384988

Browse files
authored
fix result json for non completed workflows (#711)
1 parent b513f85 commit 8384988

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {
2+
type FormattedWorkflowExecutionCanceledEvent,
3+
type FormattedWorkflowExecutionCompletedEvent,
4+
type FormattedWorkflowExecutionFailedEvent,
5+
type FormattedWorkflowExecutionTerminatedEvent,
6+
type FormattedWorkflowExecutionTimedOutEvent,
7+
} from '@/utils/data-formatters/schema/format-history-event-schema';
8+
9+
import getWorkflowResultJson from '../get-workflow-result-json';
10+
11+
describe('getWorkflowResultJson', () => {
12+
it('should return details for WorkflowExecutionCanceled event', () => {
13+
const formattedEvent: FormattedWorkflowExecutionCanceledEvent = {
14+
eventType: 'WorkflowExecutionCanceled',
15+
details: 'canceled details',
16+
decisionTaskCompletedEventId: '1',
17+
eventId: 2,
18+
timestamp: null,
19+
};
20+
expect(getWorkflowResultJson(formattedEvent)).toBe('canceled details');
21+
});
22+
23+
it('should return details for WorkflowExecutionFailed event', () => {
24+
const formattedEvent: FormattedWorkflowExecutionFailedEvent = {
25+
eventType: 'WorkflowExecutionFailed',
26+
reason: 'cadenceInternal:Generic',
27+
details: 'failed details',
28+
eventId: 2,
29+
timestamp: null,
30+
decisionTaskCompletedEventId: '1',
31+
};
32+
expect(getWorkflowResultJson(formattedEvent)).toBe('failed details');
33+
});
34+
35+
it('should return details for WorkflowExecutionTerminated event', () => {
36+
const formattedEvent: FormattedWorkflowExecutionTerminatedEvent = {
37+
eventType: 'WorkflowExecutionTerminated',
38+
details: 'terminated details',
39+
reason: 'cadenceInternal:Generic',
40+
eventId: 2,
41+
timestamp: null,
42+
identity: '1111',
43+
};
44+
expect(getWorkflowResultJson(formattedEvent)).toBe('terminated details');
45+
});
46+
47+
it('should return result for WorkflowExecutionCompleted event', () => {
48+
const formattedEvent: FormattedWorkflowExecutionCompletedEvent = {
49+
eventType: 'WorkflowExecutionCompleted',
50+
result: 'completed result',
51+
decisionTaskCompletedEventId: '1',
52+
eventId: 1,
53+
timestamp: null,
54+
};
55+
expect(getWorkflowResultJson(formattedEvent)).toBe('completed result');
56+
});
57+
58+
it('should return undefined for other eventType', () => {
59+
const formattedEvent: FormattedWorkflowExecutionTimedOutEvent = {
60+
eventType: 'WorkflowExecutionTimedOut',
61+
eventId: 1,
62+
timeoutType: 'TIMEOUT_TYPE_HEARTBEAT',
63+
timestamp: null,
64+
};
65+
expect(getWorkflowResultJson(formattedEvent)).toBeUndefined();
66+
});
67+
68+
it('should return undefined if eventType is undefined', () => {
69+
const formattedEvent = {};
70+
// @ts-expect-error empty eventType
71+
expect(getWorkflowResultJson(formattedEvent)).toBeUndefined();
72+
});
73+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { type FormattedHistoryEvent } from '@/utils/data-formatters/schema/format-history-event-schema';
2+
3+
export default function getWorkflowResultJson(
4+
formattedEvent: FormattedHistoryEvent
5+
) {
6+
const eventType = formattedEvent.eventType;
7+
if (
8+
eventType === 'WorkflowExecutionCanceled' ||
9+
eventType === 'WorkflowExecutionFailed' ||
10+
eventType === 'WorkflowExecutionTerminated'
11+
)
12+
return formattedEvent.details;
13+
14+
if (eventType === 'WorkflowExecutionCompleted') return formattedEvent.result;
15+
16+
return undefined;
17+
}

src/views/workflow-summary-tab/workflow-summary-tab.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { WorkflowPageTabContentProps } from '@/views/workflow-page/workflow
1818
import getWorkflowIsCompleted from '../workflow-page/helpers/get-workflow-is-completed';
1919
import useDescribeWorkflow from '../workflow-page/hooks/use-describe-workflow';
2020

21+
import getWorkflowResultJson from './helpers/get-workflow-result-json';
2122
import WorkflowSummaryTabDetails from './workflow-summary-tab-details/workflow-summary-tab-details';
2223
import WorkflowSummaryTabJsonView from './workflow-summary-tab-json-view/workflow-summary-tab-json-view';
2324
import { cssStyles } from './workflow-summary-tab.styles';
@@ -58,10 +59,9 @@ export default function WorkflowSummaryTab({
5859
? formatWorkflowHistoryEvent(closeEvent)
5960
: null;
6061

61-
const resultJson =
62-
formattedCloseEvent && 'result' in formattedCloseEvent
63-
? formattedCloseEvent.result
64-
: undefined;
62+
const resultJson = formattedCloseEvent
63+
? getWorkflowResultJson(formattedCloseEvent)
64+
: undefined;
6565

6666
const isWorkflowRunning =
6767
!closeEvent ||

0 commit comments

Comments
 (0)