-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Feature] - BE 테스트 개선 1단계 Test Fixture 운용 방식 통일 (Enum Fixture) #614
Changes from all commits
47b71e2
e446ed7
26c535d
739b5a6
adb1607
ac6904f
5a02135
521c494
1bbcaed
f0b74bf
123a7ba
99963e0
bf0b043
db795f0
807247d
0b29c38
a136269
f63349b
b8aae21
f54079b
6b83c22
5b80e2d
de7e81a
d206e14
0b51fc3
72d9350
f854dec
e23ce11
99cf179
2c0198d
8e590b0
5b49640
f24222f
a9e5902
18a6e65
4b9730f
d7ec90f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package kr.touroot.authentication.fixture; | ||
|
||
import kr.touroot.authentication.dto.response.OauthUserInformationResponse; | ||
import kr.touroot.authentication.dto.response.kakao.KakaoAccount; | ||
import kr.touroot.authentication.dto.response.kakao.KakaoProfile; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public enum OauthUserFixture { | ||
|
||
KAKAO_USER(1L, "test_nickname", "https://test_img_src.com"); | ||
|
||
private final Long socialLoginId; | ||
private final String nickname; | ||
private final String profileImagePath; | ||
|
||
public OauthUserInformationResponse getOauthInformationResponse() { | ||
KakaoProfile kakaoProfile = new KakaoProfile(nickname, profileImagePath); | ||
KakaoAccount kakaoAccount = new KakaoAccount(kakaoProfile); | ||
return new OauthUserInformationResponse(socialLoginId, kakaoAccount); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,31 @@ | |
|
||
import kr.touroot.member.domain.LoginType; | ||
import kr.touroot.member.domain.Member; | ||
import kr.touroot.member.dto.request.MemberRequest; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum MemberFixture { | ||
|
||
KAKAO_MEMBER(1L, null, null, "https://dev.touroot.kr/temporary/profile.png", "리비", | ||
LoginType.KAKAO), | ||
DEFAULT_MEMBER(null, "[email protected]", "password", "https://dev.touroot.kr/temporary/profile.png", "뚜리", | ||
LoginType.DEFAULT); | ||
KAKAO_MEMBER( | ||
1L, | ||
null, | ||
null, | ||
"https://dev.touroot.kr/temporary/profile.png", | ||
"리비", | ||
LoginType.KAKAO | ||
), | ||
TOUROOT_LOCAL_USER( | ||
null, | ||
"[email protected]", | ||
"password", | ||
"https://dev.touroot.kr/temporary/profile.png", | ||
"뚜리", | ||
LoginType.DEFAULT | ||
), | ||
; | ||
|
||
private final Long socialId; | ||
private final String email; | ||
|
@@ -21,10 +35,34 @@ public enum MemberFixture { | |
private final String nickname; | ||
private final LoginType loginType; | ||
|
||
public Member build() { | ||
public Member getMember() { | ||
if (loginType == LoginType.KAKAO) { | ||
return new Member(socialId, nickname, profileImageUrl, loginType); | ||
} | ||
return new Member(email, password, nickname, profileImageUrl, loginType); | ||
} | ||
|
||
public MemberRequest getCreateRequest() { | ||
return new MemberRequest(email, password, nickname, profileImageUrl); | ||
} | ||
|
||
public MemberRequest getCreateRequestWithEmail(String email) { | ||
return new MemberRequest(email, password, nickname, profileImageUrl); | ||
} | ||
|
||
public MemberRequest getCreateRequestWithPassword(String password) { | ||
return new MemberRequest(email, password, nickname, profileImageUrl); | ||
} | ||
|
||
public MemberRequest getCreateRequestWithNickname(String nickname) { | ||
return new MemberRequest(email, password, nickname, profileImageUrl); | ||
} | ||
|
||
public MemberRequest getCreateRequestWithProfileImageUrl(String profileImageUrl) { | ||
return new MemberRequest(email, password, nickname, profileImageUrl); | ||
} | ||
|
||
public MemberRequest getCreateRequestWithEmailAndNickname(String email, String nickname) { | ||
return new MemberRequest(email, password, nickname, profileImageUrl); | ||
} | ||
Comment on lines
+49
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테스트에 필요한 조합이 다르다보니 점층적인 생성자 오버로딩이 많아졌네요.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. builder를 사용해도 개선점이 크진 않을 것 같아요~ 미리 작성된 MemberFixture에 email하나, 닉네임 하나의 값만 바꾸고 싶은 경우에 사용하는 메서드들이어서요~ 빌더를 통해 진행되어도 다음처럼 어색한 구문이 탄생할 수 있겠어요 MemberRequestBuilder.forMemberFixture(MemberFixture.LIBI)
.setEmail("[email protected]")
.build(); 다만 Member에 새로운 속성이 추가되게 된다면 나머지 메서드들이 영향을 받는 다는 점에서 클로버가 지적해주신 유지보수 약점이 타당해 보이네요.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빌더 역시 사용하게 되면 도메인 명세를 무시한 (특정 속성을 지니지 않은 데이터 생성 요청) 객체를 생성할 수 있는 취약점이 될 수 있을 것 같아서 우선은 트레이드 오프 지점이라고 결론 내렸습니다. 해당 코멘트는 반영하지 않을 예정인데 다른 의견 있으시면 알려주시면 감사하겠숨다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 유지보수 약점만 인지하고 넘어가도 좋을 것 같습니다~ |
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package kr.touroot.member.service; | ||
|
||
import static kr.touroot.member.fixture.MemberRequestFixture.DUPLICATE_NICKNAME_MEMBER; | ||
import static kr.touroot.member.fixture.MemberRequestFixture.VALID_MEMBER; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
@@ -17,6 +15,7 @@ | |
import kr.touroot.member.domain.Member; | ||
import kr.touroot.member.dto.request.MemberRequest; | ||
import kr.touroot.member.dto.request.ProfileUpdateRequest; | ||
import kr.touroot.member.fixture.MemberFixture; | ||
import kr.touroot.member.helper.MemberTestHelper; | ||
import kr.touroot.utils.DatabaseCleaner; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -75,7 +74,7 @@ void getByIdNotExist() { | |
@DisplayName("정상적인 값을 가진 요청이 주어지면 회원을 생성한다.") | ||
@Test | ||
void createMember() { | ||
MemberRequest request = VALID_MEMBER.getRequest(); | ||
MemberRequest request = MemberFixture.TOUROOT_LOCAL_USER.getCreateRequest(); | ||
|
||
Long id = memberService.createMember(request); | ||
|
||
|
@@ -94,11 +93,16 @@ void createMemberWithDuplicatedEmail() { | |
.hasMessage("이미 회원 가입되어 있는 이메일입니다."); | ||
} | ||
|
||
@DisplayName("중복된 이메일을 가진 회원을 생성하려하면 예외가 발생한다.") | ||
@DisplayName("중복된 닉네임을 가진 회원을 생성하려하면 예외가 발생한다.") | ||
Comment on lines
-97
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희 닉네임 중복도 제한되고 있었나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
@Test | ||
void createMemberWithDuplicatedNickname() { | ||
testHelper.persistMember(); | ||
MemberRequest request = DUPLICATE_NICKNAME_MEMBER.getRequest(); | ||
Member persistedMember = testHelper.persistMember(); | ||
String nonDuplicatedEmail = "noDuplicate" + persistedMember.getEmail(); | ||
String duplicatedNickname = persistedMember.getNickname(); | ||
MemberRequest request = MemberFixture.TOUROOT_LOCAL_USER.getCreateRequestWithEmailAndNickname( | ||
nonDuplicatedEmail, | ||
duplicatedNickname | ||
); | ||
|
||
assertThatThrownBy(() -> memberService.createMember(request)) | ||
.isInstanceOf(BadRequestException.class) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enumFixture는 속성 값들을 거느리고 해당 fixture를 통해서 도메인 뿐만 아니라 위의 코드처럼 생성 요청 DTO를 만들 수도 있음을 안내드립니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
멋지네요! 확실히 Enum Fixture가 기존 방식보다 여러모로 유연하다는 생각이 듭니다.