-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_object_methods_test.go
177 lines (164 loc) · 4.88 KB
/
client_object_methods_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
package sfdc_test
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.stellar.af/go-sfdc"
"go.stellar.af/go-utils/random"
)
func Test_Account(t *testing.T) {
t.Run("get account", func(t *testing.T) {
t.Parallel()
account, err := Client.Account(Env.TestData.AccountID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.AccountID, account.ID)
})
t.Run("get account custom field", func(t *testing.T) {
t.Parallel()
account, err := Client.Account(Env.TestData.AccountID)
require.NoError(t, err)
cfvalue := account.CustomFields[Env.TestData.AccountCustomFieldKey]
assert.NotEmpty(t, cfvalue)
})
}
func Test_Lead(t *testing.T) {
now := time.Now().Format(time.RFC3339Nano)
t.Run("get", func(t *testing.T) {
t.Parallel()
lead, err := Client.Lead(Env.TestData.LeadID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.LeadID, lead.ID)
})
t.Run("create", func(t *testing.T) {
lead := &sfdc.Lead{
LastName: fmt.Sprintf("%s--%s", t.Name(), now),
Company: Env.TestData.AccountName,
Email: Env.TestData.UserEmail,
}
res, err := Client.CreateLead(lead)
require.NoError(t, err)
assert.True(t, res.Success, "non-success")
t.Cleanup(func() {
err := Client.DeleteLead(res.ID)
assert.NoError(t, err)
})
})
}
func Test_User(t *testing.T) {
t.Run("get user", func(t *testing.T) {
t.Parallel()
user, err := Client.User(Env.TestData.UserID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.UserID, user.ID)
})
}
func Test_Group(t *testing.T) {
t.Run("get group", func(t *testing.T) {
t.Parallel()
group, err := Client.Group(Env.TestData.GroupID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.GroupID, group.ID)
})
}
func Test_Case(t *testing.T) {
t.Run("get case", func(t *testing.T) {
t.Parallel()
_case, err := Client.Case(Env.TestData.CaseID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.CaseID, _case.ID)
})
}
func Test_ServiceContract(t *testing.T) {
t.Run("get service contract", func(t *testing.T) {
t.Parallel()
contract, err := Client.ServiceContract(Env.TestData.ServiceContractID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.ServiceContractID, contract.ID)
})
}
func Test_Contact(t *testing.T) {
t.Run("get contact", func(t *testing.T) {
t.Parallel()
contact, err := Client.Contact(Env.TestData.ContactID)
require.NoError(t, err)
assert.Equal(t, Env.TestData.ContactID, contact.ID)
})
}
func Test_CreateCase(t *testing.T) {
t.Run("create and cancel case", func(t *testing.T) {
t.Parallel()
subject := createCaseSubject(t)
caseData := &sfdc.CaseCreate{
AccountID: Env.TestData.AccountID,
Comments: "go-sfdc unit test case",
ContactID: Env.TestData.ContactID,
Description: subject,
Origin: "Web",
Status: "New",
Subject: subject,
}
result, err := Client.CreateCase(caseData)
require.NoError(t, err)
assert.True(t, result.Success)
err = Client.UpdateCase(result.ID, &sfdc.CaseUpdate{Status: "Canceled"})
require.NoError(t, err)
})
t.Run("create a case with custom fields", func(t *testing.T) {
t.Parallel()
subject := createCaseSubject(t)
caseData := &sfdc.CaseCreate{
AccountID: Env.TestData.AccountID,
Comments: "go-sfdc unit test case",
ContactID: Env.TestData.ContactID,
Description: subject,
Origin: "Web",
Status: "New",
Subject: subject,
}
customFieldValue, err := random.String(16)
require.NoError(t, err)
customFields := sfdc.CustomFields{Env.TestData.CaseCustomFieldKey: customFieldValue}
result, err := Client.CreateCase(caseData, customFields)
require.NoError(t, err)
assert.True(t, result.Success)
_case, err := Client.Case(result.ID)
require.NoError(t, err)
assert.Equal(t, customFieldValue, _case.CustomFields[Env.TestData.CaseCustomFieldKey])
err = Client.UpdateCase(result.ID, &sfdc.CaseUpdate{Status: "Canceled"})
require.NoError(t, err)
})
}
func Test_CreateFeedItem(t *testing.T) {
subject := createCaseSubject(t)
caseData := &sfdc.CaseCreate{
AccountID: Env.TestData.AccountID,
Comments: "go-sfdc unit test case",
ContactID: Env.TestData.ContactID,
Description: subject,
Origin: "Web",
Status: "New",
Subject: subject,
}
newCase, _ := Client.CreateCase(caseData)
t.Run("base", func(t *testing.T) {
t.Parallel()
req := &sfdc.FeedItemOptions{
Body: fmt.Sprintf("test at %s", time.Now().Format(time.RFC3339Nano)),
ParentID: newCase.ID,
Type: "TextPost",
Title: fmt.Sprintf("Title: %s", subject),
}
result, err := Client.CreateFeedItem(req)
require.NoError(t, err)
assert.True(t, result.Success)
feedItem, err := Client.FeedItem(result.ID)
require.NoError(t, err)
assert.Equal(t, req.Body, feedItem.Body)
assert.Equal(t, req.Title, req.Title)
})
t.Cleanup(func() {
Client.UpdateCase(newCase.ID, &sfdc.CaseUpdate{Status: "Canceled"})
})
}