-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_superadmin_test.go
46 lines (37 loc) · 1.36 KB
/
server_superadmin_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
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_AddSuperadmin(t *testing.T) {
stage, _ := playground.NewPlaygroundWithSqlitePath(t.TempDir())
service := stage.Service
user1 := &example.User{ID: 999, Email: "[email protected]"}
assert.Equal(t, caskin.ErrNotExists, service.AddSuperadmin(user1))
user1.ID = stage.Member.ID
assert.Error(t, service.AddSuperadmin(user1))
assert.NoError(t, service.AddSuperadmin(stage.Member))
list1, err := service.GetSuperadmin()
assert.NoError(t, err)
assert.Len(t, list1, 2)
}
func TestServer_DeleteSuperadmin(t *testing.T) {
stage, _ := playground.NewPlaygroundWithSqlitePath(t.TempDir())
service := stage.Service
user1 := &example.User{Email: "[email protected]"}
assert.Equal(t, caskin.ErrEmptyID, service.DeleteSuperadmin(user1))
user1.ID = stage.Member.ID
assert.Error(t, service.DeleteSuperadmin(user1))
// delete a no superadmin user, it will not return error
assert.NoError(t, service.DeleteSuperadmin(stage.Member))
list1, err := service.GetSuperadmin()
assert.NoError(t, err)
assert.Len(t, list1, 1)
assert.NoError(t, service.DeleteSuperadmin(stage.Superadmin))
list2, err := service.GetSuperadmin()
assert.NoError(t, err)
assert.Len(t, list2, 0)
}