-
Notifications
You must be signed in to change notification settings - Fork 11
/
contact_test.go
62 lines (57 loc) · 1.59 KB
/
contact_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
package harvest
import "testing"
func testContact(t *testing.T) *Contact {
a := testAPI()
contactResponse := mockResponse("contacts", "contact-example.json")
a.BaseURL = contactResponse.URL
contact, err := a.GetContact(2937808, Defaults())
if err != nil {
t.Fatal(err)
}
return contact
}
func TestGetContact(t *testing.T) {
contact := testContact(t)
if contact == nil {
t.Fatal("testContact() returned nil instead of contact")
}
if contact.ID != 2937808 {
t.Errorf("Incorrect contact ID '%v'", contact.ID)
}
}
func TestGetClientContacts(t *testing.T) {
a := testAPI()
contactResponse := mockResponse("contacts", "contacts-example.json")
a.BaseURL = contactResponse.URL
contacts, err := a.GetClientContacts(1661738, Defaults())
if err != nil {
t.Fatal(err)
}
if len(contacts) != 2 {
t.Errorf("Incorrect number of contacts '%v'", len(contacts))
}
if contacts[0].LastName != "Contact" {
t.Errorf("Incorrect Last Name '%s'", contacts[0].LastName)
}
if contacts[1].Email != "person@example.com" {
t.Errorf("Incorrect Email '%s'", contacts[1].Email)
}
}
func TestGetContacts(t *testing.T) {
a := testAPI()
contactResponse := mockResponse("contacts", "contacts-example.json")
a.BaseURL = contactResponse.URL
contacts, err := a.GetContacts(Defaults())
if err != nil {
t.Fatal(err)
}
if len(contacts) != 2 {
t.Errorf("Incorrect number of contacts '%v'", len(contacts))
}
if contacts[0].LastName != "Contact" {
t.Errorf("Incorrect Last Name '%s'", contacts[0].LastName)
}
if contacts[1].Email != "person@example.com" {
t.Errorf("Incorrect Email '%s'", contacts[1].Email)
}
}