-
Notifications
You must be signed in to change notification settings - Fork 7
/
ussd_test.go
79 lines (61 loc) · 1.83 KB
/
ussd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package ussd
import (
"github.com/samora/ussd-go/sessionstores"
"github.com/stretchr/testify/suite"
"testing"
)
const DummyServiceCode = "*123#"
type UssdSuite struct {
suite.Suite
ussd *Ussd
request *Request
store *sessionstores.Redis
}
func (u *UssdSuite) SetupSuite() {
u.request = &Request{}
u.request.Mobile = "233246662003"
u.request.Network = "vodafone"
u.request.Message = DummyServiceCode
u.store = sessionstores.NewRedis("localhost:6379")
u.ussd = New("demo", "Menu")
u.ussd.Middleware(addData("global", "i'm here"))
u.ussd.Ctrl(new(demo))
}
// func (u *UssdSuite) TearDownSuite() {
// u.ussd.end()
// }
func (u UssdSuite) TestUssd() {
u.Equal(1, len(u.ussd.middlewares))
u.Equal(2, len(u.ussd.ctrls))
data := Data{}
response := u.ussd.process(u.store, data, u.request)
u.False(response.Release)
u.Contains(response.Message, "Welcome")
u.request.Message = "1"
response = u.ussd.process(u.store, data, u.request)
u.Contains(response.Message, "Enter Name")
u.request.Message = "Samora"
response = u.ussd.process(u.store, data, u.request)
u.False(response.Release)
u.Contains(response.Message, "Select Sex")
u.request.Message = "1"
response = u.ussd.process(u.store, data, u.request)
u.False(response.Release)
u.Contains(response.Message, "Enter Age")
u.request.Message = "twenty"
response = u.ussd.process(u.store, data, u.request)
u.False(response.Release)
u.Contains(response.Message, "integer")
u.request.Message = "29"
response = u.ussd.process(u.store, data, u.request)
u.True(response.Release)
u.Contains(response.Message, "Master Samora")
u.request.Message = "*123*"
u.ussd.process(u.store, data, u.request)
u.request.Message = "0"
response = u.ussd.process(u.store, data, u.request)
u.Equal("Bye bye.", response.Message)
}
func TestUssdSuite(t *testing.T) {
suite.Run(t, new(UssdSuite))
}