Skip to content

Commit 487b2ac

Browse files
committed
Add back tests
1 parent 58215a2 commit 487b2ac

File tree

2 files changed

+66
-39
lines changed

2 files changed

+66
-39
lines changed

Gopkg.lock

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bot_test.go

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,50 @@ package main_test
22

33
import (
44
"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"
510
)
611

712
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")
1543
assert.Equal(t, traverser.CurrentState(), "locked")
44+
turnCount = traverser.Fetch("turn-count")
45+
assert.Equal(t, turnCount.(int), i)
46+
}
1647

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)
4851
}

0 commit comments

Comments
 (0)