This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
122 lines (114 loc) · 2.84 KB
/
client_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package chatbase
import (
"reflect"
"testing"
)
func TestNewClient(t *testing.T) {
t.Run("default", func(t *testing.T) {
c := New("foo-bar-baz")
if c.String() != "foo-bar-baz" {
t.Errorf("Expected foo-bar-baz, got %v", c.String())
}
})
}
func TestMessage_Client(t *testing.T) {
oldTimeStamp := TimeStamp
defer func() { TimeStamp = oldTimeStamp }()
TimeStamp = func() int64 { return 998877 }
c := New("foo-bar-baz")
t.Run("default", func(t *testing.T) {
expected := &Message{
APIKey: "foo-bar-baz",
Type: "agent",
UserID: "abc123",
TimeStamp: 998877,
Platform: "fantasy-chat",
}
m := c.Message(AgentType, "abc123", "fantasy-chat")
if !reflect.DeepEqual(expected, m) {
t.Errorf("Expected %v, got %v", expected, m)
}
})
t.Run("agent message", func(t *testing.T) {
expected := &Message{
APIKey: "foo-bar-baz",
Type: "agent",
UserID: "abc123",
TimeStamp: 998877,
Platform: "fantasy-chat",
}
m := c.AgentMessage("abc123", "fantasy-chat")
if !reflect.DeepEqual(expected, m) {
t.Errorf("Expected %v, got %v", expected, m)
}
})
t.Run("user message", func(t *testing.T) {
expected := &Message{
APIKey: "foo-bar-baz",
Type: "user",
UserID: "abc123",
TimeStamp: 998877,
Platform: "fantasy-chat",
}
m := c.UserMessage("abc123", "fantasy-chat")
if !reflect.DeepEqual(expected, m) {
t.Errorf("Expected %v, got %v", expected, m)
}
})
}
func TestEvent_Client(t *testing.T) {
t.Run("default", func(t *testing.T) {
c := New("foo-bar-baz")
expected := &Event{
APIKey: "foo-bar-baz",
UserID: "abc-123",
Intent: "test-things",
}
e := c.Event("abc-123", "test-things")
if !reflect.DeepEqual(expected, e) {
t.Errorf("Expected %v, got %v", expected, e)
}
})
}
func TestUpdate_Client(t *testing.T) {
t.Run("default", func(t *testing.T) {
c := New("foo-bar-baz")
expected := &Update{
APIKey: "foo-bar-baz",
MessageID: "abc123",
}
u := c.Update("abc123")
if !reflect.DeepEqual(expected, u) {
t.Errorf("Expected %v, got %v", expected, u)
}
})
}
func TestFacebookMessage_Client(t *testing.T) {
t.Run("default", func(t *testing.T) {
c := New("foo-bar-baz")
expected := &FacebookMessage{
APIKey: "foo-bar-baz",
Payload: map[string]string{
"hello": "world",
},
}
f := c.FacebookMessage(map[string]string{"hello": "world"})
if !reflect.DeepEqual(expected, f) {
t.Errorf("Expected %#v, got %#v", expected, f)
}
})
}
func TestFacebookRequestResponse_Client(t *testing.T) {
t.Run("default", func(t *testing.T) {
c := New("foo-bar-baz")
expected := &FacebookRequestResponse{
APIKey: "foo-bar-baz",
Request: "hello",
Response: "goodbye",
}
f := c.FacebookRequestResponse("hello", "goodbye")
if !reflect.DeepEqual(expected, f) {
t.Errorf("Expected %#v, got %#v", expected, f)
}
})
}