|
| 1 | +import { |
| 2 | + mockActivityEventGroup, |
| 3 | + mockDecisionEventGroup, |
| 4 | + mockTimerEventGroup, |
| 5 | + mockChildWorkflowEventGroup, |
| 6 | + mockSignalExternalWorkflowEventGroup, |
| 7 | + mockRequestCancelExternalWorkflowEventGroup, |
| 8 | + mockSingleEventGroup, |
| 9 | +} from '../../../__fixtures__/workflow-history-event-groups'; |
| 10 | +import { type WorkflowHistoryFiltersTypeValue } from '../../workflow-history-filters-type.types'; |
| 11 | +import filterGroupsByGroupType from '../filter-groups-by-group-type'; |
| 12 | + |
| 13 | +describe(filterGroupsByGroupType.name, () => { |
| 14 | + it('should return true if historyEventTypes is undefined', () => { |
| 15 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 16 | + historyEventTypes: undefined, |
| 17 | + }; |
| 18 | + |
| 19 | + expect(filterGroupsByGroupType(mockActivityEventGroup, value)).toBe(true); |
| 20 | + expect(filterGroupsByGroupType(mockDecisionEventGroup, value)).toBe(true); |
| 21 | + expect(filterGroupsByGroupType(mockTimerEventGroup, value)).toBe(true); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return true if Activity group type is included in historyEventTypes', () => { |
| 25 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 26 | + historyEventTypes: ['ACTIVITY'], |
| 27 | + }; |
| 28 | + |
| 29 | + expect(filterGroupsByGroupType(mockActivityEventGroup, value)).toBe(true); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should return false if Activity group type is not included in historyEventTypes', () => { |
| 33 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 34 | + historyEventTypes: ['DECISION', 'TIMER'], |
| 35 | + }; |
| 36 | + |
| 37 | + expect(filterGroupsByGroupType(mockActivityEventGroup, value)).toBe(false); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should return true if Decision group type is included in historyEventTypes', () => { |
| 41 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 42 | + historyEventTypes: ['DECISION'], |
| 43 | + }; |
| 44 | + |
| 45 | + expect(filterGroupsByGroupType(mockDecisionEventGroup, value)).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should return false if Decision group type is not included in historyEventTypes', () => { |
| 49 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 50 | + historyEventTypes: ['ACTIVITY', 'TIMER'], |
| 51 | + }; |
| 52 | + |
| 53 | + expect(filterGroupsByGroupType(mockDecisionEventGroup, value)).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should return true if Timer group type is included in historyEventTypes', () => { |
| 57 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 58 | + historyEventTypes: ['TIMER'], |
| 59 | + }; |
| 60 | + |
| 61 | + expect(filterGroupsByGroupType(mockTimerEventGroup, value)).toBe(true); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return true if ChildWorkflowExecution group type is included in historyEventTypes', () => { |
| 65 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 66 | + historyEventTypes: ['CHILDWORKFLOW'], |
| 67 | + }; |
| 68 | + |
| 69 | + expect(filterGroupsByGroupType(mockChildWorkflowEventGroup, value)).toBe( |
| 70 | + true |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should return true if SignalExternalWorkflowExecution group type is included in historyEventTypes', () => { |
| 75 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 76 | + historyEventTypes: ['SIGNAL'], |
| 77 | + }; |
| 78 | + |
| 79 | + expect( |
| 80 | + filterGroupsByGroupType(mockSignalExternalWorkflowEventGroup, value) |
| 81 | + ).toBe(true); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should return true if RequestCancelExternalWorkflowExecution group type maps to WORKFLOW and is included in historyEventTypes', () => { |
| 85 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 86 | + historyEventTypes: ['WORKFLOW'], |
| 87 | + }; |
| 88 | + |
| 89 | + expect( |
| 90 | + filterGroupsByGroupType( |
| 91 | + mockRequestCancelExternalWorkflowEventGroup, |
| 92 | + value |
| 93 | + ) |
| 94 | + ).toBe(true); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should return true if Event group type maps to WORKFLOW and is included in historyEventTypes', () => { |
| 98 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 99 | + historyEventTypes: ['WORKFLOW'], |
| 100 | + }; |
| 101 | + |
| 102 | + expect(filterGroupsByGroupType(mockSingleEventGroup, value)).toBe(true); |
| 103 | + }); |
| 104 | + |
| 105 | + it('should return true when multiple types are included and group type matches one of them', () => { |
| 106 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 107 | + historyEventTypes: ['ACTIVITY', 'DECISION', 'TIMER'], |
| 108 | + }; |
| 109 | + |
| 110 | + expect(filterGroupsByGroupType(mockActivityEventGroup, value)).toBe(true); |
| 111 | + expect(filterGroupsByGroupType(mockDecisionEventGroup, value)).toBe(true); |
| 112 | + expect(filterGroupsByGroupType(mockTimerEventGroup, value)).toBe(true); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should return false when multiple types are included but group type does not match any of them', () => { |
| 116 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 117 | + historyEventTypes: ['ACTIVITY', 'DECISION'], |
| 118 | + }; |
| 119 | + |
| 120 | + expect(filterGroupsByGroupType(mockTimerEventGroup, value)).toBe(false); |
| 121 | + expect(filterGroupsByGroupType(mockChildWorkflowEventGroup, value)).toBe( |
| 122 | + false |
| 123 | + ); |
| 124 | + expect( |
| 125 | + filterGroupsByGroupType(mockSignalExternalWorkflowEventGroup, value) |
| 126 | + ).toBe(false); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should handle empty historyEventTypes array', () => { |
| 130 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 131 | + historyEventTypes: [], |
| 132 | + }; |
| 133 | + |
| 134 | + expect(filterGroupsByGroupType(mockActivityEventGroup, value)).toBe(false); |
| 135 | + expect(filterGroupsByGroupType(mockDecisionEventGroup, value)).toBe(false); |
| 136 | + expect(filterGroupsByGroupType(mockTimerEventGroup, value)).toBe(false); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should correctly map both RequestCancelExternalWorkflowExecution and Event to WORKFLOW', () => { |
| 140 | + const value: WorkflowHistoryFiltersTypeValue = { |
| 141 | + historyEventTypes: ['WORKFLOW'], |
| 142 | + }; |
| 143 | + |
| 144 | + expect( |
| 145 | + filterGroupsByGroupType( |
| 146 | + mockRequestCancelExternalWorkflowEventGroup, |
| 147 | + value |
| 148 | + ) |
| 149 | + ).toBe(true); |
| 150 | + expect(filterGroupsByGroupType(mockSingleEventGroup, value)).toBe(true); |
| 151 | + |
| 152 | + // Should return false for other types when only WORKFLOW is included |
| 153 | + expect(filterGroupsByGroupType(mockActivityEventGroup, value)).toBe(false); |
| 154 | + expect(filterGroupsByGroupType(mockDecisionEventGroup, value)).toBe(false); |
| 155 | + }); |
| 156 | +}); |
0 commit comments