Skip to content

Commit 0a74a68

Browse files
authored
AuthControllerTest fix (#122)
1 parent 121645a commit 0a74a68

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/test/kotlin/com/back/koreaTravelGuide/domain/auth/controller/AuthControllerTest.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import com.back.koreaTravelGuide.domain.user.enums.UserRole
66
import com.back.koreaTravelGuide.domain.user.repository.UserRepository
77
import com.fasterxml.jackson.databind.ObjectMapper
88
import jakarta.servlet.http.Cookie
9-
import org.junit.jupiter.api.Assertions.assertTrue
109
import org.junit.jupiter.api.BeforeEach
1110
import org.junit.jupiter.api.DisplayName
1211
import org.junit.jupiter.api.Test
12+
import org.mockito.Mockito
1313
import org.springframework.beans.factory.annotation.Autowired
1414
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
1515
import org.springframework.boot.test.context.SpringBootTest
1616
import org.springframework.context.annotation.Import
1717
import org.springframework.data.redis.core.RedisTemplate
18+
import org.springframework.data.redis.core.ValueOperations
1819
import org.springframework.http.MediaType
1920
import org.springframework.test.context.ActiveProfiles
2021
import org.springframework.test.web.servlet.MockMvc
@@ -47,6 +48,8 @@ class AuthControllerTest {
4748
@Autowired
4849
private lateinit var objectMapper: ObjectMapper
4950

51+
private lateinit var valueOperations: ValueOperations<String, String>
52+
5053
private lateinit var pendingUser: User
5154
private lateinit var generalUser: User
5255

@@ -73,6 +76,8 @@ class AuthControllerTest {
7376
oauthId = "test5678",
7477
),
7578
)
79+
80+
valueOperations = redisTemplate.opsForValue()
7681
}
7782

7883
@Test
@@ -100,6 +105,7 @@ class AuthControllerTest {
100105
fun t2() {
101106
// given
102107
val accessToken = jwtTokenProvider.createAccessToken(generalUser.id!!, generalUser.role)
108+
val remainingTime = jwtTokenProvider.getRemainingTime(accessToken)
103109

104110
// when & then
105111
mockMvc.perform(
@@ -111,8 +117,9 @@ class AuthControllerTest {
111117
.andExpect(jsonPath("$.msg").value("로그아웃 되었습니다."))
112118

113119
// verify
114-
val isBlacklisted = redisTemplate.opsForValue().get(accessToken) != null
115-
assertTrue(isBlacklisted)
120+
Mockito.verify(
121+
valueOperations,
122+
).set(Mockito.eq(accessToken), Mockito.eq("logout"), Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS))
116123
}
117124

118125
@Test
@@ -121,7 +128,7 @@ class AuthControllerTest {
121128
// given
122129
val refreshToken = jwtTokenProvider.createRefreshToken(generalUser.id!!)
123130
val redisKey = "refreshToken:${generalUser.id}"
124-
redisTemplate.opsForValue().set(redisKey, refreshToken, 7, TimeUnit.DAYS)
131+
Mockito.`when`(valueOperations.get(redisKey)).thenReturn(refreshToken)
125132

126133
// when & then
127134
mockMvc.perform(

0 commit comments

Comments
 (0)