Commit 7a6ebf0f authored by Simon Metzler's avatar Simon Metzler

usernameavailable 400 TG-81

parent 69a4ac18
......@@ -280,6 +280,12 @@ paths:
application/json:
schema:
type: boolean
'400':
description: Invalid request. The username is empty.
content:
application/json:
schema:
type: string
'500':
description: The server cannot deliver due to an internal error.
content:
......
......@@ -21,6 +21,11 @@ func isAvailable(repository user.UserQuery) gin.HandlerFunc {
return func(ctx *gin.Context) {
username := ctx.Query("username")
if username == "" {
ctx.String(http.StatusBadRequest, "Empty username is not allowed.")
return
}
_, err := repository.SelectByUsername(username)
if err != nil {
......
......@@ -58,5 +58,24 @@ func Test_isAvailable_200_false(t *testing.T) {
}
// Currently unimplemented functionality
//func Test_isAvailable_400
func Test_isAvailable_400(t *testing.T) {
router := setup.SetupRoutes(nil, nil, nil, nil, nil, &mockUser{}, nil, nil, nil)
env := new(testEnv)
env.router = router
// Test with empty username
res := httptest.NewRecorder()
req, _ := env.newParameterRequest(
"GET",
"/usernameavailable",
map[string]string{
"username": "",
},
nil)
router.ServeHTTP(res, req)
assert.Equal(t, 400, res.Code)
assert.Equal(t, "Empty username is not allowed.", res.Body.String())
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment