-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_bulk_methods_test.go
134 lines (122 loc) · 3.42 KB
/
client_bulk_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
package sfdc_test
import (
"fmt"
"testing"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.stellar.af/go-sfdc"
)
func GetObject[R any](maxTime time.Duration, getter func() (*R, error)) (*R, error) {
bo := backoff.NewExponentialBackOff(backoff.WithMaxElapsedTime(maxTime))
backoffFn := func() (*R, error) {
res, err := getter()
if err != nil {
return nil, err
}
return res, nil
}
return backoff.RetryWithData(backoffFn, bo)
}
func TestClient_SendFeedItem(t *testing.T) {
subj := createCaseSubject(t)
newCase, err := Client.CreateCase(&sfdc.CaseCreate{
AccountID: Env.TestData.AccountID,
ContactID: Env.TestData.ContactID,
Subject: subj,
Status: "New",
})
require.NoError(t, err, "failed to create case")
title := subj + "--feed-item"
_, err = Client.SendFeedItem(&sfdc.FeedItemOptions{
CreatedByID: Env.TestData.UserID,
Title: title,
Body: "bulk api test",
ParentID: newCase.ID,
})
require.NoError(t, err, "failed to send feed item")
q := sfdc.SOQL().
Select("Id").
From("FeedItem").
Where("ParentId", sfdc.EQUALS, newCase.ID).
Where("Title", sfdc.EQUALS, title)
soql := sfdc.NewSOQL[sfdc.ObjectID](Client)
res, err := GetObject(60*time.Second, func() (*sfdc.RecordResponse[sfdc.ObjectID], error) {
res, err := soql.Query(q)
if err != nil {
return nil, err
}
if res.TotalSize == 0 {
return nil, fmt.Errorf("feed item not created yet")
}
return &res, nil
})
require.NoError(t, err, "failed to retrieve feed item")
assert.Len(t, res.Records, 1)
t.Cleanup(func() {
err := Client.UpdateCase(newCase.ID, &sfdc.CaseUpdate{Status: "Canceled"})
require.NoError(t, err)
})
}
func TestClient_SendCaseUpdate(t *testing.T) {
subj := createCaseSubject(t)
case1, err := Client.CreateCase(&sfdc.CaseCreate{
AccountID: Env.TestData.AccountID,
ContactID: Env.TestData.ContactID,
Subject: subj,
Status: "New",
Description: "1",
})
require.NoError(t, err, "failed to create case")
_, err = Client.SendCaseUpdate(case1.ID, &sfdc.Case{
Description: "2",
})
require.NoError(t, err, "failed to update case")
case2, err := GetObject(60*time.Second, func() (*sfdc.Case, error) {
res, err := Client.Case(case1.ID)
if err != nil {
return nil, err
}
if res.Description != "2" {
return nil, fmt.Errorf("not updated yet")
}
return res, nil
})
require.NoError(t, err)
assert.Equal(t, "2", case2.Description)
t.Cleanup(func() {
err := Client.UpdateCase(case1.ID, &sfdc.CaseUpdate{Status: "Canceled"})
require.NoError(t, err)
})
}
func TestClient_SendCloseCase(t *testing.T) {
subj := createCaseSubject(t)
case1, err := Client.CreateCase(&sfdc.CaseCreate{
AccountID: Env.TestData.AccountID,
ContactID: Env.TestData.ContactID,
Subject: subj,
Status: "New",
})
require.NoError(t, err, "failed to create case")
err = Client.SendCloseCase(case1.ID)
require.NoError(t, err, "failed to close case")
case2, err := GetObject(60*time.Second, func() (*sfdc.Case, error) {
res, err := Client.Case(case1.ID)
if err != nil {
return nil, err
}
if res.Status != "Closed" {
return nil, fmt.Errorf("not closed yet")
}
return res, nil
})
require.NoError(t, err)
assert.Equal(t, "Closed", case2.Status)
t.Cleanup(func() {
if case2.Status != "Closed" {
err := Client.UpdateCase(case1.ID, &sfdc.CaseUpdate{Status: "Canceled"})
require.NoError(t, err)
}
})
}