Skip to content

Commit

Permalink
refactor: 세분화된 회원 정보 수정에 맞춰서 TestCase 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
thun0514 committed Jul 14, 2024
1 parent 00553d3 commit 0d34e92
Showing 1 changed file with 19 additions and 35 deletions.
54 changes: 19 additions & 35 deletions src/test/java/jungle/HandTris/Member/AuthServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import jungle.HandTris.domain.repo.MemberRepository;
import jungle.HandTris.presentation.dto.request.MemberRequest;
import jungle.HandTris.presentation.dto.request.MemberUpdateReq;
import jungle.HandTris.presentation.dto.response.MemberProfileUpdateDetailsRes;
import jungle.HandTris.presentation.dto.response.MemberRecordDetailRes;
import jungle.HandTris.presentation.dto.response.ReissueTokenRes;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -339,7 +339,7 @@ public void testMyPageConnectWrongUser() {

@Nested
@DisplayName("회원 정보 요청")
class GetMemberProfile {
class GetMemberProfile {

}

Expand All @@ -365,12 +365,11 @@ public void testChangeMemberNicknameSuccess() {
MemberUpdateReq changeNickname = new MemberUpdateReq("user2");

// when
MemberProfileUpdateDetailsRes changeMemberProfile = memberProfileService.updateMemberProfile(
request, changeNickname, null, false);
ReissueTokenRes changeMemberProfile = memberProfileService.changeMemberNickname(
requestMember.nickname(), changeNickname);

// then
Assertions.assertThat(changeMemberProfile.nickname()).isEqualTo(member.getNickname());
Assertions.assertThat(changeMemberProfile.token()).isNotEqualTo(token);
Assertions.assertThat(changeMemberProfile.access()).isNotEqualTo(token);
}

@Test
Expand All @@ -390,8 +389,8 @@ public void testChangeMemberNicknameWithSameNickname() {

// when & then
Assertions.assertThatThrownBy(() -> {
memberProfileService.updateMemberProfile(
request, changeNickname, null, null);
memberProfileService.changeMemberNickname(
requestMember.nickname(), changeNickname);
}).isInstanceOf(NicknameNotChangedException.class);
}

Expand All @@ -414,8 +413,8 @@ public void testChangeMemberNicknameWithDuplicateNickname() {

// when & then
Assertions.assertThatThrownBy(() -> {
memberProfileService.updateMemberProfile(
request, changeNickname, null, null);
memberProfileService.changeMemberNickname(
requestMember1.nickname(), changeNickname);
}).isInstanceOf(DuplicateNicknameException.class);
}
}
Expand All @@ -440,7 +439,7 @@ public void testChangeMemberProfileImageSuccess() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer " + token);

MemberUpdateReq changeNickname = new MemberUpdateReq(null);
String originImageUrl = member.getProfileImageUrl();

// 변경하려는 프로필 사진
MockMultipartFile changeProfileImage = new MockMultipartFile(
Expand All @@ -452,11 +451,10 @@ public void testChangeMemberProfileImageSuccess() {
);

// when
MemberProfileUpdateDetailsRes changeMemberProfile = memberProfileService.updateMemberProfile(
request, changeNickname, changeProfileImage, false);
memberProfileService.changeMemberProfileImage(requestMember.nickname(), changeProfileImage);

// then
Assertions.assertThat(changeMemberProfile.profileImageUrl()).isEqualTo(member.getProfileImageUrl());
Assertions.assertThat(originImageUrl).isEqualTo(member.getProfileImageUrl());
}

@Test
Expand All @@ -472,7 +470,8 @@ public void testChangeMemberDefaultProfileImageSuccess() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer " + token);

MemberUpdateReq changeNickname = new MemberUpdateReq(null);
String originImageUrl = member.getProfileImageUrl();

// 변경하려는 프로필 사진
MockMultipartFile changeProfileImage = new MockMultipartFile(
"image", // 파라미터 이름
Expand All @@ -481,14 +480,12 @@ public void testChangeMemberDefaultProfileImageSuccess() {
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=".getBytes() // PNG 이미지 데이터 (Base64)
);

MemberProfileUpdateDetailsRes changeMemberProfile = memberProfileService.updateMemberProfile(
request, changeNickname, changeProfileImage, false);
memberProfileService.changeMemberProfileImage(requestMember.nickname(), changeProfileImage);

Assertions.assertThat(changeMemberProfile.profileImageUrl()).isEqualTo(member.getProfileImageUrl());
Assertions.assertThat(originImageUrl).isEqualTo(member.getProfileImageUrl());

// when
memberProfileService.updateMemberProfile(
request, changeNickname, null, true);
memberProfileService.deleteMemberProfileImage(requestMember.nickname());
// then
Assertions.assertThat(defaultImage).isEqualTo(member.getProfileImageUrl());
}
Expand All @@ -499,14 +496,7 @@ public void testChangeMemberNicknameWithSameNickname() {
// given
MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1");
authService.signup(requestMember);
Pair<Member, String> SigninResult = authService.signin(requestMember);
Member member = SigninResult.getFirst();
String token = SigninResult.getSecond();

MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer " + token);

MemberUpdateReq changeNickname = new MemberUpdateReq(null);
// 변경하려는 프로필 사진
MockMultipartFile changeProfileImage = new MockMultipartFile(
"image", // 파라미터 이름
Expand All @@ -517,8 +507,7 @@ public void testChangeMemberNicknameWithSameNickname() {

// when & then
Assertions.assertThatThrownBy(() -> {
memberProfileService.updateMemberProfile(
request, changeNickname, changeProfileImage, false);
memberProfileService.changeMemberProfileImage(requestMember.nickname(), changeProfileImage);
}).isInstanceOf(InvalidImageTypeException.class);
}

Expand All @@ -532,10 +521,6 @@ public void testChangeMemberNicknameWithDuplicateNickname() {
Member member = SigninResult.getFirst();
String token = SigninResult.getSecond();

MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer " + token);

MemberUpdateReq changeNickname = new MemberUpdateReq(null);
// 변경하려는 프로필 사진
MockMultipartFile changeProfileImage = new MockMultipartFile(
"image", // 파라미터 이름
Expand All @@ -550,8 +535,7 @@ public void testChangeMemberNicknameWithDuplicateNickname() {

// when & then
Assertions.assertThatThrownBy(() -> {
memberProfileService.updateMemberProfile(
request, changeNickname, changeProfileImage, false);
memberProfileService.changeMemberProfileImage(requestMember.nickname(), changeProfileImage);
}).isInstanceOf(InvalidImageTypeException.class);
}
}
Expand Down

0 comments on commit 0d34e92

Please sign in to comment.