Skip to content

Commit 17fad27

Browse files
authored
Merge pull request #164 from antmendoza/fix-diagram-generation
fix diagram generation serverlessworkflow/specification#587
2 parents 6d4dfb5 + 0cf8067 commit 17fad27

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/lib/diagram/mermaidState.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { Specification } from '../definitions';
17-
import { isObject } from '../utils';
16+
import {Specification} from '../definitions';
17+
import {isObject} from '../utils';
1818

1919
export class MermaidState {
2020
constructor(
@@ -144,7 +144,7 @@ export class MermaidState {
144144
if (isObject(this.state.end)) {
145145
const end = this.state.end as Specification.End;
146146

147-
if (end.produceEvents!.length > 0) {
147+
if (end.produceEvents) {
148148
transitionLabel = 'Produced event = [' + end.produceEvents!.map((pe) => pe.eventRef).join(',') + ']';
149149
}
150150
}

tests/lib/diagram/mermaidState.spec.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ CheckApplication --> RejectApplication : \${ .applicants | .age < 18 }
109109
CheckApplication --> RejectApplication : default`);
110110
});
111111

112-
it('should create source code for data-based state with end condition', () => {
112+
it('should create source code for data-based state with end = true ', () => {
113113
const databasedswitch = new Specification.Databasedswitchstate(
114-
JSON.parse(`{
114+
JSON.parse(`{
115115
"type":"switch",
116116
"name":"CheckApplication",
117117
"dataConditions": [
@@ -138,6 +138,35 @@ CheckApplication --> [*] : \${ .applicants | .age < 18 }
138138
CheckApplication --> StartApplication : default`);
139139
});
140140

141+
142+
it('should create source code for operation state with end.terminate = true ', () => {
143+
const databasedswitch = new Specification.Databasedswitchstate(
144+
JSON.parse(`{
145+
"name": "GreetPerson",
146+
"type": "operation",
147+
"actions": [
148+
{
149+
"name": "greetAction",
150+
"functionRef": {
151+
"refName": "greetFunction",
152+
"arguments": {
153+
"message": "$.greeting $.name"
154+
}
155+
}
156+
}
157+
],
158+
"end": {
159+
"terminate": true
160+
}
161+
}`)
162+
);
163+
const mermaidState = new MermaidState(databasedswitch);
164+
expect(mermaidState.sourceCode()).toBe(`GreetPerson : GreetPerson
165+
GreetPerson : type = Operation State
166+
GreetPerson : Num. of actions = 1
167+
GreetPerson --> [*]`);
168+
});
169+
141170
it('should create source code for operation state', () => {
142171
const states = new Specification.Operationstate(
143172
JSON.parse(`{

0 commit comments

Comments
 (0)