-
Notifications
You must be signed in to change notification settings - Fork 0
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
기본 이름이 중복되어 생성되는 문제 해결 #30
Changes from all commits
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,37 @@ | ||
package com.backend.blooming.user.domain; | ||
|
||
import com.backend.blooming.user.domain.exception.MemberException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class Name { | ||
|
||
private static final int MAX_LENGTH = 50; | ||
|
||
@Column(name = "name", unique = true, length = MAX_LENGTH, nullable = false) | ||
private String value; | ||
|
||
public Name(final String value) { | ||
validateValue(value); | ||
this.value = value; | ||
} | ||
|
||
private void validateValue(final String value) { | ||
if (value == null || value.isEmpty()) { | ||
throw new MemberException.NullOrEmptyNameException(); | ||
} | ||
if (value.length() > MAX_LENGTH) { | ||
throw new MemberException.LongerThanMaximumNameLengthException(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
import com.backend.blooming.authentication.infrastructure.exception.UnsupportedOAuthTypeException; | ||
import com.backend.blooming.authentication.infrastructure.oauth.OAuthClient; | ||
import com.backend.blooming.configuration.IsolateDatabase; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -29,6 +31,9 @@ class AuthenticationServiceTest extends AuthenticationServiceTestFixture { | |
@Autowired | ||
private AuthenticationService authenticationService; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Test | ||
void 로그인시_존재하지_않는_사용자인_경우_해당_사용자를_저장후_토큰_정보를_반환한다() { | ||
// given | ||
|
@@ -45,6 +50,30 @@ class AuthenticationServiceTest extends AuthenticationServiceTestFixture { | |
}); | ||
} | ||
|
||
@Test | ||
void 로그인시_존재하지_않는_사용자이며_oauthid가_50자를_초과하는_경우_이름을_50자까지만_저장한_후_토큰_정보를_반환한다() { | ||
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. 실제로 이름이 50자까지 저장되었는지 비교검증은 필요없을까요? 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. 해당 테스트에 비교 검증하는 부분이 있다면 이해가 더 쉬울 것 같아 이 부분만 추가해주시면 좋을 것 같습니다! 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. 헉 테스트하길 잘했어요..! |
||
// given | ||
willReturn(oauthid가_50자를_초과하는_사용자_소셜_정보).given(oAuthClient).findUserInformation(소셜_액세스_토큰); | ||
|
||
// when | ||
final LoginInformationDto actual = authenticationService.login(oauth_타입, 소셜_액세스_토큰); | ||
|
||
// then | ||
final User savedUser = userRepository.findByOAuthIdAndOAuthType( | ||
oauthid가_50자를_초과하는_사용자_소셜_정보.oAuthId(), | ||
oauth_타입 | ||
) | ||
.get(); | ||
System.out.println(savedUser); | ||
|
||
assertSoftly(softAssertions -> { | ||
softAssertions.assertThat(actual.token().accessToken()).isNotEmpty(); | ||
softAssertions.assertThat(actual.token().refreshToken()).isNotEmpty(); | ||
softAssertions.assertThat(actual.isSignUp()).isTrue(); | ||
softAssertions.assertThat(savedUser.getName().length()).isEqualTo(50); | ||
}); | ||
} | ||
|
||
@Test | ||
void 로그인시_존재하는_사용자인_경우_사용자_정보를_반환시_회원가입_여부는_거짓이다() { | ||
// given | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import com.backend.blooming.authentication.infrastructure.oauth.dto.UserInformationDto; | ||
import com.backend.blooming.authentication.infrastructure.oauth.kakao.dto.KakaoUserInformationDto; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.Name; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -24,8 +25,13 @@ public class AuthenticationServiceTestFixture { | |
protected String 소셜_액세스_토큰 = "social_access_token"; | ||
protected UserInformationDto 첫_로그인_사용자_소셜_정보 = | ||
new KakaoUserInformationDto("12345", new KakaoUserInformationDto.KakaoAccount("[email protected]")); | ||
protected UserInformationDto oauthid가_50자를_초과하는_사용자_소셜_정보 = | ||
new KakaoUserInformationDto( | ||
"1234567890123456789012345678901234567890123456789012345", | ||
new KakaoUserInformationDto.KakaoAccount("[email protected]") | ||
); | ||
protected UserInformationDto 기존_사용자_소셜_정보 = | ||
new KakaoUserInformationDto("12346", new KakaoUserInformationDto.KakaoAccount("test2@email.com")); | ||
new KakaoUserInformationDto("12346", new KakaoUserInformationDto.KakaoAccount("test3@email.com")); | ||
protected String 유효한_refresh_token; | ||
protected String 존재하지_않는_사용자의_refresh_token; | ||
protected String 유효하지_않는_refresh_token = "Bearer invalid_refresh_token"; | ||
|
@@ -36,7 +42,7 @@ void setUpFixture() { | |
final User 기존_사용자 = User.builder() | ||
.oAuthType(oauth_타입) | ||
.oAuthId(기존_사용자_소셜_정보.oAuthId()) | ||
.name("기존 사용자") | ||
.name(new Name("기존 사용자")) | ||
.email(new Email(기존_사용자_소셜_정보.email())) | ||
.build(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import com.backend.blooming.friend.domain.Friend; | ||
import com.backend.blooming.friend.infrastructure.repository.FriendRepository; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.Name; | ||
import com.backend.blooming.user.domain.User; | ||
import com.backend.blooming.user.infrastructure.repository.UserRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -45,55 +46,55 @@ void setUpFixture() { | |
final User 사용자 = User.builder() | ||
.oAuthId("12345") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자1") | ||
.name(new Name("사용자1")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청할_사용자 = User.builder() | ||
.oAuthId("12346") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자2") | ||
.name(new Name("사용자2")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_보낸_사용자 = User.builder() | ||
.oAuthId("12347") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자3") | ||
.name(new Name("사용자3")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 이미_친구_요청을_받은_사용자 = User.builder() | ||
.oAuthId("12348") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자4") | ||
.name(new Name("사용자4")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_받은_사용자2 = User.builder() | ||
.oAuthId("12349") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자5") | ||
.name(new Name("사용자5")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구_요청을_받은_사용자3 = User.builder() | ||
.oAuthId("12350") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자6") | ||
.name(new Name("사용자6")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자1 = User.builder() | ||
.oAuthId("23456") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구1") | ||
.name(new Name("친구1")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자2 = User.builder() | ||
.oAuthId("23457") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구2") | ||
.name(new Name("친구2")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
final User 친구인_사용자3 = User.builder() | ||
.oAuthId("23458") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("친구3") | ||
.name(new Name("친구3")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
userRepository.saveAll(List.of( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType; | ||
import com.backend.blooming.user.domain.Email; | ||
import com.backend.blooming.user.domain.Name; | ||
import com.backend.blooming.user.domain.User; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
@@ -12,19 +13,19 @@ public class FriendTestFixture { | |
protected static User 친구_요청을_한_사용자 = User.builder() | ||
.oAuthId("12345") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자1") | ||
.name(new Name("사용자1")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
protected static User 친구_요청을_받은_사용자 = User.builder() | ||
.oAuthId("12346") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자2") | ||
.name(new Name("사용자2")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
protected static User 친구_요청과_상관없는_사용자 = User.builder() | ||
.oAuthId("12347") | ||
.oAuthType(OAuthType.KAKAO) | ||
.name("사용자3") | ||
.name(new Name("사용자3")) | ||
.email(new Email("[email protected]")) | ||
.build(); | ||
|
||
|
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.
vo 값을 가져오는 경우 해당 vo에서 get 해오도록 했는데 정수님 코드 보고 도메인 엔티티에 직접 get 메서드 정의해 사용하면 좋을 것 같아서 이 부분도 수정하도록 하겠습니다!