-
Notifications
You must be signed in to change notification settings - Fork 27
/
message_test.go
52 lines (44 loc) · 937 Bytes
/
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
package messenger
import (
"encoding/json"
"reflect"
"strings"
"testing"
)
func TestSendMessageMarshalling(t *testing.T) {
//Avoid HTTPS in tests
GraphAPI = "http://example.com"
messenger := &Messenger{
Debug: DebugAll,
}
mockData := &MessageResponse{
RecipientID: "11213",
MessageID: "abagfda",
}
body, err := json.Marshal(mockData)
if err != nil {
t.Error(err)
}
setClient(200, body)
profile, err := messenger.SendSimpleMessage("111", "abba")
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(profile, mockData) {
t.Error("Response is invalid")
}
mockError := &rawError{
Error: Error{
Message: "error-occured",
},
}
body, err = json.Marshal(mockError)
if err != nil {
t.Error(err)
}
setClient(500, body)
profile, err = messenger.SendSimpleMessage("111", "abba")
if !strings.HasSuffix(err.Error(), mockError.Error.Message) {
t.Error("Invalid error message returned.")
}
}