-
Notifications
You must be signed in to change notification settings - Fork 2
/
builder_test.go
53 lines (50 loc) · 972 Bytes
/
builder_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
package myjson
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestQueryBuilder(t *testing.T) {
t.Run("query builder 1", func(t *testing.T) {
q := Q().
Select(Select{
Field: "account_id",
}).
Where(Where{
Field: "age",
Op: ">",
Value: 50,
}).
Join(Join{
Collection: "account",
On: []Where{
{
Field: "_id",
Op: "eq",
Value: "id",
},
},
As: "a",
}).
GroupBy("account_id").
OrderBy(OrderBy{
Field: "account_id",
Direction: OrderByDirectionDesc,
}).
Having(Where{
Field: "account_id",
Op: ">",
Value: "50",
}).
Limit(1).
Page(1).
Query()
assert.Equal(t, 1, len(q.Select))
assert.Equal(t, 1, len(q.Where))
assert.Equal(t, 1, len(q.GroupBy))
assert.Equal(t, 1, len(q.OrderBy))
assert.Equal(t, 1, q.Limit)
assert.Equal(t, 1, q.Page)
assert.Equal(t, 1, len(q.Having))
assert.Equal(t, 1, len(q.Join))
})
}