Skip to content

Commit

Permalink
Merge pull request #47 from inhooo00/feature/myPage
Browse files Browse the repository at this point in the history
Test: TokenProvider 목킹 의존성 주입 추가
  • Loading branch information
inhooo00 authored Jul 28, 2024
2 parents ed72453 + 3f17848 commit 876e87b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
package shop.kkeujeok.kkeujeokbackend.auth.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import shop.kkeujeok.kkeujeokbackend.auth.api.AuthController;
import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.RefreshTokenReqDto;
import shop.kkeujeok.kkeujeokbackend.auth.api.dto.request.TokenReqDto;
import shop.kkeujeok.kkeujeokbackend.auth.api.dto.response.MemberLoginResDto;
import shop.kkeujeok.kkeujeokbackend.auth.api.dto.response.UserInfo;
import shop.kkeujeok.kkeujeokbackend.auth.application.AuthMemberService;
import shop.kkeujeok.kkeujeokbackend.auth.application.AuthService;
import shop.kkeujeok.kkeujeokbackend.auth.application.AuthServiceFactory;
import shop.kkeujeok.kkeujeokbackend.auth.application.TokenService;
import shop.kkeujeok.kkeujeokbackend.common.annotation.ControllerTest;
import shop.kkeujeok.kkeujeokbackend.global.jwt.api.dto.TokenDto;
import shop.kkeujeok.kkeujeokbackend.member.domain.Member;
import shop.kkeujeok.kkeujeokbackend.member.domain.SocialType;
Expand All @@ -34,27 +22,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ActiveProfiles("test")
@WebMvcTest(AuthController.class)
public class AuthControllerTest {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@MockBean
private AuthServiceFactory authServiceFactory;

@MockBean
private AuthMemberService authMemberService;

@MockBean
private TokenService tokenService;

@Mock
private AuthService authService;
public class AuthControllerTest extends ControllerTest {

private Member member;

Expand All @@ -69,9 +37,9 @@ public void setUp() {
.build();
}


@DisplayName("로그인하면 accessToken과 refreshToken을 반환합니다.")
@Test
public void generateAccessAndRefreshToken_ShouldReturnToken() throws Exception {
public void 로그인하면_accessToken과_refreshToken을_반환합니다() throws Exception {
String provider = "google";
TokenReqDto tokenReqDto = new TokenReqDto("auth-code");
UserInfo userInfo = new UserInfo("email", "name", "picture", "nickname");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package shop.kkeujeok.kkeujeokbackend.common.annotation;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import shop.kkeujeok.kkeujeokbackend.auth.api.AuthController;
import shop.kkeujeok.kkeujeokbackend.auth.application.AuthMemberService;
import shop.kkeujeok.kkeujeokbackend.auth.application.AuthService;
import shop.kkeujeok.kkeujeokbackend.auth.application.AuthServiceFactory;
import shop.kkeujeok.kkeujeokbackend.auth.application.TokenService;
import shop.kkeujeok.kkeujeokbackend.block.api.BlockController;
import shop.kkeujeok.kkeujeokbackend.block.application.BlockService;
import shop.kkeujeok.kkeujeokbackend.global.jwt.TokenProvider;

@AutoConfigureRestDocs
@WebMvcTest({
BlockController.class
BlockController.class,
AuthController.class
})
@ActiveProfiles("test")
public abstract class ControllerTest {
Expand All @@ -25,4 +33,20 @@ public abstract class ControllerTest {

@MockBean
protected BlockService blockService;

@MockBean
protected TokenProvider tokenProvider;

@MockBean
protected AuthServiceFactory authServiceFactory;

@MockBean
protected AuthMemberService authMemberService;

@MockBean
protected TokenService tokenService;

@Mock
protected AuthService authService;

}

0 comments on commit 876e87b

Please sign in to comment.