Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Wo-ogie committed Feb 2, 2024
2 parents 2a29c74 + bfa046d commit 9b50a37
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@RequiredArgsConstructor
Expand Down Expand Up @@ -80,7 +81,10 @@ public void rejoin(Long memberId) {
public MemberDto update(Long memberId, MemberUpdateRequest updateRequest) {
Member member = memberQueryService.getById(memberId);

validateNicknameDuplication(updateRequest.getNickname());
// 닉네임을 변경했다면, 변경하고자 하는 닉네임이 이미 사용중이지 않은지 확인
if (!Objects.equals(member.getNickname(), updateRequest.getNickname())) {
validateNicknameDuplication(updateRequest.getNickname());
}

MultipartFile profileImageForUpdate = updateRequest.getProfileImage();
if (profileImageForUpdate == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ void givenMemberUpdateInfo_whenUpdatingMemberInfo_thenUpdate() {
assertThat(updatedMemberDto.getGender()).isEqualTo(memberUpdateInfo.getGender());
}

@DisplayName("수정할 회원 정보가 주어지고, 회원 정보를 수정하면, 주어진 정보로 회원 정보가 수정된다. 이때, 닉네임이 변경되지 않았다면 닉네임 중복 확인 과정은 거치지 않는다.")
@Test
void givenMemberInfoToUpdate_whenUpdateMemberInfo_thenMemberInfoShouldBeUpdatedWithoutNicknameDuplicationCheckIfNicknameNotChanged() {
// given
long memberId = 1L;
String nickname = "nickname";
Member member = createMember(memberId, nickname);
MemberUpdateRequest memberUpdateInfo = new MemberUpdateRequest(nickname, LocalDate.of(2020, 1, 1), Gender.ETC, createMockMultipartFile());
ProfileImage oldProfileImage = createProfileImage(member, 2L);
given(memberQueryService.getById(memberId)).willReturn(member);
given(profileImageQueryService.findByMember(member)).willReturn(Optional.of(oldProfileImage));
willDoNothing().given(profileImageCommandService).softDelete(oldProfileImage);
given(profileImageCommandService.upload(any(Member.class), eq(memberUpdateInfo.getProfileImage()))).willReturn(createProfileImage(member, 10L));

// when
MemberDto updatedMemberDto = sut.update(memberId, memberUpdateInfo);

// then
then(memberQueryService).should().getById(memberId);
then(profileImageQueryService).should().findByMember(member);
then(profileImageCommandService).should().softDelete(oldProfileImage);
then(profileImageCommandService).should().upload(any(Member.class), eq(memberUpdateInfo.getProfileImage()));
verifyEveryMocksShouldHaveNoMoreInteractions();
assertThat(updatedMemberDto.getNickname()).isEqualTo(memberUpdateInfo.getNickname());
assertThat(updatedMemberDto.getBirthDay()).isEqualTo(memberUpdateInfo.getBirthDay());
assertThat(updatedMemberDto.getGender()).isEqualTo(memberUpdateInfo.getGender());
}

@DisplayName("수정할 회원 정보 중 이미 사용중인 닉네임이 주어지고, 회원 정보를 수정하면, 예외가 발생한다.")
@Test
void givenNicknameThatAlreadyExists_whenUpdatingMemberInfo_thenThrowNicknameDuplicationException() {
Expand Down Expand Up @@ -256,10 +284,14 @@ private Member createDeletedMember(long memberId) {
}

private Member createMember(long memberId) {
return createMember(memberId, Set.of(RoleType.USER));
return createMember(memberId, "nickname", Set.of(RoleType.USER));
}

private Member createMember(long memberId, Set<RoleType> roleTypes) {
private Member createMember(long memberId, String nickname) {
return createMember(memberId, nickname, Set.of(RoleType.USER));
}

private Member createMember(long memberId, String nickname, Set<RoleType> roleTypes) {
return new Member(
memberId,
"profile image url",
Expand All @@ -268,7 +300,7 @@ private Member createMember(long memberId, Set<RoleType> roleTypes) {
LoginType.KAKAO,
roleTypes,
"email",
"nickname",
nickname,
LocalDate.of(2000, 1, 1),
20,
Gender.MALE,
Expand Down

0 comments on commit 9b50a37

Please sign in to comment.