diff --git a/src/test/java/com/depromeet/domain/member/application/MemberServiceTest.java b/src/test/java/com/depromeet/domain/member/application/MemberServiceTest.java index ed2394c5d..8d5143b80 100644 --- a/src/test/java/com/depromeet/domain/member/application/MemberServiceTest.java +++ b/src/test/java/com/depromeet/domain/member/application/MemberServiceTest.java @@ -12,6 +12,7 @@ import com.depromeet.domain.member.domain.Member; import com.depromeet.domain.member.domain.OauthInfo; import com.depromeet.domain.member.domain.Profile; +import com.depromeet.domain.member.dto.request.NicknameUpdateRequest; import com.depromeet.domain.member.dto.response.MemberSearchResponse; import com.depromeet.domain.member.dto.response.MemberSocialInfoResponse; import com.depromeet.global.error.exception.CustomException; @@ -255,4 +256,45 @@ void setUp() { assertEquals(FollowStatus.FOLLOWED_BY_ME, responses.get(2).followStatus()); } } + + @Nested + class 닉네임을_변경할떄 { + @Test + void 다른_유저와_닉네임이_중복되면_예외가_발생한다() { + // given + OauthInfo oauthInfo = + OauthInfo.createOauthInfo("testOauthId", "testOauthProvider", "testEmail"); + saveAndRegisterMember(oauthInfo); + + Member anotherMember = + Member.createNormalMember( + OauthInfo.createOauthInfo( + "testOauthId2", "testOauthProvider2", "testEmail2"), + "testNickname2"); + memberRepository.save(anotherMember); + + // when & then + NicknameUpdateRequest request = new NicknameUpdateRequest("testNickname2"); + assertThatThrownBy(() -> memberService.updateMemberNickname(request)) + .isInstanceOf(CustomException.class) + .hasMessage(ErrorCode.MEMBER_ALREADY_NICKNAME.getMessage()); + } + + @Test + void 닉네임이_중복되지_않으면_변경된다() { + // given + OauthInfo oauthInfo = + OauthInfo.createOauthInfo("testOauthId", "testOauthProvider", "testEmail"); + saveAndRegisterMember(oauthInfo); + + // when + NicknameUpdateRequest request = new NicknameUpdateRequest("testNickname2"); + + // then + assertDoesNotThrow(() -> memberService.updateMemberNickname(request)); + + Member member = memberRepository.findById(1L).get(); + assertEquals("testNickname2", member.getProfile().getNickname()); + } + } }