-
Notifications
You must be signed in to change notification settings - Fork 28
/
crm_schemas_test.go
192 lines (174 loc) · 3.67 KB
/
crm_schemas_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package hubspot
import (
"encoding/json"
"os"
"testing"
)
func TestGetSchemas(t *testing.T) {
t.SkipNow()
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Schemas.List()
if err != nil {
t.Error(err)
}
if len(res.Results) < 1 {
t.Errorf("expected results to have some results")
}
}
func TestCreateSchema(t *testing.T) {
t.SkipNow()
// this example is from Hubspot..
var exampleJson string = `
{
"name": "cars",
"labels": {
"singular": "Car",
"plural": "Cars"
},
"primaryDisplayProperty": "model",
"secondaryDisplayProperties": [
"make"
],
"searchableProperties": [
"year",
"make",
"vin",
"model"
],
"requiredProperties": [
"year",
"make",
"vin",
"model"
],
"properties": [
{
"name": "condition",
"label": "Condition",
"type": "enumeration",
"fieldType": "select",
"options": [
{
"label": "New",
"value": "new"
},
{
"label": "Used",
"value": "used"
}
]
},
{
"name": "date_received",
"label": "Date received",
"type": "date",
"fieldType": "date"
},
{
"name": "year",
"label": "Year",
"type": "number",
"fieldType": "number"
},
{
"name": "make",
"label": "Make",
"type": "string",
"fieldType": "text"
},
{
"name": "model",
"label": "Model",
"type": "string",
"fieldType": "text"
},
{
"name": "vin",
"label": "VIN",
"type": "string",
"hasUniqueValue": true,
"fieldType": "text"
},
{
"name": "price",
"label": "Price",
"type": "number",
"fieldType": "number"
},
{
"name": "notes",
"label": "Notes",
"type": "string",
"fieldType": "text"
}
],
"associatedObjects": [
"CONTACT"
]
}
`
req := make(map[string]interface{})
err := json.Unmarshal([]byte(exampleJson), &req)
if err != nil {
t.Error(err)
}
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Schemas.Create(req)
if err != nil {
t.Error(err)
}
if *res.Name != "cars" {
t.Errorf("expected post schema result to have an id field")
}
}
func TestGetSchema(t *testing.T) {
t.SkipNow()
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Schemas.Get("cars")
if err != nil {
t.Error(err)
}
if *res.Name != "cars" {
t.Errorf("expected post schema result to have an id field")
}
}
func TestDeleteSchema(t *testing.T) {
t.SkipNow()
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Schemas.Get("cars")
if err != nil {
t.Error(err)
}
err = cli.CRM.Schemas.Delete(string(*res.FullyQualifiedName), &RequestQueryOption{Archived: false})
if err != nil {
t.Error(err)
}
err = cli.CRM.Schemas.Delete(string(*res.FullyQualifiedName), &RequestQueryOption{Archived: true})
if err != nil {
t.Error(err)
}
}
func TestUpdateSchema(t *testing.T) {
t.SkipNow()
// Note: You need to wait some time after calling create before calling Update as it'll return an error message.
req := make(map[string]interface{})
req["primaryDisplayProperty"] = "year"
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Schemas.Get("cars")
if err != nil {
t.Error(err)
return
}
if *res.PrimaryDisplayProperty != "model" {
t.Error("expected primaryDisplayProperty to be model before update")
return
}
res, err = cli.CRM.Schemas.Update(string(*res.FullyQualifiedName), req)
if err != nil {
t.Error(err)
return
}
if *res.PrimaryDisplayProperty != "year" {
t.Errorf("expected primaryDisplayProperty to be year after update, got %s", res.PrimaryDisplayProperty)
}
}