LetsFlow
Search…
A proper introduction
Use response data and data instructions.
In the previous tutorial two actors greeted each other and could have a small conversation. In this tutorial we have a similar premise. The initiator is now at a conference, where he strikes a conversation introducing himself.
Create a new subdirectory named introduction.
To keep it simple we're not modeling all kind of different responses in this tutorial. For that take a look at the "A handshake" tutorial.

Introduce yourself

Joe, the initiator, will introduce himself stating his name and organization. Jane will respond by introducing herself also stating her name and organization.
1
Feature: Two actors meet at a conference and exchange information.
2
3
Background:
4
Given a chain is created by "Joe"
5
Given "Joe" creates the "main" process using the "introduction" scenario
6
And "Joe" is the "initiator" actor of the "main" process
7
And "Jane" is the "recipient" actor of the "main" process
8
9
Scenario:
10
When "Joe" runs the "introduce_initiator" action of the "main" process with:
11
| name | Joe Smith |
12
| organization | LTO Network |
13
Then the "main" process is in the "wait_on_recipient" state
14
15
When "Jane" runs the "introduce_recipient" action of the "main" process with:
16
| name | Jane Wong |
17
| organization | Acme Inc |
18
Then the "main" process is completed
Copied!

The basic scenario

YAML
JSON
1
$schema: "https://specs.letsflow.io/v0.2.0/scenario/schema.json#"
2
title: A proper introduction
3
4
actors:
5
initiator:
6
title: Initiator
7
recipient:
8
title: Recipient
9
10
actions:
11
introduce_initiator:
12
title: Greet the person you're meeting
13
actor: initiator
14
introduce_recipient:
15
title: Reply to the initiator
16
actor: recipient
17
18
states:
19
initial:
20
action: introduce_initiator
21
transition: wait_on_recipient
22
wait_on_recipient:
23
action: introduce_recipient
24
transition: :success
Copied!
1
{
2
"$schema": "https://specs.letsflow.io/v0.2.0/scenario/schema.json#",
3
"title": "A proper introduction",
4
"actors": {
5
"initiator": {
6
"title": "Initiator"
7
},
8
"recipient": {
9
"title": "Recipient"
10
}
11
},
12
"actions": {
13
"introduce_initiator": {
14
"actor": "initiator"
15
},
16
"introduce_recipient": {
17
"actor": "recipient"
18
}
19
},
20
"states": {
21
"initial": {
22
"action": "introduce_initiator",
23
"transition": "wait_on_recipient"
24
},
25
"wait_on_recipient": {
26
"action": "introduce_recipient",
27
"transition": ":success"
28
}
29
}
30
}
Copied!

Using response data

Defining the actors

The process is gathering information about both actors. We need to define the properties that the actors will have.
We define the actors in the scenario using JSON schema. In the instantiated process these will become objects with the specified properties.
YAML
JSON
1
$schema: "https://specs.letsflow.io/v0.2.0/scenario/schema.json#"
2
title: A proper introduction
3
4
actors:
5
initiator:
6
$schema: "http://json-schema.org/schema#"
7
title: Initiator
8
type: object
9
properties:
10
name:
11
type: string
12
organization:
13
type: string
14
recipient:
15
$schema: "http://json-schema.org/schema#"
16
title: Recipient
17
type: object
18
properties:
19
name:
20
type: string
21
organization:
22
type: string
Copied!
1
{
2
"actors": {
3
"initiator": {
4
"$schema": "http://json-schema.org/schema#",
5
"title": "Initiator",
6
"type": "object",
7
"properties": {
8
"name": {
9
"type": "string"
10
},
11
"organization": {
12
"type": "string"
13
}
14
}
15
},
16
"recipient": {
17
"$schema": "http://json-schema.org/schema#",
18
"title": "Recipient",
19
"type": "object",
20
"properties": {
21
"name": {
22
"type": "string"
23
},
24
"organization": {
25
"type": "string"
26
}
27
}
28
}
29
}
30
}
Copied!
The JSON schema for actors can become quite big. It that case, it's recommended to store it in a separate JSON file and use $ref with a URL to the file.

Testing the actor properties

