-
Notifications
You must be signed in to change notification settings - Fork 6
/
crm_associations_test.go
83 lines (75 loc) · 1.62 KB
/
crm_associations_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
package hubspot
import "testing"
func TestCRMAssociations(t *testing.T) {
// Init client
c := NewClient(NewClientConfig())
// Create company
companyData := CompaniesRequest{
Properties: []Property{
Property{
Name: "name",
Value: "Test Company",
},
Property{
Name: "description",
Value: "Company description here...",
},
},
}
companyResp, err := c.Companies().Create(companyData)
if err != nil {
t.Error(err)
}
if companyResp.ErrorResponse.Status == "error" {
t.Error(companyResp.ErrorResponse.Message)
}
// Create contact
contactData := ContactsRequest{
Properties: []Property{
Property{
Property: "email",
Value: "crm_associations@example.com",
},
Property{
Property: "firstname",
Value: "CRM",
},
Property{
Property: "lastname",
Value: "Associations",
},
},
}
contactResp, err := c.Contacts().Create(contactData)
if err != nil {
t.Fatal(err)
}
if contactResp.ErrorResponse.Status == "error" {
t.Fatal(contactResp.ErrorResponse.Message)
}
// Create CRM association contact -> company
assocData := CRMAssociationsRequest{
FromObjectID: contactResp.Vid,
ToObjectID: companyResp.CompanyID,
DefinitionID: CRMAssociationContactToCompany,
}
err = c.CRMAssociations().Create(assocData)
if err != nil {
t.Fatal(err)
}
// Delete association
err = c.CRMAssociations().Delete(assocData)
if err != nil {
t.Fatal(err)
}
// Delete contact
err = c.Contacts().Delete(contactResp.Vid)
if err != nil {
t.Fatal(err)
}
// Delete Company
err = c.Companies().Delete(companyResp.CompanyID)
if err != nil {
t.Error(err)
}
}