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
/
Copy pathmessage_test.go
60 lines (56 loc) · 1.46 KB
/
message_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
package chatbase
import (
"encoding/json"
"reflect"
"testing"
)
func TestMessage_Setters(t *testing.T) {
t.Run("default", func(t *testing.T) {
m := Message{
APIKey: "secret",
Type: AgentType,
UserID: "abc-123",
TimeStamp: 998877,
Platform: "test",
}
expected := Message{
APIKey: "secret",
Type: AgentType,
UserID: "abc-123",
TimeStamp: 111444,
Platform: "test",
Message: "Hello world!",
Intent: "test-things",
NotHandled: true,
Feedback: true,
Version: "1.2.34",
SessionID: "session-identifier",
}
m.SetMessage("Hello world!").SetIntent("test-things").SetNotHandled(true).SetFeedback(true).SetVersion("1.2.34").SetTimeStamp(111444).SetSessionID("session-identifier")
if !reflect.DeepEqual(expected, m) {
t.Errorf("Expected %#v, got %#v", expected, m)
}
})
}
func TestMessages_Append(t *testing.T) {
t.Run("default", func(t *testing.T) {
msgs := Messages{}
msgs.Append(&Message{APIKey: "foo-bar", UserID: "bar-foo"})
expected := Messages{{APIKey: "foo-bar", UserID: "bar-foo"}}
if !reflect.DeepEqual(expected, msgs) {
t.Errorf("Expected %#v, got %#v", expected, msgs)
}
})
}
func TestMessages_MarshalJSON(t *testing.T) {
t.Run("default", func(t *testing.T) {
m := Messages{}
b, err := json.Marshal(m)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
if s := string(b); s != `{"messages":[]}` {
t.Errorf("Unexpected result %v", s)
}
})
}