Skip to content

Commit

Permalink
Merge pull request #198 from cgk95/hotfix/authtest
Browse files Browse the repository at this point in the history
fix :: interceptor 추가로 인한 테스트 코드 수정
  • Loading branch information
chan99k authored Feb 27, 2024
2 parents bf83dea + 5f88361 commit 33f942e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AuthController {
@GetMapping("/reissuanceJWT")
public ResponseEntity<ApiResponse<AuthDto>> reissuanceJWT(HttpServletRequest request){

return ApiResponse.toResponseEntity(SUCCESS_REQUEST_REGENERATED_JWT, AuthDto.of(authService.generateTokenAndSaveAuth(request.getHeader("Authorization"))));
return ApiResponse.toResponseEntity(SUCCESS_REQUEST_REGENERATED_JWT,
AuthDto.of(authService.generateTokenAndSaveAuth(request.getHeader("Authorization"))));
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
package com.kernel360.auth.controller;

import com.kernel360.common.ControllerTest;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.restdocs.payload.JsonFieldType;

import static com.kernel360.common.utils.RestDocumentUtils.getDocumentRequest;
import static com.kernel360.common.utils.RestDocumentUtils.getDocumentResponse;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.kernel360.common.ControllerTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;

@Disabled
@AutoConfigureWebMvc
class AuthControllerTest extends ControllerTest {


@Test
void 토큰_갱신요청이_왔을때_리스폰스로_상태코드201과_갱신토큰이_잘_보내지는지() throws Exception {
String requestToken = "token";
String resultToken = "reissuanceToken";

when(authService.generateTokenAndSaveAuth(requestToken)).thenReturn(resultToken);
when(acceptInterceptor.preHandle(any(), any(),
any())).thenReturn(true);

when(authService.generateTokenAndSaveAuth(requestToken))
.thenReturn(resultToken);

mockMvc.perform(get("/auth/reissuanceJWT")
.header("Authorization", requestToken))
Expand All @@ -37,15 +42,15 @@ class AuthControllerTest extends ControllerTest {
.andExpect(jsonPath("$.status").value(201))
.andExpect(jsonPath("$.code").value("BAC001"))
.andExpect(jsonPath("$.message").value("JWT 토큰 재발급 성공"))
.andDo(document("auth/reissuanceJWT",
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").description("상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("code").description("비즈니스 코드"),
fieldWithPath("value.jwtToken").type(JsonFieldType.STRING).description("JWT토큰")
)))
.andReturn();
.andDo(document("auth/reissuanceJWT",
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("status").description("상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("code").description("비즈니스 코드"),
fieldWithPath("value.jwtToken").type(JsonFieldType.STRING).description("JWT토큰")
)))
.andReturn();
}
}

0 comments on commit 33f942e

Please sign in to comment.