diff --git a/src/main/java/com/backend/blooming/authentication/application/AuthenticationService.java b/src/main/java/com/backend/blooming/authentication/application/AuthenticationService.java index 602a9ade..75ea9f5b 100644 --- a/src/main/java/com/backend/blooming/authentication/application/AuthenticationService.java +++ b/src/main/java/com/backend/blooming/authentication/application/AuthenticationService.java @@ -12,6 +12,7 @@ import com.backend.blooming.authentication.infrastructure.oauth.OAuthType; import com.backend.blooming.authentication.infrastructure.oauth.dto.UserInformationDto; 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 lombok.RequiredArgsConstructor; @@ -25,6 +26,8 @@ @RequiredArgsConstructor public class AuthenticationService { + private static final int NAME_MAX_LENGTH = 50; + private static final int BEGIN_INDEX = 0; private final OAuthClientComposite oAuthClientComposite; private final TokenProvider tokenProvider; private final UserRepository userRepository; @@ -56,12 +59,21 @@ private User persistUser(final UserInformationDto userInformationDto, final OAut final User savedUser = User.builder() .oAuthId(userInformationDto.oAuthId()) .oAuthType(oAuthType) + .name(convertToNameAndTruncateLength(userInformationDto.oAuthId())) .email(new Email(userInformationDto.email())) .build(); return userRepository.save(savedUser); } + private Name convertToNameAndTruncateLength(final String oAuthId) { + if (oAuthId.length() > NAME_MAX_LENGTH) { + return new Name(oAuthId.substring(BEGIN_INDEX, NAME_MAX_LENGTH)); + } + + return new Name(oAuthId); + } + private TokenDto convertToTokenDto(final User user) { final Long userId = user.getId(); final String accessToken = tokenProvider.createToken(TokenType.ACCESS, userId); diff --git a/src/main/java/com/backend/blooming/exception/ExceptionMessage.java b/src/main/java/com/backend/blooming/exception/ExceptionMessage.java index dda45ded..facfe3b1 100644 --- a/src/main/java/com/backend/blooming/exception/ExceptionMessage.java +++ b/src/main/java/com/backend/blooming/exception/ExceptionMessage.java @@ -21,7 +21,8 @@ public enum ExceptionMessage { NULL_OR_EMPTY_EMAIL("이메일은 비어있을 수 없습니다."), LONGER_THAN_MAXIMUM_EMAIL("이메일의 최대 길이를 초과했습니다."), INVALID_EMAIL_FORMAT("이메일 형식에 어긋났습니다."), - + NULL_OR_EMPTY_NAME("이름은 비어있을 수 없습니다."), + LONGER_THAN_MAXIMUM_NAME("이름의 최대 길이를 초과했습니다."), // 테마 색상 UNSUPPORTED_THEME_COLOR("지원하지 않는 테마 색상입니다."), diff --git a/src/main/java/com/backend/blooming/user/application/UserService.java b/src/main/java/com/backend/blooming/user/application/UserService.java index 6f4ffd99..c2b020f6 100644 --- a/src/main/java/com/backend/blooming/user/application/UserService.java +++ b/src/main/java/com/backend/blooming/user/application/UserService.java @@ -5,6 +5,7 @@ import com.backend.blooming.user.application.dto.UpdateUserDto; import com.backend.blooming.user.application.dto.ReadUsersWithFriendsStatusDto; import com.backend.blooming.user.application.exception.NotFoundUserException; +import com.backend.blooming.user.domain.Name; import com.backend.blooming.user.domain.User; import com.backend.blooming.user.infrastructure.repository.UserRepository; import com.backend.blooming.user.infrastructure.repository.UserWithFriendsStatusRepository; @@ -52,7 +53,8 @@ public ReadUserDto updateById(final Long userId, final UpdateUserDto updateUserD private void updateUserByRequest(final User user, final UpdateUserDto updateUserDto) { if (updateUserDto.name() != null) { - user.updateName(updateUserDto.name()); + final Name updateName = new Name(updateUserDto.name()); + user.updateName(updateName); } if (updateUserDto.color() != null) { final ThemeColor themeColor = ThemeColor.from(updateUserDto.color()); diff --git a/src/main/java/com/backend/blooming/user/domain/Name.java b/src/main/java/com/backend/blooming/user/domain/Name.java new file mode 100644 index 00000000..40a28d9e --- /dev/null +++ b/src/main/java/com/backend/blooming/user/domain/Name.java @@ -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(); + } + } +} diff --git a/src/main/java/com/backend/blooming/user/domain/User.java b/src/main/java/com/backend/blooming/user/domain/User.java index 7036b9d4..96c4e466 100644 --- a/src/main/java/com/backend/blooming/user/domain/User.java +++ b/src/main/java/com/backend/blooming/user/domain/User.java @@ -27,7 +27,6 @@ @Table(name = "users") public class User extends BaseTimeEntity { - private static final String DEFAULT_NAME = ""; private static final String DEFAULT_STATUS_MESSAGE = ""; private static final ThemeColor DEFAULT_THEME_COLOR = ThemeColor.INDIGO; @@ -45,8 +44,8 @@ public class User extends BaseTimeEntity { @Embedded private Email email; - @Column(unique = true, length = 50, nullable = false) - private String name; + @Embedded + private Name name; @Enumerated(EnumType.STRING) @Column(name = "theme_color", nullable = false) @@ -63,26 +62,18 @@ private User( final String oAuthId, final OAuthType oAuthType, final Email email, - final String name, + final Name name, final ThemeColor color, final String statusMessage ) { this.oAuthId = oAuthId; this.oAuthType = oAuthType; this.email = email; - this.name = processName(name); + this.name = name; this.color = processColor(color); this.statusMessage = processStatusMessage(statusMessage); } - private String processName(final String name) { - if (name == null) { - return DEFAULT_NAME; - } - - return name; - } - private ThemeColor processColor(final ThemeColor color) { if (color == null) { return DEFAULT_THEME_COLOR; @@ -103,7 +94,7 @@ public void delete() { this.deleted = true; } - public void updateName(final String name) { + public void updateName(final Name name) { this.name = name; } @@ -119,6 +110,10 @@ public String getEmail() { return email.getValue(); } + public String getName() { + return name.getValue(); + } + public String getColorName() { return color.name(); } diff --git a/src/main/java/com/backend/blooming/user/domain/exception/MemberException.java b/src/main/java/com/backend/blooming/user/domain/exception/MemberException.java index b351a3b7..bc59b32f 100644 --- a/src/main/java/com/backend/blooming/user/domain/exception/MemberException.java +++ b/src/main/java/com/backend/blooming/user/domain/exception/MemberException.java @@ -29,4 +29,18 @@ public InvalidEmailFormatException() { super(ExceptionMessage.INVALID_EMAIL_FORMAT); } } + + public static class NullOrEmptyNameException extends MemberException { + + public NullOrEmptyNameException() { + super(ExceptionMessage.NULL_OR_EMPTY_NAME); + } + } + + public static class LongerThanMaximumNameLengthException extends MemberException { + + public LongerThanMaximumNameLengthException() { + super(ExceptionMessage.LONGER_THAN_MAXIMUM_NAME); + } + } } diff --git a/src/main/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryImpl.java b/src/main/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryImpl.java index 981840d1..d849bfb0 100644 --- a/src/main/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryImpl.java +++ b/src/main/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryImpl.java @@ -31,7 +31,7 @@ public List findAllByNameContainsAndDeletedIsFalse( .leftJoin(friend) .on(buildFriendsConditions(currentUser.getId())) .fetchJoin() - .where(user.deleted.isFalse().and(user.name.contains(keyword))) + .where(user.deleted.isFalse().and(user.name.value.contains(keyword))) .fetch(); return userWithFriendDtos.stream() diff --git a/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTest.java b/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTest.java index 5b09e29c..dfaf371f 100644 --- a/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTest.java +++ b/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTest.java @@ -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자까지만_저장한_후_토큰_정보를_반환한다() { + // 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 diff --git a/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTestFixture.java b/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTestFixture.java index 0560f552..9e5478f9 100644 --- a/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTestFixture.java +++ b/src/test/java/com/backend/blooming/authentication/application/AuthenticationServiceTestFixture.java @@ -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("test@email.com")); + protected UserInformationDto oauthid가_50자를_초과하는_사용자_소셜_정보 = + new KakaoUserInformationDto( + "1234567890123456789012345678901234567890123456789012345", + new KakaoUserInformationDto.KakaoAccount("test2@email.com") + ); 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(); diff --git a/src/test/java/com/backend/blooming/friend/application/FriendServiceTestFixture.java b/src/test/java/com/backend/blooming/friend/application/FriendServiceTestFixture.java index fc930b20..c417fa14 100644 --- a/src/test/java/com/backend/blooming/friend/application/FriendServiceTestFixture.java +++ b/src/test/java/com/backend/blooming/friend/application/FriendServiceTestFixture.java @@ -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("user1@email.com")) .build(); final User 친구_요청할_사용자 = User.builder() .oAuthId("12346") .oAuthType(OAuthType.KAKAO) - .name("사용자2") + .name(new Name("사용자2")) .email(new Email("user2@email.com")) .build(); final User 친구_요청을_보낸_사용자 = User.builder() .oAuthId("12347") .oAuthType(OAuthType.KAKAO) - .name("사용자3") + .name(new Name("사용자3")) .email(new Email("user3@email.com")) .build(); final User 이미_친구_요청을_받은_사용자 = User.builder() .oAuthId("12348") .oAuthType(OAuthType.KAKAO) - .name("사용자4") + .name(new Name("사용자4")) .email(new Email("user4@email.com")) .build(); final User 친구_요청을_받은_사용자2 = User.builder() .oAuthId("12349") .oAuthType(OAuthType.KAKAO) - .name("사용자5") + .name(new Name("사용자5")) .email(new Email("user5@email.com")) .build(); final User 친구_요청을_받은_사용자3 = User.builder() .oAuthId("12350") .oAuthType(OAuthType.KAKAO) - .name("사용자6") + .name(new Name("사용자6")) .email(new Email("user6@email.com")) .build(); final User 친구인_사용자1 = User.builder() .oAuthId("23456") .oAuthType(OAuthType.KAKAO) - .name("친구1") + .name(new Name("친구1")) .email(new Email("friend1@email.com")) .build(); final User 친구인_사용자2 = User.builder() .oAuthId("23457") .oAuthType(OAuthType.KAKAO) - .name("친구2") + .name(new Name("친구2")) .email(new Email("friend2@email.com")) .build(); final User 친구인_사용자3 = User.builder() .oAuthId("23458") .oAuthType(OAuthType.KAKAO) - .name("친구3") + .name(new Name("친구3")) .email(new Email("friend3@email.com")) .build(); userRepository.saveAll(List.of( diff --git a/src/test/java/com/backend/blooming/friend/domain/FriendTestFixture.java b/src/test/java/com/backend/blooming/friend/domain/FriendTestFixture.java index fea07338..b428060a 100644 --- a/src/test/java/com/backend/blooming/friend/domain/FriendTestFixture.java +++ b/src/test/java/com/backend/blooming/friend/domain/FriendTestFixture.java @@ -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("user1@email.com")) .build(); protected static User 친구_요청을_받은_사용자 = User.builder() .oAuthId("12346") .oAuthType(OAuthType.KAKAO) - .name("사용자2") + .name(new Name("사용자2")) .email(new Email("user2@email.com")) .build(); protected static User 친구_요청과_상관없는_사용자 = User.builder() .oAuthId("12347") .oAuthType(OAuthType.KAKAO) - .name("사용자3") + .name(new Name("사용자3")) .email(new Email("user3@email.com")) .build(); diff --git a/src/test/java/com/backend/blooming/friend/infrastructure/repository/FriendRepositoryTestFixture.java b/src/test/java/com/backend/blooming/friend/infrastructure/repository/FriendRepositoryTestFixture.java index f8bc6afb..7058af16 100644 --- a/src/test/java/com/backend/blooming/friend/infrastructure/repository/FriendRepositoryTestFixture.java +++ b/src/test/java/com/backend/blooming/friend/infrastructure/repository/FriendRepositoryTestFixture.java @@ -3,6 +3,7 @@ import com.backend.blooming.authentication.infrastructure.oauth.OAuthType; import com.backend.blooming.friend.domain.Friend; 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; @@ -39,49 +40,49 @@ void setUpFixture() { 친구_요청한_사용자 = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자1") + .name(new Name("사용자1")) .email(new Email("user1@email.com")) .build(); 이미_친구_요청_받은_사용자 = User.builder() .oAuthId("12346") .oAuthType(OAuthType.KAKAO) - .name("사용자2") + .name(new Name("사용자2")) .email(new Email("user2@email.com")) .build(); 친구_요청을_받은적_없는_사용자 = User.builder() .oAuthId("12347") .oAuthType(OAuthType.KAKAO) - .name("사용자3") + .name(new Name("사용자3")) .email(new Email("user3@email.com")) .build(); final User 친구_요청을_받은_사용자2 = User.builder() .oAuthId("12348") .oAuthType(OAuthType.KAKAO) - .name("사용자4") + .name(new Name("사용자4")) .email(new Email("user4@email.com")) .build(); final User 친구_요청을_받은_사용자3 = User.builder() .oAuthId("12349") .oAuthType(OAuthType.KAKAO) - .name("사용자5") + .name(new Name("사용자5")) .email(new Email("user5@email.com")) .build(); final User 친구인_사용자1 = User.builder() .oAuthId("23456") .oAuthType(OAuthType.KAKAO) - .name("친구1") + .name(new Name("친구1")) .email(new Email("friend1@email.com")) .build(); final User 친구인_사용자2 = User.builder() .oAuthId("23457") .oAuthType(OAuthType.KAKAO) - .name("친구2") + .name(new Name("친구2")) .email(new Email("friend2@email.com")) .build(); final User 친구인_사용자3 = User.builder() .oAuthId("23458") .oAuthType(OAuthType.KAKAO) - .name("친구3") + .name(new Name("친구3")) .email(new Email("friend3@email.com")) .build(); userRepository.saveAll(List.of( diff --git a/src/test/java/com/backend/blooming/user/application/UserServiceTestFixture.java b/src/test/java/com/backend/blooming/user/application/UserServiceTestFixture.java index 15db1cd5..b3a00b3d 100644 --- a/src/test/java/com/backend/blooming/user/application/UserServiceTestFixture.java +++ b/src/test/java/com/backend/blooming/user/application/UserServiceTestFixture.java @@ -6,6 +6,7 @@ import com.backend.blooming.themecolor.domain.ThemeColor; import com.backend.blooming.user.application.dto.UpdateUserDto; 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; @@ -46,7 +47,7 @@ void setUpFixture() { 사용자 = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자") + .name(new Name("사용자")) .email(new Email("test@email.com")) .color(ThemeColor.BEIGE) .statusMessage("기존 상태 메시지") @@ -54,19 +55,19 @@ void setUpFixture() { 친구인_사용자 = User.builder() .oAuthId("12346") .oAuthType(OAuthType.KAKAO) - .name("사용자2") + .name(new Name("사용자2")) .email(new Email("test2@email.com")) .build(); 친구가_아닌_사용자 = User.builder() .oAuthId("12347") .oAuthType(OAuthType.KAKAO) - .name("사용자3") + .name(new Name("사용자3")) .email(new Email("test3@email.com")) .build(); final User 삭제한_사용자 = User.builder() .oAuthId("12348") .oAuthType(OAuthType.KAKAO) - .name("삭제한 사용자") + .name(new Name("삭제한 사용자")) .email(new Email("test4@email.com")) .build(); 삭제한_사용자.delete(); diff --git a/src/test/java/com/backend/blooming/user/domain/NameTest.java b/src/test/java/com/backend/blooming/user/domain/NameTest.java new file mode 100644 index 00000000..5a797179 --- /dev/null +++ b/src/test/java/com/backend/blooming/user/domain/NameTest.java @@ -0,0 +1,46 @@ +package com.backend.blooming.user.domain; + +import com.backend.blooming.user.domain.exception.MemberException; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +@SuppressWarnings("NonAsciiCharacters") +class NameTest { + + @Test + void 이름을_생성한다() { + // given + final String nameValue = "name"; + + // when + final Name actual = new Name(nameValue); + + // then + assertThat(actual.getValue()).isEqualTo(nameValue); + } + + @ParameterizedTest(name = "빈 값: {0}") + @NullAndEmptySource + void 빈값으로_이름을_생성할시_예외를_반환한다(final String invalidNameValue) { + // when & then + assertThatThrownBy(() -> new Name(invalidNameValue)) + .isInstanceOf(MemberException.NullOrEmptyNameException.class); + } + + @Test + void 이름의_최대_길이를_초과한_값으로_이름을_생성할시_예외를_반환한다() { + // given + final String invalidNameValue = "12345678901234567890123456789012345678901234567890123456"; + + // when & then + assertThatThrownBy(() -> new Name(invalidNameValue)) + .isInstanceOf(MemberException.LongerThanMaximumNameLengthException.class); + } +} diff --git a/src/test/java/com/backend/blooming/user/domain/UserTest.java b/src/test/java/com/backend/blooming/user/domain/UserTest.java index ee665320..a59881bf 100644 --- a/src/test/java/com/backend/blooming/user/domain/UserTest.java +++ b/src/test/java/com/backend/blooming/user/domain/UserTest.java @@ -15,20 +15,21 @@ class UserTest extends UserTestFixture { @Test - void 사용자_생성시_이름_색상_상태메시지를_설정하지_않을시_기본값으로_설정한다() { + void 사용자_생성시_색상_상태메시지를_설정하지_않을시_기본값으로_설정한다() { // when final User actual = User.builder() - .oAuthId("12345") - .oAuthType(OAuthType.KAKAO) - .email(new Email("user@email.com")) - .build(); + .oAuthId("12345") + .oAuthType(OAuthType.KAKAO) + .email(new Email("user@email.com")) + .name(new Name("test")) + .build(); // then SoftAssertions.assertSoftly(softAssertions -> { softAssertions.assertThat(actual.getOAuthId()).isEqualTo("12345"); softAssertions.assertThat(actual.getOAuthType()).isEqualTo(OAuthType.KAKAO); softAssertions.assertThat(actual.getEmail()).isEqualTo("user@email.com"); - softAssertions.assertThat(actual.getName()).isEqualTo(""); + softAssertions.assertThat(actual.getName()).isEqualTo("test"); softAssertions.assertThat(actual.getColor()).isEqualTo(ThemeColor.INDIGO); softAssertions.assertThat(actual.getStatusMessage()).isEqualTo(""); }); @@ -49,7 +50,7 @@ class UserTest extends UserTestFixture { final String updateName = "수정한 이름"; // when - 사용자.updateName(updateName); + 사용자.updateName(new Name(updateName)); // then assertSoftly(softAssertions -> { @@ -106,7 +107,7 @@ class UserTest extends UserTestFixture { final User user = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자") + .name(new Name("사용자")) .email(new Email("user@email.com")) .color(ThemeColor.BEIGE) .build(); @@ -124,7 +125,7 @@ class UserTest extends UserTestFixture { final User user = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자") + .name(new Name("사용자")) .email(new Email("user@email.com")) .color(ThemeColor.BEIGE) .build(); @@ -142,7 +143,7 @@ class UserTest extends UserTestFixture { final User user = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자") + .name(new Name("사용자")) .email(new Email("user@email.com")) .color(ThemeColor.BEIGE) .build(); diff --git a/src/test/java/com/backend/blooming/user/domain/UserTestFixture.java b/src/test/java/com/backend/blooming/user/domain/UserTestFixture.java index c6329793..34e43c4d 100644 --- a/src/test/java/com/backend/blooming/user/domain/UserTestFixture.java +++ b/src/test/java/com/backend/blooming/user/domain/UserTestFixture.java @@ -15,7 +15,7 @@ public class UserTestFixture { protected User 사용자 = User.builder() .oAuthId(기존_소셜_아이디) .oAuthType(기존_소셜_타입) - .name(기존_이름) + .name(new Name(기존_이름)) .email(new Email(기존_이메일)) .color(기존_테마_색상) .statusMessage(기존_상태_메시지) diff --git a/src/test/java/com/backend/blooming/user/infrastructure/repository/UserRepositoryTestFixture.java b/src/test/java/com/backend/blooming/user/infrastructure/repository/UserRepositoryTestFixture.java index cb079216..797a22db 100644 --- a/src/test/java/com/backend/blooming/user/infrastructure/repository/UserRepositoryTestFixture.java +++ b/src/test/java/com/backend/blooming/user/infrastructure/repository/UserRepositoryTestFixture.java @@ -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.beans.factory.annotation.Autowired; @@ -29,19 +30,19 @@ void setUpFixture() { 사용자 = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자") + .name(new Name("사용자")) .email(new Email("test@email.com")) .build(); 사용자2 = User.builder() .oAuthId("12346") .oAuthType(OAuthType.KAKAO) - .name("사용자2") + .name(new Name("사용자2")) .email(new Email("test2@email.com")) .build(); 삭제된_사용자 = User.builder() .oAuthId("12348") .oAuthType(OAuthType.KAKAO) - .name("삭제된 사용자") + .name(new Name("삭제된 사용자")) .email(new Email("test4@email.com")) .build(); 삭제된_사용자.delete(); diff --git a/src/test/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryTestFixture.java b/src/test/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryTestFixture.java index 0104e42f..ff45a090 100644 --- a/src/test/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryTestFixture.java +++ b/src/test/java/com/backend/blooming/user/infrastructure/repository/UserWithFriendsStatusRepositoryTestFixture.java @@ -4,6 +4,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 org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; @@ -31,37 +32,37 @@ void setUpFixture() { 사용자 = User.builder() .oAuthId("12345") .oAuthType(OAuthType.KAKAO) - .name("사용자") + .name(new Name("사용자")) .email(new Email("test@email.com")) .build(); 친구인_사용자 = User.builder() .oAuthId("12346") .oAuthType(OAuthType.KAKAO) - .name("사용자2 검색어") + .name(new Name("사용자2 검색어")) .email(new Email("test2@email.com")) .build(); 친구로_요청한_사용자 = User.builder() .oAuthId("12347") .oAuthType(OAuthType.KAKAO) - .name("사용자3 검색어") + .name(new Name("사용자3 검색어")) .email(new Email("test3@email.com")) .build(); 친구_요청을_받은_사용자 = User.builder() .oAuthId("12348") .oAuthType(OAuthType.KAKAO) - .name("사용자4") + .name(new Name("사용자4")) .email(new Email("test4@email.com")) .build(); 관계가_없는_사용자 = User.builder() .oAuthId("12349") .oAuthType(OAuthType.KAKAO) - .name("사용자5") + .name(new Name("사용자5")) .email(new Email("test5@email.com")) .build(); 삭제된_사용자 = User.builder() .oAuthId("12350") .oAuthType(OAuthType.KAKAO) - .name("사용자6") + .name(new Name("사용자6")) .email(new Email("test6@email.com")) .build(); 삭제된_사용자.delete();