-
Notifications
You must be signed in to change notification settings - Fork 163
/
model_test.go
58 lines (46 loc) · 970 Bytes
/
model_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
package gorsk_test
import (
"context"
"testing"
"github.com/ribice/gorsk"
"github.com/ribice/gorsk/pkg/utl/mock"
)
func TestBeforeInsert(t *testing.T) {
base := &gorsk.Base{
ID: 1,
}
base.BeforeInsert(context.TODO())
if base.CreatedAt.IsZero() {
t.Error("CreatedAt was not changed")
}
if base.UpdatedAt.IsZero() {
t.Error("UpdatedAt was not changed")
}
}
func TestBeforeUpdate(t *testing.T) {
base := &gorsk.Base{
ID: 1,
CreatedAt: mock.TestTime(2000),
}
base.BeforeUpdate(context.TODO())
if base.UpdatedAt == mock.TestTime(2001) {
t.Error("UpdatedAt was not changed")
}
}
func TestPaginationTransform(t *testing.T) {
p := &gorsk.PaginationReq{
Limit: 5000, Page: 5,
}
pag := p.Transform()
if pag.Limit != 1000 {
t.Error("Default limit not set")
}
if pag.Offset != 5000 {
t.Error("Offset not set correctly")
}
p.Limit = 0
newPag := p.Transform()
if newPag.Limit != 100 {
t.Error("Min limit not set")
}
}