-
Notifications
You must be signed in to change notification settings - Fork 28
/
crm_imports_test.go
107 lines (98 loc) · 2.63 KB
/
crm_imports_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
package hubspot
import (
"bytes"
"encoding/csv"
"fmt"
"os"
"testing"
)
func TestGetActiveImports(t *testing.T) {
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Imports.Active(&CrmActiveImportOptions{
Before: "",
After: "",
Offset: 0,
})
fmt.Printf("%+v\n", res)
fmt.Printf("%+v\n", err)
}
func TestGetImportById(t *testing.T) {
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Imports.Get(32331356)
fmt.Printf("%+v\n", res)
fmt.Printf("%+v\n", err)
}
func TestCancelImportById(t *testing.T) {
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Imports.Cancel(32331339)
fmt.Printf("%+v\n", res)
fmt.Printf("%+v\n", err)
}
func TestImportErrorsById(t *testing.T) {
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Imports.Errors(12342, &CrmImportErrorsOptions{
After: "abcd",
Limit: 1234,
})
fmt.Printf("%+v\n", res)
fmt.Printf("%+v\n", err)
}
func createTestCsv(count int) *bytes.Buffer {
buf := &bytes.Buffer{}
csvwriter := csv.NewWriter(buf)
csvHeader := []string{"email", "firstname", "lastname"}
_ = csvwriter.Write(csvHeader)
for i := 0; i < count; i++ {
testFirst := fmt.Sprintf("FirstName3%d", i)
testLast := fmt.Sprintf("LastName%d", i)
testEmail := fmt.Sprintf("test%[email protected]", i)
_ = csvwriter.Write([]string{testEmail, testFirst, testLast})
}
csvwriter.Flush()
return buf
}
func createTestMetadataConfig() *CrmImportConfig {
result := &CrmImportConfig{
Name: "Example Create Import",
ImportOperations: map[string]string{
"0-1": "CREATE",
},
Files: []CrmImportFileConfig{
{
FileName: "example.csv",
FileFormat: "CSV",
DateFormat: "DAY_MONTH_YEAR",
Data: createTestCsv(6),
FileImportPage: CrmImportFilePageConfig{
HasHeader: true,
ColumnMappings: []CrmImportColumnMapping{
{
ColumnObjectTypeId: "0-1",
ColumnName: "email",
PropertyName: "email",
IdColumnType: "HUBSPOT_ALTERNATE_ID",
},
{
ColumnObjectTypeId: "0-1",
ColumnName: "firstname",
PropertyName: "firstname",
},
{
ColumnObjectTypeId: "0-1",
ColumnName: "lastname",
PropertyName: "lastname",
},
},
},
},
},
}
return result
}
func TestImportStart(t *testing.T) {
cli, _ := NewClient(SetPrivateAppToken(os.Getenv("PRIVATE_APP_TOKEN")))
res, err := cli.CRM.Imports.Start(createTestMetadataConfig())
fmt.Printf("%+v\n", res)
fmt.Printf("%+v\n", err)
// t.Error(1)
}