-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathprofile_test.go
68 lines (60 loc) · 1.33 KB
/
profile_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
package messenger
import (
"encoding/json"
"reflect"
"testing"
)
func TestGetProfile(t *testing.T) {
//Avoid HTTPS in tests
GraphAPI = "http://example.com"
messenger := &Messenger{}
mockData := &Profile{
FirstName: "John",
LastName: "Smith",
ProfilePicture: "https://example.com/",
Gender: "male",
Timezone: -5,
Locale: "en_US",
}
body, err := json.Marshal(mockData)
if err != nil {
t.Error(err)
}
setClient(200, body)
profile, err := messenger.GetProfile("123")
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(profile, mockData) {
t.Error("Profiles do not match")
}
errorData := &rawError{Error: Error{
Message: "w/e",
}}
body, err = json.Marshal(errorData)
if err != nil {
t.Error(err)
}
setClient(400, body)
_, err = messenger.GetProfile("123")
if err.Error() != "Error occured: "+errorData.Error.Message {
t.Error("Invalid error parsing")
}
}
func TestGetPSID(t *testing.T) {
GraphAPI = "http://example.com"
messenger := &Messenger{}
setClient(200, []byte(`{"recipient":"userid", "id":"pageid"}`))
psid, err := messenger.GetPSID("token")
if err != nil {
t.Error(err)
}
if *psid != "userid" {
t.Error("Invalid userid")
}
setClient(400, []byte(""))
_, err = messenger.GetPSID("token")
if err == nil {
t.Error("Error shouldn't be empty.")
}
}