Skip to content
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

refactor : 회원가입 로직 수정 #161

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bamyanggang.domainmodule.domain.user.exception

import com.bamyanggang.commonmodule.exception.CustomException

sealed class UserException(
errorCode: Int,
message: String,
) : CustomException(CODE_PREFIX, errorCode, message) {

class DuplicatedUser(message: String = "이미 존재하는 유저입니다.") :
UserException(errorCode = 1, message = message)

companion object {
const val CODE_PREFIX = "USER"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface UserRepository {

fun findById(userId: UUID): User

}
fun existsBySocialId(socialId: String): Boolean

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bamyanggang.domainmodule.domain.user.service

import com.bamyanggang.domainmodule.domain.user.aggregate.User
import com.bamyanggang.domainmodule.domain.user.enums.SocialLoginProvider
import com.bamyanggang.domainmodule.domain.user.exception.UserException
import com.bamyanggang.domainmodule.domain.user.repository.UserRepository

class UserAppender(
Expand All @@ -18,6 +19,7 @@ class UserAppender(
goal: String?,
dream: String?
): User {
if(userRepository.existsBySocialId(socialId)) {throw UserException.DuplicatedUser()}
return User.create(
socialId = socialId,
profileImgUrl = profileImgUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.bamyanggang.domainmodule.domain.user.service

import com.bamyanggang.domainmodule.domain.user.enums.SocialLoginProvider
import com.bamyanggang.domainmodule.domain.user.exception.UserException
import com.bamyanggang.domainmodule.domain.user.repository.UserRepository
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify

class UserAppenderTest : BehaviorSpec({
val mockUserRepository = mockk<UserRepository>(relaxed = true)
val userAppender = UserAppender(mockUserRepository)
val socialId = "socialId"
val profileImgUrl = "profileImgUrl"
val provider = SocialLoginProvider.KAKAO
val email = "email"
val nickName = "nickName"
val jobSearchStatus = "jobSearchStatus"
val desiredJob = "desiredJob"
val goal = "goal"
val dream = "dream"

Given("a social id, profile image url, provider, email, nickname, job search status, desired job, goal, and dream") {
every { mockUserRepository.existsBySocialId(socialId) } returns false

When("appendUser is called") {
userAppender.appendUser(socialId, profileImgUrl, provider, email, nickName, jobSearchStatus, desiredJob, goal, dream)

Then("a new user should be created and saved") {
verify { mockUserRepository.existsBySocialId(socialId) }
verify { mockUserRepository.save(any()) }
}
}
}

Given("a social id that already exists") {
every { mockUserRepository.existsBySocialId(socialId) } returns true

When("appendUser is called") {
val exception = shouldThrow<UserException.DuplicatedUser> {
userAppender.appendUser(socialId, profileImgUrl, provider, email, nickName, jobSearchStatus, desiredJob, goal, dream)
}

Then("a DuplicatedUser exception should be thrown") {
verify { mockUserRepository.existsBySocialId(socialId) }
assert(exception.message == "이미 존재하는 유저입니다.")
}
}
}

})
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ public User findBySocialId(String socialId) {
}

@Override
public User findById(@NotNull UUID userId) {
public User findById(UUID userId) {
return userJpaRepository.findByUserId(userId)
.map(userMapper::toDomainEntity)
.orElseThrow(() -> new PersistenceException.NotFound());
}
}

@Override
public boolean existsBySocialId(String socialId) {
return userJpaRepository.existsBySocialId(socialId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface UserJpaRepository extends JpaRepository<UserJpaEntity, UUID> {

Optional<UserJpaEntity> findByUserId(UUID id);

boolean existsBySocialId(String socialId);

}
Loading