Skip to content

Commit

Permalink
tests(router): add admin tests
Browse files Browse the repository at this point in the history
* add admin tests
* split tests in multiple files for better maintainability.

Closes: #71
  • Loading branch information
Stefan Jacobi committed Jun 20, 2024
1 parent 12d81e7 commit 3d2280e
Show file tree
Hide file tree
Showing 26 changed files with 4,717 additions and 2,427 deletions.
19 changes: 13 additions & 6 deletions server/api/handler/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ func NewUserHandler(persister persistence.Persister) UserHandler {

func (uh *userHandler) List(ctx echo.Context) error {
var request adminRequest.UserListRequest
err := (&echo.DefaultBinder{}).BindQueryParams(ctx, &request)
err := ctx.Bind(&request)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "unable to parse request")
ctx.Logger().Error(err)
return echo.NewHTTPError(http.StatusBadRequest, "unable to list users").SetInternal(err)
}

err = ctx.Validate(&request)
if err != nil {
ctx.Logger().Error(err)
return echo.NewHTTPError(http.StatusBadRequest, "unable to list users").SetInternal(err)
}

if request.Page == 0 {
Expand Down Expand Up @@ -92,12 +99,12 @@ func (uh *userHandler) Get(ctx echo.Context) error {

userIdString := ctx.Param("user_id")
if userIdString == "" {
return echo.NewHTTPError(http.StatusBadRequest, "missing user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

userId, err := uuid.FromString(userIdString)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

return uh.persister.GetConnection().Transaction(func(tx *pop.Connection) error {
Expand Down Expand Up @@ -126,12 +133,12 @@ func (uh *userHandler) Remove(ctx echo.Context) error {

userIdString := ctx.Param("user_id")
if userIdString == "" {
return echo.NewHTTPError(http.StatusBadRequest, "missing user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

userId, err := uuid.FromString(userIdString)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid user_id")
return echo.NewHTTPError(http.StatusBadRequest, "user_id must be a valid uuid4")
}

return uh.persister.GetConnection().Transaction(func(tx *pop.Connection) error {
Expand Down
Loading

0 comments on commit 3d2280e

Please sign in to comment.