Skip to content

Commit

Permalink
test: 닉네임 변경 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
uwoobeat committed Jan 30, 2024
1 parent 30c2b6d commit ad22d29
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit ad22d29

Please sign in to comment.