Add unit tests for UpdateUserForm JSON unmarshalling
continuous-integration/drone/push Build is passing

- Introduced `form_test.go` to validate the behavior of the `UpdateUserForm` struct's JSON unmarshalling, specifically for the `profile_image` field.
- Added tests to ensure omitted `profile_image` is not treated as an update, null values clear the image, and valid URLs are preserved.
- Enhanced the `UpdateUserForm` and `UpdateProfileForm` structs to include logic for distinguishing between omitted and explicitly null profile images during JSON unmarshalling.

This update improves the robustness of user profile updates by ensuring correct handling of profile image data in JSON requests, enhancing overall data integrity in the user management system.
This commit is contained in:
Mazyar
2026-06-22 22:09:30 +03:30
parent d486a5e44f
commit ce8a18aa8b
3 changed files with 115 additions and 8 deletions
+2 -2
View File
@@ -204,7 +204,7 @@ func (s *userService) Update(ctx context.Context, id string, form *UpdateUserFor
user.Phone = form.Phone
}
if form.ProfileImage != nil {
if form.isProfileImageSet() {
user.ProfileImage = form.ProfileImage
}
@@ -601,7 +601,7 @@ func (s *userService) UpdateProfile(ctx context.Context, userID string, form *Up
}
user.Phone = form.Phone
}
if form.ProfileImage != nil {
if form.isProfileImageSet() {
user.ProfileImage = form.ProfileImage
}