In the test, we want to see that the actors are assigned the correct properties after introducing themselves.
1
Feature: Two actors meet at a conference and exchange information.
2
3
Background:
4
Given a chain is created by "Joe"
5
Given "Joe" creates the "main" process using the "introduction" scenario
6
And "Joe" is the "initiator" actor of the "main" process
7
And "Jane" is the "recipient" actor of the "main" process
8
9
Scenario:
10
When "Joe" runs the "introduce_initiator" action of the "main" process with:
11
| name | Joe Smith |
12
| organization | LTO Network |
13
Then the "initiator" actor of the "main" process has:
14
| name | Joe Smith |
15
| organization | LTO Network |
16
And the "main" process is in the "wait_on_recipient" state
17
18
When "Jane" runs the "introduce_recipient" action of the "main" process with:
19
| name | Jane Wong |
20
| organization | Acme Inc |
21
Then the "recipient" actor of the "main" process has:
22
| name | Jane Wong |
23
| organization | Acme Inc |
24
And the "main" process is completed
Copied!

Update instructions

The process doesn't automatically update the actor information. We need to supply update instructions for each action.
Adding an update property to an action or response will update the selected object with the data that's send by the client.
YAML
JSON
1
$schema: "https://specs.letsflow.io/v0.2.0/scenario/schema.json#"
2
title: A proper introduction
3
4
actors:
5
initiator:
6
$schema: "http://json-schema.org/schema#"
7
title: Initiator
8
type: object
9
properties:
10
name:
11
type: string
12
organization:
13
type: string
14
recipient:
15
$schema: "http://json-schema.org/schema#"
16
title: Recipient
17
type: object
18
properties:
19
name:
20
type: string
21
organization:
22
type: string
23
24
actions:
25
introduce_initiator:
26
title: Greet the person you're meeting
27
actor: initiator
28
update: actors.initiator
29
introduce_recipient:
30
title: Reply to the initiator
31
actor: recipient
32
update: actors.recipient
33
34
states:
35
initial:
36
action: introduce_initiator
37
transition: wait_on_recipient
38
wait_on_recipient:
39
action: introduce_recipient
40
transition: :success
Copied!
1
{
2
"$schema": "https://specs.letsflow.io/v0.2.0/scenario/schema.json#",
3
"title": "A proper introduction",
4
"actors": {
5
"initiator": {
6
"$schema": "http://json-schema.org/schema#",
7
"title": "Initiator",
8
"type": "object",
9
"properties": {
10
"name": {
11
"type": "string"
12
},
13
"organization": {
14
"type": "string"
15
}
16
}
17
},
18
"recipient": {
19
"$schema": "http://json-schema.org/schema#",
20
"title": "Recipient",
21
"type": "object",
22
"properties": {
23
"name": {
24
"type": "string"
25
},
26
"organization": {
27
"type": "string"
28
}
29
}
30
}
31
},
32
"actions": {
33
"introduce_initiator": {
34
"title": "Greet the person you're meeting",
35
"actor": "initiator",
36
"update": "actors.initiator"
37
},
38
"introduce_recipient": {
39
"title": "Reply to the initiator",
40
"actor": "recipient",
41
"update": "actors.recipient"
42
}
43
},
44
"states": {
45
"initial": {
46
"action": "introduce_initiator",
47
"transition": "wait_on_recipient"
48
},
49
"wait_on_recipient": {
50
"action": "introduce_recipient",
51
"transition": ":success"
52
}
53
}
54
}
Copied!

Using the actor's name

Once we know the name of the actor, we can use it in the process. Rather than saying "Reply to the initiator", we could say "Reply to Joe Smith".
The <tpl> data instruction parses a mustache template, injecting process data.
YAML
JSON
1
introduce_recipient:
2
title: !tpl Reply to {{ actors.initiator }}
3
actor: recipient
4
update: actors.recipient
Copied!
1
"introduce_recipient": {
2
"title": {
3
"<tpl>": "Reply to {{ actors.initiator }}"
4
},
5
"actor": "initiator",
6
"update": "actors.initiator"
7
}
Copied!

Now you!

We only get the name and organization of the recipient. To contact her, we'd also like to know her e-mail address.
In the process, she won't give it while introducing herself. Instead the initiator may ask the information after the introduction. If he doesn't ask, the conversation is over.
To keep it simple, we'll assume she's always willing to give her e-mail address.
  1. 1.
    EditScenario section of the main.feature test file. The process isn't completed after the introduction. Instead it's in the wait on initiator state. The initiator will give run the complete action to finish the process.
  2. 2.
    Add a second Scenario section. The first steps are the same as the original Scenario. On wait on initiator, the initiator will ask for email.
  3. 3.
    The recipient will reply on email the request with her e-mail address. Her address is added to the actor information. This will complete the process.
  4. 4.
    Modify the scenario so the new test succeeds.

More data next

Process data can be utilized for much more than just being displayed in titles and instructions. In the upcoming tutorials we'll see how data can alter the flow using conditions and how it can be used when communicating with externals system.
Last modified 2yr ago