Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

사용자 정보 수정 시 이름만 수정한다면 이미지는 null 전달되는 요청 처리 #401

Merged
merged 7 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ public ReadUserDto readById(final Long userId) {
public ReadUserDto updateById(final Long userId, final UpdateUserDto userDto) {
final User user = userRepository.findByIdAndDeletedIsFalse(userId)
.orElseThrow(() -> new UserNotFoundException("사용자 정보를 사용할 수 없습니다."));
final StoreImageDto storeImageDto = imageProcessor.storeImageFile(userDto.profileImage());

user.update(userDto.name(), storeImageDto.toProfileImageEntity());
if (userDto.profileImage() != null) {
final StoreImageDto storeImageDto = imageProcessor.storeImageFile(userDto.profileImage());
user.updateProfileImage(storeImageDto.toProfileImageEntity());
}
user.updateName(userDto.name());


return ReadUserDto.from(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ private User(
this.oauthId = oauthId;
}

public void update(final String name, final ProfileImage profileProfileImage) {
public void updateName(final String name) {
this.name = name;
}

public void updateProfileImage(final ProfileImage profileProfileImage) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profileProfileImage?!가 되어버렸네요!

this.profileImage = profileProfileImage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ class UserServiceTest {
});
}

@Test
void 사용자_정보를_수정시_이름만_수정한다() {
// given
final User user = User.builder()
.name("사용자")
.profileImage(new ProfileImage("upload.png", "store.png"))
.reliability(4.7d)
.oauthId("12345")
.build();

userRepository.save(user);

final UpdateUserDto updateUserDto = new UpdateUserDto("updateName", null);

// when
userService.updateById(user.getId(), updateUserDto);

// then
SoftAssertions.assertSoftly(softAssertions -> {
softAssertions.assertThat(user.getName()).isEqualTo("updateName");
softAssertions.assertThat(user.getProfileImage().getImage().getStoreName()).isEqualTo("store.png");
softAssertions.assertThat(user.getReliability()).isEqualTo(4.7d);
softAssertions.assertThat(user.getOauthId()).isEqualTo("12345");
});
}

@Test
void 사용자_정보_수정시_존재하지_않는_사용자라면_예외가_발생한다() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class UserTest {

@Test
void 회원_정보를_수정한다() {
void 회원_정보의_이름을_수정한다() {
// given
final User user = User.builder()
.name("kakao12345")
Expand All @@ -22,12 +22,32 @@ class UserTest {
.build();

// when
user.update("newName", new ProfileImage("newUpload.png", "newStore.png"));
user.updateName("newName");

// then
SoftAssertions.assertSoftly(softAssertions -> {
softAssertions.assertThat(user.getName()).isEqualTo("newName");
softAssertions.assertThat(user.getProfileImage()).isEqualTo(new ProfileImage("newUpload.png", "newStore.png"));
softAssertions.assertThat(user.getProfileImage()).isEqualTo(new ProfileImage("upload.png", "store.png"));
softAssertions.assertThat(user.getReliability()).isEqualTo(5.0d);
});
}

@Test
void 회원_정보의_이미지를_수정한다() {
// given
final User user = User.builder()
.name("kakao12345")
.profileImage(new ProfileImage("upload.png", "store.png"))
.reliability(5.0d)
.build();

// when
user.updateProfileImage(new ProfileImage("updateUpload.png", "updateStore.png"));

// then
SoftAssertions.assertSoftly(softAssertions -> {
softAssertions.assertThat(user.getName()).isEqualTo("kakao12345");
softAssertions.assertThat(user.getProfileImage()).isEqualTo(new ProfileImage("updateUpload.png", "updateStore.png"));
softAssertions.assertThat(user.getReliability()).isEqualTo(5.0d);
});
}
Expand Down
Loading