@@ -2,47 +2,50 @@ package main_test
2
2
3
3
import (
4
4
"testing"
5
+
6
+ "github.com/fsm/emitable"
7
+ bot "github.com/fsm/getting-started"
8
+ "github.com/fsm/test"
9
+ "github.com/stretchr/testify/assert"
5
10
)
6
11
7
12
func TestChatbot (t * testing.T ) {
8
- /*
9
- traverser := test.New(bot.GetStateMachine(), bot.GetStore())
10
-
11
- // Send initial message
12
- traverser.Send("Hi")
13
-
14
- // Verify we're in the proper state
13
+ traverser := test .New (bot .GetStateMachine (), bot .GetStore ())
14
+
15
+ // Send initial message
16
+ traverser .Send ("Hi" )
17
+
18
+ // Verify we're in the proper state
19
+ assert .Equal (t , traverser .CurrentState (), "locked" )
20
+
21
+ // Validate turn-count variable
22
+ turnCount := traverser .Fetch ("turn-count" )
23
+ assert .Equal (t , turnCount .(int ), 0 )
24
+
25
+ // Validate that messages are being emitted received
26
+ assert .Equal (t ,
27
+ "Hello and welcome! I am Turnstile 3000." ,
28
+ traverser .GetReceived (),
29
+ )
30
+ assert .Equal (t ,
31
+ "I am currently locked, and need a coin to be unlocked." ,
32
+ traverser .GetReceived ().(emitable.QuickReply ).Message ,
33
+ )
34
+
35
+ // Go through the turnstyle 5 times
36
+ for i := 1 ; i <= 5 ; i ++ {
37
+ // Insert a coin
38
+ traverser .Send ("insert coin" )
39
+ assert .Equal (t , traverser .CurrentState (), "unlocked" )
40
+
41
+ // Push the turnstyle
42
+ traverser .Send ("push" )
15
43
assert .Equal (t , traverser .CurrentState (), "locked" )
44
+ turnCount = traverser .Fetch ("turn-count" )
45
+ assert .Equal (t , turnCount .(int ), i )
46
+ }
16
47
17
- // Validate turn-count variable
18
- turnCount, _ := traverser.Fetch("turn-count")
19
- assert.Equal(t, turnCount.(int), 0)
20
-
21
- // Validate that messages are being emitted received
22
- assert.Equal(t,
23
- "Hello and welcome! I am Turnstile 3000.",
24
- traverser.GetReceived(),
25
- )
26
- assert.Equal(t,
27
- "I am currently locked, and need a coin to be unlocked.",
28
- traverser.GetReceived().(emitable.QuickReply).Message,
29
- )
30
-
31
- // Go through the turnstyle 5 times
32
- for i := 1; i <= 5; i++ {
33
- // Insert a coin
34
- traverser.Send("insert coin")
35
- assert.Equal(t, traverser.CurrentState(), "unlocked")
36
-
37
- // Push the turnstyle
38
- traverser.Send("push")
39
- assert.Equal(t, traverser.CurrentState(), "locked")
40
- turnCount, _ = traverser.Fetch("turn-count")
41
- assert.Equal(t, turnCount.(int), i)
42
- }
43
-
44
- // Turn count should be 5 now
45
- turnCount, _ = traverser.Fetch("turn-count")
46
- assert.Equal(t, turnCount.(int), 5)
47
- */
48
+ // Turn count should be 5 now
49
+ turnCount = traverser .Fetch ("turn-count" )
50
+ assert .Equal (t , turnCount .(int ), 5 )
48
51
}
0 commit comments