Skip to content

Commit

Permalink
fix(api) fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helderbetiol committed Jun 14, 2024
1 parent 2c73718 commit 455ba00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion API/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func getModifyPassDataFromBody(r *http.Request, userEmail string) (string, strin
var data map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&data)
if err != nil {
return currentPassword, "", isReset, err
return currentPassword, "", isReset, fmt.Errorf("invalid request")
}
if userEmail == u.RESET_TAG {
// it's not change, it's reset (no need for current password)
Expand Down
10 changes: 5 additions & 5 deletions API/controllers/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestModifyRole(t *testing.T) {
statusCode int
message string
}{
{"ExtraDataReturnsError", e2e.ValidateRequestWithToken, userToken, userId, `{"roles": {"*": "user"},"name": "other name"}`, http.StatusBadRequest, "Only 'roles' should be provided to patch"},
{"ExtraDataReturnsError", e2e.ValidateRequestWithToken, userToken, userId, `{"roles": {"*": "user"},"name": "other name"}`, http.StatusBadRequest, "only 'roles' should be provided to patch"},
{"InvalidRole", e2e.ValidateRequestWithToken, userToken, userId, `{"roles": {"*": "invalid"}}`, http.StatusInternalServerError, "Role assigned is not valid: "},
{"InvalidId", e2e.ValidateRequestWithToken, userToken, "invalid", `{"roles": {"*": "user"}}`, http.StatusBadRequest, "User ID is not valid"},
{"ModifyRoleWithNormalUser", e2e.ValidateRequestWithUser, "user", userId, `{"roles": {"*": "manager"}}`, http.StatusUnauthorized, "Caller does not have permission to modify this user"},
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestModifyPassword(t *testing.T) {
statusCode int
message string
}{
{"NotEnoughArguments", `{"newPassword": "fake_password"}`, http.StatusBadRequest, "Invalid request: wrong body format"},
{"NotEnoughArguments", `{"newPassword": "fake_password"}`, http.StatusBadRequest, "invalid request: wrong body format"},
{"Success", correctRequestBody, http.StatusOK, "successfully updated user password"},
}

Expand All @@ -234,7 +234,7 @@ func TestResetPassword(t *testing.T) {
message string
}{
{"InvalidResetToken", test_utils.GetUserToken(email, password), correctRequestBody, http.StatusForbidden, "Token is not valid."}, // User token is not a reset token
{"NotEnoughArguments", models.GenerateToken(u.RESET_TAG, userId, time.Minute), `{}`, http.StatusBadRequest, "Invalid request: wrong body format"},
{"NotEnoughArguments", models.GenerateToken(u.RESET_TAG, userId, time.Minute), `{}`, http.StatusBadRequest, "invalid request: wrong body format"},
{"Success", models.GenerateToken(u.RESET_TAG, userId, time.Minute), correctRequestBody, http.StatusOK, "successfully updated user password"},
}

Expand All @@ -260,8 +260,8 @@ func TestRequestsWithInvalidBody(t *testing.T) {
{"CreateUser", "POST", test_utils.GetEndpoint("users"), "Invalid request: wrong format body"},
{"CreateBulkUsers", "POST", test_utils.GetEndpoint("usersBulk"), "Invalid request"},
{"Login", "POST", test_utils.GetEndpoint("login"), "Invalid request"},
{"ModifyUser", "PATCH", test_utils.GetEndpoint("usersInstance", userId), "Invalid request"},
{"ModifyPassword", "POST", test_utils.GetEndpoint("changePassword"), "Invalid request"},
{"ModifyUser", "PATCH", test_utils.GetEndpoint("usersInstance", userId), "invalid request"},
{"ModifyPassword", "POST", test_utils.GetEndpoint("changePassword"), "invalid request"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 455ba00

Please sign in to comment.