-
Notifications
You must be signed in to change notification settings - Fork 6
/
contacts_test.go
97 lines (86 loc) · 1.83 KB
/
contacts_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
96
97
package hubspot
import (
"testing"
"github.com/leonelquinteros/gorand"
)
func TestContacts(t *testing.T) {
tEmailUser, err := gorand.GetAlphaNumString(8)
if err != nil {
t.Fatal(err)
}
tEmailHost, err := gorand.GetAlphaNumString(6)
if err != nil {
t.Fatal(err)
}
tEmail := tEmailUser + "@" + tEmailHost + ".com"
data := ContactsRequest{
Properties: []Property{
Property{
Property: "email",
Value: tEmail,
},
Property{
Property: "firstname",
Value: "Test",
},
Property{
Property: "lastname",
Value: "Contact",
},
},
}
// Create
c := NewClient(NewClientConfig())
r, err := c.Contacts().Create(data)
if err != nil {
t.Fatal(err)
}
if r.ErrorResponse.Status == "error" {
t.Fatal(r.ErrorResponse.Message)
}
// Update
data.Properties[1].Value = data.Properties[1].Value.(string) + "1"
if r.Vid != 0 {
err = c.Contacts().Update(r.Vid, data)
if err != nil {
t.Fatal(err)
}
if r.ErrorResponse.Status == "error" {
t.Fatal(r.ErrorResponse.Message)
}
}
// CreateOrUpdate
data.Properties[2].Value = data.Properties[2].Value.(string) + "2"
if r.Vid != 0 {
ru, err := c.Contacts().CreateOrUpdate(data.Properties[0].Value.(string), data)
if err != nil {
t.Fatal(err)
}
if ru.ErrorResponse.Status == "error" {
t.Fatal(r.ErrorResponse.Message)
}
}
// Get contact
contact, err := c.Contacts().Get(r.Vid)
if err != nil {
t.Fatal(err)
}
if r.ErrorResponse.Status == "error" {
t.Fatal(r.ErrorResponse.Message)
}
// Get by email
contact, err = c.Contacts().GetByEmail(data.Properties[0].Value.(string))
if err != nil {
t.Fatal(err)
}
if r.ErrorResponse.Status == "error" {
t.Fatal(r.ErrorResponse.Message)
}
// Delete
err = c.Contacts().Delete(contact.Vid)
if err != nil {
t.Fatal(err)
}
//t.Logf("%+v", r)
//t.Logf("%+v", contact)
}