Skip to content

Commit

Permalink
Merge pull request #164 from antmendoza/fix-diagram-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
tsurdilo authored Feb 2, 2022
2 parents 6d4dfb5 + 0cf8067 commit 17fad27
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lib/diagram/mermaidState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Specification } from '../definitions';
import { isObject } from '../utils';
import {Specification} from '../definitions';
import {isObject} from '../utils';

export class MermaidState {
constructor(
Expand Down Expand Up @@ -144,7 +144,7 @@ export class MermaidState {
if (isObject(this.state.end)) {
const end = this.state.end as Specification.End;

if (end.produceEvents!.length > 0) {
if (end.produceEvents) {
transitionLabel = 'Produced event = [' + end.produceEvents!.map((pe) => pe.eventRef).join(',') + ']';
}
}
Expand Down
33 changes: 31 additions & 2 deletions tests/lib/diagram/mermaidState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ CheckApplication --> RejectApplication : \${ .applicants | .age < 18 }
CheckApplication --> RejectApplication : default`);
});

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


it('should create source code for operation state with end.terminate = true ', () => {
const databasedswitch = new Specification.Databasedswitchstate(
JSON.parse(`{
"name": "GreetPerson",
"type": "operation",
"actions": [
{
"name": "greetAction",
"functionRef": {
"refName": "greetFunction",
"arguments": {
"message": "$.greeting $.name"
}
}
}
],
"end": {
"terminate": true
}
}`)
);
const mermaidState = new MermaidState(databasedswitch);
expect(mermaidState.sourceCode()).toBe(`GreetPerson : GreetPerson
GreetPerson : type = Operation State
GreetPerson : Num. of actions = 1
GreetPerson --> [*]`);
});

it('should create source code for operation state', () => {
const states = new Specification.Operationstate(
JSON.parse(`{
Expand Down

0 comments on commit 17fad27

Please sign in to comment.