-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_user_test.go
More file actions
74 lines (56 loc) · 2.22 KB
/
server_user_test.go
File metadata and controls
74 lines (56 loc) · 2.22 KB
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
package caskin_test
import (
"testing"
"github.com/awatercolorpen/caskin"
"github.com/awatercolorpen/caskin/example"
"github.com/awatercolorpen/caskin/playground"
"github.com/stretchr/testify/assert"
)
func TestServer_CreateUser(t *testing.T) {
stage, _ := playground.NewPlaygroundWithSqlitePath(t.TempDir())
service := stage.Service
user1 := &example.User{Email: "member2@qq.com"}
assert.NoError(t, service.CreateUser(user1))
user2 := &example.User{Email: "member2@qq.com"}
assert.Equal(t, caskin.ErrAlreadyExists, service.CreateUser(user2))
user3 := &example.User{Email: "member2@qq.com"}
assert.Equal(t, caskin.ErrEmptyID, service.DeleteUser(user3))
user3.ID = user2.ID
assert.NoError(t, service.DeleteUser(user3))
user4 := &example.User{ID: user2.ID + 1}
assert.Equal(t, caskin.ErrNotExists, service.DeleteUser(user4))
assert.NoError(t, service.CreateUser(user4))
}
func TestServer_UpdateUser(t *testing.T) {
stage, _ := playground.NewPlaygroundWithSqlitePath(t.TempDir())
service := stage.Service
user1 := &example.User{ID: stage.Member.ID, Email: "member2@qq.com"}
assert.NoError(t, service.UpdateUser(user1))
user2 := &example.User{}
assert.Equal(t, caskin.ErrEmptyID, service.UpdateUser(user2))
user3 := &example.User{ID: 999}
assert.Equal(t, caskin.ErrNotExists, service.UpdateUser(user3))
}
func TestServer_RecoverUser(t *testing.T) {
stage, _ := playground.NewPlaygroundWithSqlitePath(t.TempDir())
service := stage.Service
user1 := &example.User{}
assert.Equal(t, caskin.ErrAlreadyExists, service.RecoverUser(user1))
assert.NoError(t, service.DeleteUser(stage.Member))
user2 := &example.User{Email: stage.Member.Email}
assert.NoError(t, service.RecoverUser(user2))
user3 := &example.User{ID: 999}
assert.Equal(t, caskin.ErrNotExists, service.RecoverUser(user3))
}
func TestServer_DeleteUser(t *testing.T) {
stage, _ := playground.NewPlaygroundWithSqlitePath(t.TempDir())
service := stage.Service
assert.NoError(t, service.DeleteUser(stage.Superadmin))
list1, err := service.GetSuperadmin()
assert.NoError(t, err)
assert.Len(t, list1, 0)
assert.NoError(t, service.DeleteUser(stage.Member))
list2, err := service.GetUserRole(stage.Admin, stage.Domain)
assert.NoError(t, err)
assert.Len(t, list2, 1)
}