Return user on create user
This commit is contained in:
parent
08dbacd71b
commit
8ad22b1280
|
|
@ -59,6 +59,7 @@ func (a *UserAPI) CreateUser(ctx *gin.Context) {
|
||||||
internal := toInternal(&user, []byte{})
|
internal := toInternal(&user, []byte{})
|
||||||
if a.DB.GetUserByName(internal.Name) == nil {
|
if a.DB.GetUserByName(internal.Name) == nil {
|
||||||
a.DB.CreateUser(internal)
|
a.DB.CreateUser(internal)
|
||||||
|
ctx.JSON(200, toExternal(internal))
|
||||||
} else {
|
} else {
|
||||||
ctx.AbortWithError(400, errors.New("username already exists"))
|
ctx.AbortWithError(400, errors.New("username already exists"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,8 @@ func (s *UserSuite) Test_CreateUser() {
|
||||||
s.a.CreateUser(s.ctx)
|
s.a.CreateUser(s.ctx)
|
||||||
|
|
||||||
s.db.AssertCalled(s.T(), "CreateUser", &model.User{Name: "tom", Pass: pwByte, Admin: true})
|
s.db.AssertCalled(s.T(), "CreateUser", &model.User{Name: "tom", Pass: pwByte, Admin: true})
|
||||||
|
|
||||||
|
s.expectJSON(`{"id":0, "name":"tom", "admin":true}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserSuite) Test_CreateUser_NoPassword() {
|
func (s *UserSuite) Test_CreateUser_NoPassword() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue