-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow-execution.test.ts
174 lines (153 loc) · 5.42 KB
/
workflow-execution.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import { suite, test } from 'mocha-typescript';
import { WorkflowExecution } from './workflow-execution';
import * as chai from 'chai';
import { WorkflowExecutionStates as States } from './workflow-execution-states';
import { WorkflowHistoryGenerator } from '../../../../../testing/helpers/workflow-history-generator';
chai.use(require('chai-shallow-deep-equal'));
const expect = chai.expect;
@suite
class WorkflowExecutionTest {
private stateMachine: WorkflowExecution;
private historyGenerator: WorkflowHistoryGenerator;
expectStateMachine(currentState: States, params: any) {
expect(this.stateMachine.currentState).to.eq(
currentState,
`Current state "${States[this.stateMachine.currentState]}" does not match "${States[currentState]}"`);
(<any>expect(this.stateMachine).to).shallowDeepEqual(params);
}
applyStatesToStateMachine(states: States[]): void {
states.forEach(state => this.stateMachine.currentState = state);
}
before() {
this.stateMachine = new WorkflowExecution();
this.historyGenerator = new WorkflowHistoryGenerator();
}
@test
shouldTransitionToStarted() {
const event = this.historyGenerator.createStartedEvent({
input: 'test-input',
});
this.stateMachine.processHistoryEvent(event);
expect(this.stateMachine.currentState).to.eq(States.Started);
expect(this.stateMachine.input).to.eq('test-input');
}
@test
shouldTransitionToCompleted() {
const params = {
result: 'test-result',
};
const event = this.historyGenerator.createCompletedEvent(params);
this.stateMachine.currentState = States.Started;
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.Completed, params);
}
@test
shouldTransitionToCancelRequested() {
const params = {
cause: 'test cause',
};
const event = this.historyGenerator.createCancelRequestedEvent(params);
this.stateMachine.currentState = States.Started;
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.CancelRequested, params);
}
@test
shouldTransitionToCancelFailed() {
const params = {
cause: 'test cause',
};
const event = this.historyGenerator.createCancelFailedEvent(params);
this.applyStatesToStateMachine([States.Started, States.CancelRequested]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.CancelFailed, params);
}
@test
shouldTransitionToCompleteFailed() {
const params = {
cause: 'test cause',
};
const event = this.historyGenerator.createCompleteFailedEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.CompleteFailed, params);
}
@test
shouldTransitionToFailed() {
const params = {
reason: 'test reason',
};
const event = this.historyGenerator.createFailedEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.ExecutionFailed, params);
}
@test
shouldTransitionToFailFailed() {
const params = {
cause: 'test reason',
};
const event = this.historyGenerator.createFailFailedEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.FailFailed, params);
}
@test
shouldTransitionToTimedOut() {
const params = {
timeoutType: 'test timeout type',
};
const event = this.historyGenerator.createTimedOutEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.TimedOut, params);
}
@test
shouldTransitionToContinuedAsNew() {
const params = {
input: 'test input 2',
};
const event = this.historyGenerator.createContinuedAsNewEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.ContinuedAsNew, params);
}
@test
shouldTransitionToContinueAsNewFailed() {
const params = {
cause: 'my test cause',
};
const event = this.historyGenerator.createContinueAsNewFailedEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.ContinueAsNewFailed, params);
}
@test
shouldTransitionToTerminated() {
const params = {
cause: 'my test cause',
};
const event = this.historyGenerator.createTerminatedEvent(params);
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.processHistoryEvent(event);
this.expectStateMachine(States.Terminated, params);
}
@test
shouldTransitionToCompleteStateRequested() {
const params = {
requestedResult: 'test',
};
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.setCompleteStateRequestedWith('test');
this.expectStateMachine(States.CompletedStateRequested, params);
}
@test
shouldTransitionToExecutionFailedStateRequested() {
const params = {
requestedCause: 'test cause',
requestedDetails: 'test details',
};
this.applyStatesToStateMachine([States.Started]);
this.stateMachine.setExecutionFailedStateRequestedWith('test cause', 'test details');
this.expectStateMachine(States.ExecutionFailedStateRequested, params);
}
}