-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_soql_test.go
166 lines (160 loc) · 6.05 KB
/
client_soql_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
package sfdc_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.stellar.af/go-sfdc"
)
func Test_SOQL(t *testing.T) {
t.Parallel()
t.Run("where equals", func(t *testing.T) {
t.Parallel()
expected := "SELECT Id FROM Case WHERE IsClosed = false LIMIT 10"
s, err := sfdc.SOQL().Select("Id").From("Case").Where("IsClosed", sfdc.EQUALS, false).Limit(10).String()
require.NoError(t, err)
assert.Equal(t, expected, s)
})
t.Run("where multiple", func(t *testing.T) {
t.Parallel()
expected := fmt.Sprintf("SELECT Id FROM Case WHERE IsClosed = false AND AccountId = '%s'", Env.TestData.AccountID)
s, err := sfdc.SOQL().Select("Id").From("Case").Where("IsClosed", sfdc.EQUALS, false).Where("AccountId", "=", Env.TestData.AccountID).String()
require.NoError(t, err)
assert.Equal(t, expected, s)
})
t.Run("where contains", func(t *testing.T) {
t.Parallel()
expected := `SELECT Id FROM Case WHERE Description LIKE '%a%'`
s, err := sfdc.SOQL().Select("Id").From("Case").Where("Description", sfdc.CONTAINS, "a").String()
require.NoError(t, err)
assert.Equal(t, expected, s)
})
t.Run("where contains query", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.CONTAINS, " ").Limit(1)
sc := sfdc.NewSOQL[sfdc.OpenCase](Client)
results, err := sc.Query(q)
require.NoError(t, err)
assert.Equal(t, 1, results.TotalSize)
})
t.Run("where starts with query", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.STARTS_WITH, "go").Limit(1)
sc := sfdc.NewSOQL[sfdc.OpenCase](Client)
results, err := sc.Query(q)
require.NoError(t, err)
assert.Equal(t, 1, results.TotalSize)
})
t.Run("where ends with query", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.ENDS_WITH, "0").Limit(1)
sc := sfdc.NewSOQL[sfdc.OpenCase](Client)
results, err := sc.Query(q)
require.NoError(t, err)
assert.Equal(t, 1, results.TotalSize)
})
t.Run("where in", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.IN, []string{"One", "Two"})
expected := `SELECT Id FROM Case WHERE Subject IN ('One','Two')`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where not in", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.NOT_IN, []string{"One", "Two"})
expected := `SELECT Id FROM Case WHERE Subject NOT IN ('One','Two')`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where not equals", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.NOT_EQUALS, "One")
expected := `SELECT Id FROM Case WHERE Subject != 'One'`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where greater than", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.GREATER_THAN, 1)
expected := `SELECT Id FROM Case WHERE Subject > 1`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where less than", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.LESS_THAN, 1)
expected := `SELECT Id FROM Case WHERE Subject < 1`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where gequal", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.GEQUAL, 1)
expected := `SELECT Id FROM Case WHERE Subject >= 1`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where lequal", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.LEQUAL, 1)
expected := `SELECT Id FROM Case WHERE Subject <= 1`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where includes", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.INCLUDES, "One")
expected := `SELECT Id FROM Case WHERE Subject INCLUDES 'One'`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("where excludes", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.EXCLUDES, "One")
expected := `SELECT Id FROM Case WHERE Subject EXCLUDES 'One'`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("sort", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.INCLUDES, "One").Sort("Id")
expected := `SELECT Id FROM Case WHERE Subject INCLUDES 'One' ORDER BY Id ASC NULLS FIRST`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("sort ascending", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.INCLUDES, "One").Sort("Id").Ascending()
expected := `SELECT Id FROM Case WHERE Subject INCLUDES 'One' ORDER BY Id ASC NULLS FIRST`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("sort descending", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.INCLUDES, "One").Sort("Id").Descending()
expected := `SELECT Id FROM Case WHERE Subject INCLUDES 'One' ORDER BY Id DESC NULLS FIRST`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
t.Run("sort ascending nulls last", func(t *testing.T) {
t.Parallel()
q := sfdc.SOQL().Select("Id").From("Case").Where("Subject", sfdc.INCLUDES, "One").Sort("Id").NullsLast()
expected := `SELECT Id FROM Case WHERE Subject INCLUDES 'One' ORDER BY Id ASC NULLS LAST`
result, err := q.String()
require.NoError(t, err)
assert.Equal(t, expected, result)
})
}