diff --git a/damaba/src/main/resources/schema.sql b/damaba/src/main/resources/schema.sql index 8261812..1f6fe16 100644 --- a/damaba/src/main/resources/schema.sql +++ b/damaba/src/main/resources/schema.sql @@ -7,16 +7,17 @@ DROP TABLE IF EXISTS promotion_hashtag; CREATE TABLE `user` ( - id BIGINT NOT NULL AUTO_INCREMENT, - roles VARCHAR(255) NOT NULL, - login_type VARCHAR(255) NOT NULL, - o_auth_login_uid VARCHAR(255) NOT NULL UNIQUE, - nickname VARCHAR(7) NOT NULL UNIQUE, - profile_image_url VARCHAR(255) NOT NULL, - gender VARCHAR(255) NOT NULL, - instagram_id VARCHAR(30), - created_at DATETIME NOT NULL, - updated_at DATETIME NOT NULL, + id BIGINT NOT NULL AUTO_INCREMENT, + roles VARCHAR(255) NOT NULL, + login_type VARCHAR(255) NOT NULL, + o_auth_login_uid VARCHAR(255) NOT NULL UNIQUE, + nickname VARCHAR(7) NOT NULL UNIQUE, + profile_image_name VARCHAR(255) NOT NULL, + profile_image_url VARCHAR(255) NOT NULL, + gender VARCHAR(255) NOT NULL, + instagram_id VARCHAR(30), + created_at DATETIME NOT NULL, + updated_at DATETIME NOT NULL, PRIMARY KEY (id) ); CREATE INDEX idx__user__o_auth_login_uid ON `user` (o_auth_login_uid); diff --git a/damaba/src/test/kotlin/com/damaba/damaba/util/RandomTestUtils.kt b/damaba/src/test/kotlin/com/damaba/damaba/util/RandomTestUtils.kt index cb28bf5..32a70a8 100644 --- a/damaba/src/test/kotlin/com/damaba/damaba/util/RandomTestUtils.kt +++ b/damaba/src/test/kotlin/com/damaba/damaba/util/RandomTestUtils.kt @@ -32,6 +32,8 @@ class RandomTestUtils { randomInt(positive = true) % 25 + 1, ) + fun randomUrl(): String = "https://${randomString()}" + fun generateRandomList(maxSize: Int, generator: () -> T): List = generateSequence { generator() } .take(randomInt(positive = true, max = maxSize)) diff --git a/damaba/src/test/kotlin/com/damaba/damaba/util/TestFixture.kt b/damaba/src/test/kotlin/com/damaba/damaba/util/TestFixture.kt index 2e1aab0..29c56ac 100644 --- a/damaba/src/test/kotlin/com/damaba/damaba/util/TestFixture.kt +++ b/damaba/src/test/kotlin/com/damaba/damaba/util/TestFixture.kt @@ -14,7 +14,9 @@ import com.damaba.damaba.util.RandomTestUtils.Companion.generateRandomSet import com.damaba.damaba.util.RandomTestUtils.Companion.randomLocalDate import com.damaba.damaba.util.RandomTestUtils.Companion.randomLong import com.damaba.damaba.util.RandomTestUtils.Companion.randomString +import com.damaba.damaba.util.RandomTestUtils.Companion.randomUrl import com.damaba.user.domain.user.User +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import com.damaba.user.domain.user.constant.LoginType import com.damaba.user.domain.user.constant.UserRoleType @@ -30,7 +32,7 @@ object TestFixture { oAuthLoginUid: String = randomString(), loginType: LoginType = LoginType.KAKAO, nickname: String = randomString(len = 7), - profileImageUrl: String = randomString(), + profileImage: UserProfileImage = UserProfileImage(randomString(), randomUrl()), gender: Gender = Gender.MALE, instagramId: String = randomString(len = 30), ): User = User( @@ -39,7 +41,7 @@ object TestFixture { oAuthLoginUid = oAuthLoginUid, loginType = loginType, nickname = nickname, - profileImageUrl = profileImageUrl, + profileImage = profileImage, gender = gender, instagramId = instagramId, ) diff --git a/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UpdateMyInfoRequest.kt b/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UpdateMyInfoRequest.kt index 8cc3b2d..1f6ac72 100644 --- a/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UpdateMyInfoRequest.kt +++ b/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UpdateMyInfoRequest.kt @@ -1,6 +1,7 @@ package com.damaba.user.adapter.inbound.user.dto import com.damaba.user.application.port.inbound.user.UpdateMyInfoUseCase +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import io.swagger.v3.oas.annotations.media.Schema @@ -14,14 +15,14 @@ data class UpdateMyInfoRequest( @Schema(description = "인스타 아이디", example = "damaba.unofficial") val instagramId: String?, - @Schema(description = "프로필 이미지 URL") - val profileImageUrl: String, + @Schema(description = "프로필 이미지") + val profileImage: UserProfileImage, ) { fun toCommand(requestUserId: Long): UpdateMyInfoUseCase.Command = UpdateMyInfoUseCase.Command( userId = requestUserId, nickname = this.nickname, gender = this.gender, instagramId = this.instagramId, - profileImageUrl = profileImageUrl, + profileImage = profileImage, ) } diff --git a/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UserResponse.kt b/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UserResponse.kt index 967d1c5..08d353b 100644 --- a/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UserResponse.kt +++ b/user/src/main/kotlin/com/damaba/user/adapter/inbound/user/dto/UserResponse.kt @@ -1,6 +1,7 @@ package com.damaba.user.adapter.inbound.user.dto import com.damaba.user.domain.user.User +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import com.damaba.user.domain.user.constant.LoginType import io.swagger.v3.oas.annotations.media.Schema @@ -15,8 +16,8 @@ data class UserResponse( @Schema(description = "닉네임", example = "홍길동") val nickname: String, - @Schema(description = "프로필 이미지 url", example = "https://user-profile-image-url") - val profileImageUrl: String, + @Schema(description = "프로필 이미지") + val profileImage: UserProfileImage, @Schema(description = "성별") val gender: Gender, @@ -29,7 +30,7 @@ data class UserResponse( id = user.id, loginType = user.loginType, nickname = user.nickname, - profileImageUrl = user.profileImageUrl, + profileImage = user.profileImage, gender = user.gender, instagramId = user.instagramId, ) diff --git a/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepository.kt b/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepository.kt index cdb8af1..8f5a063 100644 --- a/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepository.kt +++ b/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepository.kt @@ -36,22 +36,22 @@ class UserCoreRepository( } override fun update(user: User): User { - val originalUser = getUserJpaEntityById(user.id) + val originalUserJpaEntity = getUserJpaEntityById(user.id) - if (originalUser.profileImageUrl != user.profileImageUrl) { - val originalProfileImage = userProfileImageJpaRepository.findByUrl(originalUser.profileImageUrl) + if (originalUserJpaEntity.profileImage.url != user.profileImage.url) { + val originalProfileImage = userProfileImageJpaRepository.findByUrl(originalUserJpaEntity.profileImage.url) originalProfileImage?.delete() userProfileImageJpaRepository.save( UserProfileImageJpaEntity( userId = user.id, - url = user.profileImageUrl, - name = extractProfileImageFileName(user.profileImageUrl), + name = user.profileImage.name, + url = user.profileImage.url, ), ) } - originalUser.update(user) - return originalUser.toDomain() + originalUserJpaEntity.update(user) + return originalUserJpaEntity.toDomain() } private fun findUserJpaEntityById(id: Long): UserJpaEntity? = @@ -59,9 +59,4 @@ class UserCoreRepository( private fun getUserJpaEntityById(id: Long): UserJpaEntity = userJpaRepository.findById(id).orElseThrow { UserNotFoundException() } - - // https://image.damaba.me/profile-image-1.jpg => profile-image-1 - private fun extractProfileImageFileName(profileImageUrl: String) = - profileImageUrl.substringBeforeLast(".") - .substringAfterLast("/") } diff --git a/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserJpaEntity.kt b/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserJpaEntity.kt index 3f50b14..22016ab 100644 --- a/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserJpaEntity.kt +++ b/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserJpaEntity.kt @@ -22,22 +22,10 @@ class UserJpaEntity( loginType: LoginType, oAuthLoginUid: String, nickname: String, - profileImageUrl: String, + profileImage: UserProfileImageJpaEmbeddable, gender: Gender, instagramId: String?, ) : BaseJpaTimeEntity() { - companion object { - fun from(user: User): UserJpaEntity = UserJpaEntity( - roles = user.roles, - loginType = user.loginType, - oAuthLoginUid = user.oAuthLoginUid, - nickname = user.nickname, - profileImageUrl = user.profileImageUrl, - gender = user.gender, - instagramId = user.instagramId, - ) - } - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) @@ -62,7 +50,7 @@ class UserJpaEntity( private set @Column(name = "profile_image_url", nullable = false) - var profileImageUrl: String = profileImageUrl + var profileImage: UserProfileImageJpaEmbeddable = profileImage private set @Enumerated(EnumType.STRING) @@ -80,7 +68,7 @@ class UserJpaEntity( oAuthLoginUid = this.oAuthLoginUid, loginType = this.loginType, nickname = this.nickname, - profileImageUrl = this.profileImageUrl, + profileImage = this.profileImage.toDomain(), gender = this.gender, instagramId = this.instagramId, ) @@ -89,6 +77,18 @@ class UserJpaEntity( this.nickname = user.nickname this.gender = user.gender this.instagramId = user.instagramId - this.profileImageUrl = user.profileImageUrl + this.profileImage = UserProfileImageJpaEmbeddable.from(user.profileImage) + } + + companion object { + fun from(user: User): UserJpaEntity = UserJpaEntity( + roles = user.roles, + loginType = user.loginType, + oAuthLoginUid = user.oAuthLoginUid, + nickname = user.nickname, + profileImage = UserProfileImageJpaEmbeddable.from(user.profileImage), + gender = user.gender, + instagramId = user.instagramId, + ) } } diff --git a/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserProfileImageJpaEmbeddable.kt b/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserProfileImageJpaEmbeddable.kt new file mode 100644 index 0000000..ea442f6 --- /dev/null +++ b/user/src/main/kotlin/com/damaba/user/adapter/outbound/user/UserProfileImageJpaEmbeddable.kt @@ -0,0 +1,23 @@ +package com.damaba.user.adapter.outbound.user + +import com.damaba.user.domain.user.UserProfileImage +import jakarta.persistence.Column +import jakarta.persistence.Embeddable + +@Embeddable +data class UserProfileImageJpaEmbeddable( + @Column(name = "profile_image_name", nullable = false) + val name: String, + + @Column(name = "profile_image_url", nullable = false) + val url: String, +) { + fun toDomain() = UserProfileImage(name, url) + + companion object { + fun from(userProfileImage: UserProfileImage) = UserProfileImageJpaEmbeddable( + name = userProfileImage.name, + url = userProfileImage.url, + ) + } +} diff --git a/user/src/main/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCase.kt b/user/src/main/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCase.kt index ce5de1b..41701af 100644 --- a/user/src/main/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCase.kt +++ b/user/src/main/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCase.kt @@ -1,6 +1,7 @@ package com.damaba.user.application.port.inbound.user import com.damaba.user.domain.user.User +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.UserValidator import com.damaba.user.domain.user.constant.Gender @@ -12,7 +13,7 @@ interface UpdateMyInfoUseCase { val nickname: String, val gender: Gender, val instagramId: String?, - val profileImageUrl: String, + val profileImage: UserProfileImage, ) { init { UserValidator.validateUserNickname(nickname) diff --git a/user/src/main/kotlin/com/damaba/user/application/service/user/UserService.kt b/user/src/main/kotlin/com/damaba/user/application/service/user/UserService.kt index 997adfa..c4d084b 100644 --- a/user/src/main/kotlin/com/damaba/user/application/service/user/UserService.kt +++ b/user/src/main/kotlin/com/damaba/user/application/service/user/UserService.kt @@ -40,15 +40,15 @@ class UserService( throw NicknameAlreadyExistsException(command.nickname) } - if (user.profileImageUrl != command.profileImageUrl) { - publishEventPort.publish(DeleteFileEvent(url = user.profileImageUrl)) + if (user.profileImage != command.profileImage) { + publishEventPort.publish(DeleteFileEvent(url = user.profileImage.url)) } user.update( nickname = command.nickname, gender = command.gender, instagramId = command.instagramId, - profileImageUrl = command.profileImageUrl, + profileImage = command.profileImage, ) return updateUserPort.update(user) } diff --git a/user/src/main/kotlin/com/damaba/user/domain/user/User.kt b/user/src/main/kotlin/com/damaba/user/domain/user/User.kt index c6f7c2f..8d3e3d8 100644 --- a/user/src/main/kotlin/com/damaba/user/domain/user/User.kt +++ b/user/src/main/kotlin/com/damaba/user/domain/user/User.kt @@ -11,14 +11,14 @@ class User( val loginType: LoginType, val oAuthLoginUid: String, nickname: String, - profileImageUrl: String, + profileImage: UserProfileImage, gender: Gender, instagramId: String?, ) { var nickname: String = nickname private set - var profileImageUrl: String = profileImageUrl + var profileImage: UserProfileImage = profileImage private set var gender: Gender = gender @@ -34,12 +34,12 @@ class User( nickname: String, gender: Gender, instagramId: String?, - profileImageUrl: String, + profileImage: UserProfileImage, ) { this.nickname = nickname this.gender = gender this.instagramId = instagramId - this.profileImageUrl = profileImageUrl + this.profileImage = profileImage } override fun equals(other: Any?): Boolean { @@ -52,7 +52,10 @@ class User( companion object { val DEFAULT_GENDER = Gender.UNDEFINED - const val DEFAULT_PROFILE_IMAGE_URL = "https://dummyimage.com/244x100.png/cc0000/ffffff" + val DEFAULT_PROFILE_IMAGE = UserProfileImage( + name = "default-user-profile-image.jpg", + url = "https://dummyimage.com/244x100.png/cc0000/ffffff", + ) fun create(loginType: LoginType, oAuthLoginUid: String, nickname: String): User = User( id = 0, @@ -60,7 +63,7 @@ class User( loginType = loginType, oAuthLoginUid = oAuthLoginUid, nickname = nickname, - profileImageUrl = DEFAULT_PROFILE_IMAGE_URL, + profileImage = DEFAULT_PROFILE_IMAGE, gender = DEFAULT_GENDER, instagramId = null, ) diff --git a/user/src/main/kotlin/com/damaba/user/domain/user/UserProfileImage.kt b/user/src/main/kotlin/com/damaba/user/domain/user/UserProfileImage.kt new file mode 100644 index 0000000..1635b51 --- /dev/null +++ b/user/src/main/kotlin/com/damaba/user/domain/user/UserProfileImage.kt @@ -0,0 +1,6 @@ +package com.damaba.user.domain.user + +data class UserProfileImage( + val name: String, + val url: String, +) diff --git a/user/src/test/kotlin/com/damaba/user/DamabaUserTestApplication.kt b/user/src/test/kotlin/com/damaba/user/DamabaUserTestApplication.kt index a77d384..7159b6c 100644 --- a/user/src/test/kotlin/com/damaba/user/DamabaUserTestApplication.kt +++ b/user/src/test/kotlin/com/damaba/user/DamabaUserTestApplication.kt @@ -1,7 +1,6 @@ package com.damaba.user import com.damaba.user.property.AuthProperties -import com.damaba.user.property.DamabaProperties import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.cloud.openfeign.EnableFeignClients @@ -10,8 +9,5 @@ import org.springframework.test.context.ActiveProfiles @ActiveProfiles("test") @SpringBootApplication(scanBasePackages = ["com.damaba"]) @EnableFeignClients -@EnableConfigurationProperties( - DamabaProperties::class, - AuthProperties::class, -) +@EnableConfigurationProperties(AuthProperties::class) class DamabaUserTestApplication diff --git a/user/src/test/kotlin/com/damaba/user/adapter/inbound/user/UserControllerTest.kt b/user/src/test/kotlin/com/damaba/user/adapter/inbound/user/UserControllerTest.kt index 2a7eb55..5372d1c 100644 --- a/user/src/test/kotlin/com/damaba/user/adapter/inbound/user/UserControllerTest.kt +++ b/user/src/test/kotlin/com/damaba/user/adapter/inbound/user/UserControllerTest.kt @@ -5,6 +5,7 @@ import com.damaba.user.application.port.inbound.user.CheckNicknameExistenceUseCa import com.damaba.user.application.port.inbound.user.GetMyInfoUseCase import com.damaba.user.application.port.inbound.user.UpdateMyInfoUseCase import com.damaba.user.config.ControllerTestConfig +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import com.damaba.user.util.RandomTestUtils.Companion.randomBoolean import com.damaba.user.util.RandomTestUtils.Companion.randomLong @@ -77,7 +78,7 @@ class UserControllerTest @Autowired constructor( nickname = randomString(len = 7), gender = Gender.FEMALE, instagramId = randomString(), - profileImageUrl = randomUrl(), + profileImage = UserProfileImage(randomString(), randomUrl()), ) val expectedResult = createUser( id = requestUser.id, @@ -98,7 +99,8 @@ class UserControllerTest @Autowired constructor( .andExpect(jsonPath("$.nickname").value(expectedResult.nickname)) .andExpect(jsonPath("$.gender").value(expectedResult.gender.toString())) .andExpect(jsonPath("$.instagramId").value(expectedResult.instagramId)) - .andExpect(jsonPath("$.profileImageUrl").value(expectedResult.profileImageUrl)) + .andExpect(jsonPath("$.profileImage.name").value(expectedResult.profileImage.name)) + .andExpect(jsonPath("$.profileImage.url").value(expectedResult.profileImage.url)) verify { updateMyInfoUseCase.updateMyInfo(request.toCommand(requestUser.id)) } } diff --git a/user/src/test/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepositoryTest.kt b/user/src/test/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepositoryTest.kt index c30f9f1..8b09af1 100644 --- a/user/src/test/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepositoryTest.kt +++ b/user/src/test/kotlin/com/damaba/user/adapter/outbound/user/UserCoreRepositoryTest.kt @@ -1,8 +1,10 @@ package com.damaba.user.adapter.outbound.user +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.exception.UserNotFoundException import com.damaba.user.util.RandomTestUtils.Companion.randomLong import com.damaba.user.util.RandomTestUtils.Companion.randomString +import com.damaba.user.util.RandomTestUtils.Companion.randomUrl import com.damaba.user.util.TestFixture.createUser import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable @@ -147,21 +149,22 @@ class UserCoreRepositoryTest @Autowired constructor( assertThat(updatedUser.nickname).isEqualTo(originalUser.nickname) assertThat(updatedUser.gender).isEqualTo(originalUser.gender) assertThat(updatedUser.instagramId).isEqualTo(originalUser.instagramId) - assertThat(updatedUser.profileImageUrl).isEqualTo(originalUser.profileImageUrl) + assertThat(updatedUser.profileImage).isEqualTo(originalUser.profileImage) } @Test fun `갱신할 유저 정보가 주어지고, 유저를 업데이트하면, 수정된 유저 정보가 반환된다`() { // given + val profileImage = UserProfileImage(randomString(), randomUrl()) val originalUser = - userCoreRepository.save(createUser(profileImageUrl = "https://file.test/original-image.jpg")) + userCoreRepository.save(createUser(profileImage = profileImage)) // when val result = userCoreRepository.update( createUser( id = originalUser.id, - profileImageUrl = "https://file.test/new-image.jpg", + profileImage = profileImage, ), ) @@ -171,31 +174,46 @@ class UserCoreRepositoryTest @Autowired constructor( assertThat(result.nickname).isEqualTo(updatedUser.nickname) assertThat(result.gender).isEqualTo(updatedUser.gender) assertThat(result.instagramId).isEqualTo(updatedUser.instagramId) - assertThat(result.profileImageUrl).isEqualTo(updatedUser.profileImageUrl) + assertThat(result.profileImage).isEqualTo(updatedUser.profileImage) + } + + @Test + fun `갱신할 유저 정보와 새로운 프로필 이미지가 주어지고, 유저를 업데이트하면, 수정된 유저 정보가 반환된다`() { + // given + val originalProfileImage = UserProfileImage("original-image.jpg", "https://file.test/original-image.jpg") + val newProfileImage = UserProfileImage("new-image.jpg", "https://file.test/new-image.jpg") + val originalUser = userCoreRepository.save(createUser(profileImage = originalProfileImage)) + + // when + val result = + userCoreRepository.update(createUser(id = originalUser.id, profileImage = newProfileImage)) + + // then + val updatedUser = userCoreRepository.getById(originalUser.id) + assertThat(result).isEqualTo(updatedUser) + assertThat(result.nickname).isEqualTo(updatedUser.nickname) + assertThat(result.gender).isEqualTo(updatedUser.gender) + assertThat(result.instagramId).isEqualTo(updatedUser.instagramId) + assertThat(result.profileImage).isEqualTo(updatedUser.profileImage) } @Test fun `갱신할 유저 정보와 새로운 프로필 이미지가 주어지고, 유저를 업데이트하면, 수정된 유저 정보가 반환되고 기존 프로필 이미지는 삭제된다`() { // given - val originalUser = userCoreRepository.save( - createUser(profileImageUrl = "https://file.test/original-image.jpg"), - ) + val originalProfileImage = UserProfileImage("original-image.jpg", "https://file.test/original-image.jpg") + val newProfileImage = UserProfileImage("new-image.jpg", "https://file.test/new-image.jpg") + val originalUser = userCoreRepository.save(createUser(profileImage = originalProfileImage)) userProfileImageJpaRepository.save( UserProfileImageJpaEntity( userId = originalUser.id, - url = originalUser.profileImageUrl, - name = "original-image", + name = originalProfileImage.name, + url = originalProfileImage.url, ), ) // when val result = - userCoreRepository.update( - createUser( - id = originalUser.id, - profileImageUrl = "https://file.test/new-image.jpg", - ), - ) + userCoreRepository.update(createUser(id = originalUser.id, profileImage = newProfileImage)) // then val updatedUser = userCoreRepository.getById(originalUser.id) @@ -203,9 +221,9 @@ class UserCoreRepositoryTest @Autowired constructor( assertThat(result.nickname).isEqualTo(updatedUser.nickname) assertThat(result.gender).isEqualTo(updatedUser.gender) assertThat(result.instagramId).isEqualTo(updatedUser.instagramId) - assertThat(result.profileImageUrl).isEqualTo(updatedUser.profileImageUrl) + assertThat(result.profileImage).isEqualTo(updatedUser.profileImage) - val foundOriginalProfileImage = userProfileImageJpaRepository.findByUrl(originalUser.profileImageUrl) + val foundOriginalProfileImage = userProfileImageJpaRepository.findByUrl(originalUser.profileImage.url) assertThat(foundOriginalProfileImage).isNull() } } diff --git a/user/src/test/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCaseCommandTest.kt b/user/src/test/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCaseCommandTest.kt index 19367cd..b9bf3d2 100644 --- a/user/src/test/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCaseCommandTest.kt +++ b/user/src/test/kotlin/com/damaba/user/application/port/inbound/user/UpdateMyInfoUseCaseCommandTest.kt @@ -1,8 +1,10 @@ package com.damaba.user.application.port.inbound.user import com.damaba.common_exception.ValidationException +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import com.damaba.user.util.RandomTestUtils.Companion.randomString +import com.damaba.user.util.RandomTestUtils.Companion.randomUrl import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable import kotlin.test.Test @@ -20,7 +22,7 @@ class UpdateMyInfoUseCaseCommandTest { nickname = invalidNickname, gender = Gender.MALE, instagramId = randomString(), - profileImageUrl = randomString(), + profileImage = UserProfileImage(randomString(), randomUrl()), ) } @@ -40,7 +42,7 @@ class UpdateMyInfoUseCaseCommandTest { nickname = randomString(len = 5), gender = Gender.MALE, instagramId = invalidInstagramId, - profileImageUrl = randomString(), + profileImage = UserProfileImage(randomString(), randomUrl()), ) } diff --git a/user/src/test/kotlin/com/damaba/user/application/service/user/UserServiceTest.kt b/user/src/test/kotlin/com/damaba/user/application/service/user/UserServiceTest.kt index 89d572a..887e785 100644 --- a/user/src/test/kotlin/com/damaba/user/application/service/user/UserServiceTest.kt +++ b/user/src/test/kotlin/com/damaba/user/application/service/user/UserServiceTest.kt @@ -1,13 +1,13 @@ package com.damaba.user.application.service.user import com.damaba.common_file.domain.DeleteFileEvent -import com.damaba.common_file.domain.File import com.damaba.user.application.port.inbound.user.CheckNicknameExistenceUseCase import com.damaba.user.application.port.inbound.user.UpdateMyInfoUseCase import com.damaba.user.application.port.outbound.common.PublishEventPort import com.damaba.user.application.port.outbound.user.CheckNicknameExistencePort import com.damaba.user.application.port.outbound.user.GetUserPort import com.damaba.user.application.port.outbound.user.UpdateUserPort +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import com.damaba.user.domain.user.exception.NicknameAlreadyExistsException import com.damaba.user.util.RandomTestUtils.Companion.randomBoolean @@ -79,14 +79,13 @@ class UserServiceTest { val newNickname = randomString(len = 7) val newGender = Gender.FEMALE val newInstagramId = null - val newProfileImageUrl = randomUrl() - val uploadedFile = File(randomString(), randomString()) + val newProfileImageUrl = UserProfileImage(randomString(), randomUrl()) val command = UpdateMyInfoUseCase.Command(userId, newNickname, newGender, newInstagramId, newProfileImageUrl) val expectedResult = createUser( nickname = newNickname, gender = newGender, instagramId = newInstagramId, - profileImageUrl = uploadedFile.url, + profileImage = newProfileImageUrl, ) every { getUserPort.getById(userId) } returns user every { checkNicknameExistencePort.doesNicknameExist(newNickname) } returns false @@ -109,7 +108,7 @@ class UserServiceTest { assertThat(actualResult.nickname).isEqualTo(expectedResult.nickname) assertThat(actualResult.gender).isEqualTo(expectedResult.gender) assertThat(actualResult.instagramId).isEqualTo(expectedResult.instagramId) - assertThat(actualResult.profileImageUrl).isEqualTo(expectedResult.profileImageUrl) + assertThat(actualResult.profileImage).isEqualTo(expectedResult.profileImage) } @Test @@ -118,12 +117,12 @@ class UserServiceTest { val userId = randomLong() val user = createUser(id = userId) val newNickname = randomString(len = 7) - val command = UpdateMyInfoUseCase.Command(userId, newNickname, user.gender, user.instagramId, user.profileImageUrl) + val command = UpdateMyInfoUseCase.Command(userId, newNickname, user.gender, user.instagramId, user.profileImage) val expectedResult = createUser( nickname = newNickname, gender = user.gender, instagramId = user.instagramId, - profileImageUrl = user.profileImageUrl, + profileImage = user.profileImage, ) every { getUserPort.getById(userId) } returns user every { checkNicknameExistencePort.doesNicknameExist(newNickname) } returns false @@ -143,7 +142,7 @@ class UserServiceTest { assertThat(actualResult.nickname).isEqualTo(expectedResult.nickname) assertThat(actualResult.gender).isEqualTo(expectedResult.gender) assertThat(actualResult.instagramId).isEqualTo(expectedResult.instagramId) - assertThat(actualResult.profileImageUrl).isEqualTo(expectedResult.profileImageUrl) + assertThat(actualResult.profileImage).isEqualTo(expectedResult.profileImage) } @Test @@ -151,13 +150,14 @@ class UserServiceTest { // given val userId = randomLong() val user = createUser(id = userId) - val newProfileImageUrl = randomUrl() - val command = UpdateMyInfoUseCase.Command(userId, user.nickname, user.gender, user.instagramId, newProfileImageUrl) + val newProfileImageUrl = UserProfileImage(randomString(), randomUrl()) + val command = + UpdateMyInfoUseCase.Command(userId, user.nickname, user.gender, user.instagramId, newProfileImageUrl) val expectedResult = createUser( nickname = user.nickname, gender = user.gender, instagramId = user.instagramId, - profileImageUrl = newProfileImageUrl, + profileImage = newProfileImageUrl, ) every { getUserPort.getById(userId) } returns user every { publishEventPort.publish(any(DeleteFileEvent::class)) } just Runs @@ -177,7 +177,7 @@ class UserServiceTest { assertThat(actualResult.nickname).isEqualTo(expectedResult.nickname) assertThat(actualResult.gender).isEqualTo(expectedResult.gender) assertThat(actualResult.instagramId).isEqualTo(expectedResult.instagramId) - assertThat(actualResult.profileImageUrl).isEqualTo(expectedResult.profileImageUrl) + assertThat(actualResult.profileImage).isEqualTo(expectedResult.profileImage) } @Test @@ -185,7 +185,13 @@ class UserServiceTest { // given val userId = randomLong() val existingNickname = randomString(len = 7) - val command = UpdateMyInfoUseCase.Command(userId, existingNickname, Gender.FEMALE, randomString(), randomUrl()) + val command = UpdateMyInfoUseCase.Command( + userId, + existingNickname, + Gender.FEMALE, + randomString(), + UserProfileImage(randomString(), randomUrl()), + ) every { getUserPort.getById(userId) } returns createUser(id = userId) every { checkNicknameExistencePort.doesNicknameExist(existingNickname) } returns true diff --git a/user/src/test/kotlin/com/damaba/user/domain/user/UserTest.kt b/user/src/test/kotlin/com/damaba/user/domain/user/UserTest.kt index a7f2dc4..de378ac 100644 --- a/user/src/test/kotlin/com/damaba/user/domain/user/UserTest.kt +++ b/user/src/test/kotlin/com/damaba/user/domain/user/UserTest.kt @@ -4,6 +4,7 @@ import com.damaba.user.domain.user.constant.Gender import com.damaba.user.domain.user.constant.LoginType import com.damaba.user.domain.user.constant.UserRoleType import com.damaba.user.util.RandomTestUtils.Companion.randomString +import com.damaba.user.util.RandomTestUtils.Companion.randomUrl import com.damaba.user.util.TestFixture.createUser import org.assertj.core.api.Assertions.assertThat import kotlin.test.Test @@ -25,7 +26,7 @@ class UserTest { assertThat(userCreated.loginType).isEqualTo(loginType) assertThat(userCreated.oAuthLoginUid).isEqualTo(oAuthLoginUid) assertThat(userCreated.nickname).isEqualTo(nickname) - assertThat(userCreated.profileImageUrl).isEqualTo(User.DEFAULT_PROFILE_IMAGE_URL) + assertThat(userCreated.profileImage).isEqualTo(User.DEFAULT_PROFILE_IMAGE) assertThat(userCreated.gender).isEqualTo(User.DEFAULT_GENDER) assertThat(userCreated.instagramId).isNull() @@ -40,21 +41,21 @@ class UserTest { val newNickname = randomString() val newGender = Gender.FEMALE val newInstagramId = randomString() - val newProfileImageUrl = randomString() + val newProfileImage = UserProfileImage(randomString(), randomUrl()) // when user.update( nickname = newNickname, gender = newGender, instagramId = newInstagramId, - profileImageUrl = newProfileImageUrl, + profileImage = newProfileImage, ) // then assertThat(user.nickname).isEqualTo(newNickname) assertThat(user.gender).isEqualTo(newGender) assertThat(user.instagramId).isEqualTo(newInstagramId) - assertThat(user.profileImageUrl).isEqualTo(newProfileImageUrl) + assertThat(user.profileImage).isEqualTo(newProfileImage) } @Test diff --git a/user/src/test/kotlin/com/damaba/user/util/TestFixture.kt b/user/src/test/kotlin/com/damaba/user/util/TestFixture.kt index ea963bc..ccb28f7 100644 --- a/user/src/test/kotlin/com/damaba/user/util/TestFixture.kt +++ b/user/src/test/kotlin/com/damaba/user/util/TestFixture.kt @@ -2,11 +2,13 @@ package com.damaba.user.util import com.damaba.user.domain.auth.AuthToken import com.damaba.user.domain.user.User +import com.damaba.user.domain.user.UserProfileImage import com.damaba.user.domain.user.constant.Gender import com.damaba.user.domain.user.constant.LoginType import com.damaba.user.domain.user.constant.UserRoleType import com.damaba.user.util.RandomTestUtils.Companion.randomLong import com.damaba.user.util.RandomTestUtils.Companion.randomString +import com.damaba.user.util.RandomTestUtils.Companion.randomUrl import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.core.Authentication import org.springframework.security.core.authority.SimpleGrantedAuthority @@ -29,7 +31,7 @@ object TestFixture { oAuthLoginUid: String = randomString(), loginType: LoginType = LoginType.KAKAO, nickname: String = randomString(len = 7), - profileImageUrl: String = randomString(), + profileImage: UserProfileImage = UserProfileImage(randomString(), randomUrl()), gender: Gender = Gender.MALE, instagramId: String? = randomString(len = 30), ): User = User( @@ -38,7 +40,7 @@ object TestFixture { oAuthLoginUid = oAuthLoginUid, loginType = loginType, nickname = nickname, - profileImageUrl = profileImageUrl, + profileImage = profileImage, gender = gender, instagramId = instagramId, )