-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66c9ec2
commit f9e5661
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/kotlin/com/trip/safe/user/service/UserServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.trip.safe.user.service | ||
|
||
import com.trip.safe.common.security.jwt.JwtTokenProvider | ||
import com.trip.safe.user.domain.User | ||
import com.trip.safe.user.domain.UserRepository | ||
import com.trip.safe.user.exception.UserExistException | ||
import com.trip.safe.user.presentation.dto.request.UserSignUpRequest | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.assertDoesNotThrow | ||
import org.junit.jupiter.api.assertThrows | ||
import org.springframework.security.crypto.password.PasswordEncoder | ||
|
||
class UserServiceTest : DescribeSpec( | ||
{ | ||
val userRepository = mockk<UserRepository>(relaxed = true) | ||
val jwtTokenProvider = mockk<JwtTokenProvider>(relaxed = true) | ||
val passwordEncoder = mockk<PasswordEncoder>(relaxed = true) | ||
val userService = UserService(userRepository, jwtTokenProvider, passwordEncoder) | ||
val requestStub = UserSignUpRequest("testAccountId", "testPassword", 20) | ||
|
||
describe("유저가 회원가입을 하는 경우") { | ||
context("이미 존재하는 유저이면") { | ||
coEvery { userRepository.existsByAccountId(requestStub.accountId) } returns true | ||
it("UserExistException을 던진다.") { | ||
assertThrows<UserExistException> { userService.signUp(requestStub) } | ||
coVerify(exactly = 0) { userRepository.save(any()) } | ||
} | ||
} | ||
|
||
context("존재하지 않는 유저이면") { | ||
coEvery { userRepository.existsByAccountId(requestStub.accountId) } returns false | ||
coEvery { passwordEncoder.encode(requestStub.password) } returns requestStub.password | ||
it("회원가입에 성공한다.") { | ||
assertDoesNotThrow { userService.signUp(requestStub) } | ||
coVerify(exactly = 1) { userRepository.save(any()) } | ||
} | ||
} | ||
} | ||
} | ||
) |