-
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
d38d2c8
commit b2439ff
Showing
5 changed files
with
38 additions
and
39 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
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
31 changes: 18 additions & 13 deletions
31
...t/java/com/inq/wishhair/wesharewishhair/auth/presentation/TokenReissueControllerTest.java
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 |
---|---|---|
@@ -1,51 +1,56 @@ | ||
package com.inq.wishhair.wesharewishhair.auth.presentation; | ||
|
||
import static com.inq.wishhair.wesharewishhair.common.fixture.AuthFixture.*; | ||
import static org.mockito.BDDMockito.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import com.inq.wishhair.wesharewishhair.auth.application.TokenReissueService; | ||
import com.inq.wishhair.wesharewishhair.auth.application.dto.response.TokenResponse; | ||
import com.inq.wishhair.wesharewishhair.auth.domain.TokenRepository; | ||
import com.inq.wishhair.wesharewishhair.auth.domain.entity.Token; | ||
import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport; | ||
import com.inq.wishhair.wesharewishhair.user.domain.UserRepository; | ||
import com.inq.wishhair.wesharewishhair.user.domain.entity.User; | ||
import com.inq.wishhair.wesharewishhair.user.fixture.UserFixture; | ||
|
||
@DisplayName("[TokenReissueController 테스트] - API") | ||
class TokenReissueControllerTest extends ApiTestSupport { | ||
|
||
private static final String REISSUE_TOKEN_URL = "/api/token/reissue"; | ||
private static final String REISSUE_TOKEN_URL = "/api/tokens/reissue"; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@MockBean | ||
private TokenReissueService tokenReissueService; | ||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private TokenRepository tokenRepository; | ||
|
||
@Test | ||
@DisplayName("[토큰 재발급 API 를 호출한다]") | ||
void reissueToken() throws Exception { | ||
//given | ||
TokenResponse tokenResponse = new TokenResponse("accessToken", "refreshToken"); | ||
given(tokenReissueService.reissueToken(1L, TOKEN)) | ||
.willReturn(tokenResponse); | ||
User user = UserFixture.getFixedManUser(); | ||
Long userId = userRepository.save(user).getId(); | ||
|
||
String token = getAccessToken(userId); | ||
tokenRepository.save(Token.issue(userId, token)); | ||
|
||
//when | ||
ResultActions result = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.post(REISSUE_TOKEN_URL) | ||
.header(AUTHORIZATION, ACCESS_TOKEN) | ||
.header(AUTHORIZATION, BEARER + token) | ||
); | ||
|
||
//then | ||
result.andExpectAll( | ||
status().isOk(), | ||
jsonPath("$.accessToken").value(tokenResponse.accessToken()), | ||
jsonPath("$.refreshToken").value(tokenResponse.refreshToken()) | ||
jsonPath("$.accessToken").exists(), | ||
jsonPath("$.refreshToken").exists() | ||
); | ||
} | ||
} |
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
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