-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_internal_hook_test.go
68 lines (54 loc) · 1.87 KB
/
api_internal_hook_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
package cosy
import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/uozi-tech/cosy/model"
"testing"
)
func TestInternalGetHook(t *testing.T) {
model.RegisterModels(User{}, Product{})
model.ResolvedModels()
c := &gin.Context{}
expected := Core[Product](c).
SetPreloads("User")
actual := Core[Product](c)
getHook[Product]()(actual)
assert.Equal(t, expected, actual)
}
func TestInternalListHook(t *testing.T) {
model.RegisterModels(User{}, Product{})
model.ResolvedModels()
c := &gin.Context{}
expected := Core[User](c).
SetFussy("school_id", "title", "name", "gender", "college", "direction", "office_number", "email", "phone").
SetIn("status").
SetBetween("employed_at")
actual := Core[User](c)
getListHook[User]()(actual)
assert.Equal(t, expected.rules, actual.rules)
assert.Equal(t, expected.preloads, actual.preloads)
assert.Equal(t, expected.in, actual.in)
assert.Equal(t, expected.eq, actual.eq)
assert.Equal(t, expected.fussy, actual.fussy)
assert.Equal(t, expected.orIn, actual.orIn)
assert.Equal(t, expected.orEq, actual.orEq)
assert.Equal(t, expected.orFussy, actual.orFussy)
assert.Equal(t, expected.search, actual.search)
assert.Equal(t, expected.between, actual.between)
expected2 := Core[Product](c).
SetFussy("name", "description", "price").
SetEqual("user_id").
SetIn("status").
SetPreloads("Status", "User")
actual2 := Core[Product](c)
getListHook[Product]()(actual2)
assert.Equal(t, expected2.rules, actual2.rules)
assert.Equal(t, expected2.preloads, actual2.preloads)
assert.Equal(t, expected2.in, actual2.in)
assert.Equal(t, expected2.eq, actual2.eq)
assert.Equal(t, expected2.fussy, actual2.fussy)
assert.Equal(t, expected2.orIn, actual2.orIn)
assert.Equal(t, expected2.orEq, actual2.orEq)
assert.Equal(t, expected2.orFussy, actual2.orFussy)
assert.Equal(t, expected2.search, actual2.search)
}