forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
contact_api_test.go
87 lines (79 loc) · 3.13 KB
/
contact_api_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
package intercom
import "testing"
func TestContactAPIFind(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/contact.json", expectedURI: "/contacts/54c42e7ea7a765fa7", t: t}
api := ContactAPI{httpClient: &http}
contact, err := api.find(UserIdentifiers{ID: "54c42e7ea7a765fa7"})
if err != nil {
t.Errorf("Error parsing fixture %s", err)
}
if contact.ID != "54c42e7ea7a765fa7" {
t.Errorf("ID was %s, expected 54c42e7ea7a765fa7", contact.ID)
}
if contact.Phone != "+1234567890" {
t.Errorf("Phone was %s, expected +1234567890", contact.Phone)
}
if contact.UserID != "123" {
t.Errorf("UserID was %s, expected 123", contact.UserID)
}
}
func TestContactAPIListDefault(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/contacts.json", expectedURI: "/contacts", t: t}
api := ContactAPI{httpClient: &http}
contactList, _ := api.list(contactListParams{})
contacts := contactList.Contacts
if contacts[0].ID != "54c42e7ea7a765fa7" {
t.Errorf("ID was %s, expected 54c42e7ea7a765fa7", contacts[0].ID)
}
pages := contactList.Pages
if pages.Page != 1 {
t.Errorf("Page was %d, expected 1", pages.Page)
}
}
func TestContactAPIListByEmail(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/contacts.json", expectedURI: "/contacts", t: t}
api := ContactAPI{httpClient: &http}
contactList, _ := api.list(contactListParams{Email: "[email protected]"})
contacts := contactList.Contacts
if contacts[0].ID != "54c42e7ea7a765fa7" {
t.Errorf("ID was %s, expected 54c42e7ea7a765fa7", contacts[0].ID)
}
if clParams, ok := http.lastQueryParams.(contactListParams); !ok || clParams.Email != "[email protected]" {
t.Errorf("Email expected to be [email protected], but was %s", clParams.Email)
}
pages := contactList.Pages
if pages.Page != 1 {
t.Errorf("Page was %d, expected 1", pages.Page)
}
}
func TestContactAPICreate(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/contact.json", expectedURI: "/contacts", t: t}
api := ContactAPI{httpClient: &http}
contact := &Contact{Email: "[email protected]"}
api.create(contact)
}
func TestContactAPIUpdate(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/contact.json", expectedURI: "/contacts", t: t}
api := ContactAPI{httpClient: &http}
contact := &Contact{UserID: "123", Email: "[email protected]"}
api.update(contact)
}
func TestContactAPIConvert(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/user.json", expectedURI: "/contacts/convert", t: t}
api := ContactAPI{httpClient: &http}
contact := &Contact{UserID: "abc", Email: "[email protected]"}
user := &User{UserID: "123"}
returned, _ := api.convert(contact, user)
if returned.UserID != "123" {
t.Errorf("Expected UserID %s, got %s", "123", returned.UserID)
}
}
func TestContactAPIDelete(t *testing.T) {
http := TestUserHTTPClient{fixtureFilename: "fixtures/contact.json", expectedURI: "/contacts/b123d", t: t}
api := ContactAPI{httpClient: &http}
contact := &Contact{ID: "b123d"}
returned, _ := api.delete(contact.ID)
if returned.UserID != "123" {
t.Errorf("Expected UserID %s, got %s", "123", returned.UserID)
}
}