forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_test.go
95 lines (81 loc) · 2.74 KB
/
user_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
package intercom
import (
"testing"
)
func TestUserFindByID(t *testing.T) {
user, _ := (&UserService{Repository: TestUserAPI{t: t}}).FindByID("46adad3f09126dca")
if user.ID != "46adad3f09126dca" {
t.Errorf("User not found")
}
}
func TestUserFindByEmail(t *testing.T) {
user, _ := (&UserService{Repository: TestUserAPI{t: t}}).FindByEmail("[email protected]")
if user.Email != "[email protected]" {
t.Errorf("User not found")
}
}
func TestUserFindByUserID(t *testing.T) {
user, _ := (&UserService{Repository: TestUserAPI{t: t}}).FindByUserID("134d")
if user.UserID != "134d" {
t.Errorf("User not found")
}
}
func TestUserList(t *testing.T) {
userList, _ := (&UserService{Repository: TestUserAPI{t: t}}).List(PageParams{})
users := userList.Users
if users[0].ID != "46adad3f09126dca" {
t.Errorf("User not listed")
}
}
func TestUserSave(t *testing.T) {
userService := UserService{Repository: TestUserAPI{t: t}}
user := User{ID: "46adad3f09126dca", CustomAttributes: map[string]interface{}{"is_cool": true}}
userService.Save(&user)
}
func TestUserDelete(t *testing.T) {
(&UserService{Repository: TestUserAPI{t: t}}).Delete("46adad3f09126dca")
}
func TestUserMessageAddress(t *testing.T) {
contact := User{ID: "46adad3f09126dca", UserID: "aaaa", Email: "[email protected]"}
address := contact.MessageAddress()
if address.ID != "46adad3f09126dca" {
t.Errorf("User address had wrong ID")
}
if address.Type != "user" {
t.Errorf("User address was not of type user, was %s", address.Type)
}
if address.Email != "[email protected]" {
t.Errorf("User address had wrong Email")
}
if address.UserID != "aaaa" {
t.Errorf("User address had wrong UserID")
}
}
type TestUserAPI struct {
t *testing.T
}
func (t TestUserAPI) find(params UserIdentifiers) (User, error) {
return User{ID: params.ID, Email: params.Email, UserID: params.UserID}, nil
}
func (t TestUserAPI) list(params userListParams) (UserList, error) {
return UserList{Users: []User{User{ID: "46adad3f09126dca", Email: "[email protected]", UserID: "aa123"}}}, nil
}
func (t TestUserAPI) scroll(scrollParam string) (UserList, error) {
return UserList{Users: []User{User{ID: "46adad3f09126dca", Email: "[email protected]", UserID: "aa123"}}}, nil
}
func (t TestUserAPI) save(user *User) (User, error) {
if user.ID != "46adad3f09126dca" {
t.t.Errorf("User ID was %s, expected 46adad3f09126dca", user.ID)
}
expectedCAs := map[string]interface{}{"is_cool": true}
if user.CustomAttributes["is_cool"] != expectedCAs["is_cool"] {
t.t.Errorf("Custom attributes was %v, expected %v", user.CustomAttributes, expectedCAs)
}
return User{}, nil
}
func (t TestUserAPI) delete(id string) (User, error) {
if id != "46adad3f09126dca" {
t.t.Errorf("id was %s, expected 46adad3f09126dca", id)
}
return User{}, nil
}