-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
1 changed file
with
122 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...tion/src/test/kotlin/team/comit/simtong/domain/user/usecase/ChangePasswordUseCaseTests.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,122 @@ | ||
package team.comit.simtong.domain.user.usecase | ||
|
||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertDoesNotThrow | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.BDDMockito.given | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import team.comit.simtong.domain.user.dto.ChangePasswordRequest | ||
import team.comit.simtong.domain.user.exception.DifferentPasswordException | ||
import team.comit.simtong.domain.user.exception.UserNotFoundException | ||
import team.comit.simtong.domain.user.model.Authority | ||
import team.comit.simtong.domain.user.model.User | ||
import team.comit.simtong.domain.user.spi.CommandUserPort | ||
import team.comit.simtong.domain.user.spi.QueryUserPort | ||
import team.comit.simtong.domain.user.spi.UserSecurityPort | ||
import java.util.UUID | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class ChangePasswordUseCaseTests { | ||
|
||
@MockBean | ||
private lateinit var queryUserPort: QueryUserPort | ||
|
||
@MockBean | ||
private lateinit var userSecurityPort: UserSecurityPort | ||
|
||
@MockBean | ||
private lateinit var commandUserPort: CommandUserPort | ||
|
||
private lateinit var changePasswordUseCase: ChangePasswordUseCase | ||
|
||
private val id = UUID.randomUUID() | ||
|
||
private val userStub: User by lazy { | ||
User( | ||
id = id, | ||
nickname = "test nickname", | ||
name = "test name", | ||
email = "[email protected]", | ||
password = "test password", | ||
employeeNumber = 1234567890, | ||
authority = Authority.ROLE_COMMON, | ||
spotId = UUID.randomUUID(), | ||
teamId = UUID.randomUUID(), | ||
profileImagePath = "test profile image path" | ||
) | ||
} | ||
|
||
private val requestStub: ChangePasswordRequest by lazy { | ||
ChangePasswordRequest( | ||
password = "test password", | ||
newPassword = "test new password" | ||
) | ||
} | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
changePasswordUseCase = ChangePasswordUseCase( | ||
queryUserPort, | ||
userSecurityPort, | ||
commandUserPort | ||
) | ||
} | ||
|
||
@Test | ||
fun `비밀번호 변경 성공`() { | ||
// given | ||
given(userSecurityPort.getCurrentUserId()) | ||
.willReturn(id) | ||
|
||
given(queryUserPort.queryUserById(id)) | ||
.willReturn(userStub) | ||
|
||
given(userSecurityPort.compare(requestStub.password, userStub.password)) | ||
.willReturn(true) | ||
|
||
given(userSecurityPort.encode(requestStub.newPassword)) | ||
.willReturn(requestStub.newPassword) | ||
|
||
// when & then | ||
assertDoesNotThrow { | ||
changePasswordUseCase.execute(requestStub) | ||
} | ||
} | ||
|
||
@Test | ||
fun `유저 찾기 실패`() { | ||
// given | ||
given(userSecurityPort.getCurrentUserId()) | ||
.willReturn(id) | ||
|
||
given(queryUserPort.queryUserById(id)) | ||
.willReturn(null) | ||
|
||
// when & then | ||
assertThrows<UserNotFoundException> { | ||
changePasswordUseCase.execute(requestStub) | ||
} | ||
} | ||
|
||
@Test | ||
fun `비밀번호 불일치`() { | ||
// given | ||
given(userSecurityPort.getCurrentUserId()) | ||
.willReturn(id) | ||
|
||
given(queryUserPort.queryUserById(id)) | ||
.willReturn(userStub) | ||
|
||
given(userSecurityPort.compare(requestStub.password, userStub.password)) | ||
.willReturn(false) | ||
|
||
// when & then | ||
assertThrows<DifferentPasswordException> { | ||
changePasswordUseCase.execute(requestStub) | ||
} | ||
} | ||
|
||
} |