|
| 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 | +}); |
0 commit comments