From d413ef91ca9ba8649884ec05b6bd37f610c256d9 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sun, 22 Oct 2023 16:00:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20test=20docs=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Mypage-API.adoc | 4 ++ .../presentation/MypageControllerTest.java | 69 +++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/docs/asciidoc/Mypage-API.adoc b/src/docs/asciidoc/Mypage-API.adoc index 58e5ef94..59e4d843 100644 --- a/src/docs/asciidoc/Mypage-API.adoc +++ b/src/docs/asciidoc/Mypage-API.adoc @@ -11,6 +11,10 @@ operation::mypage-controller-test/sign_out[snippets='http-request,http-response, === Mypage 회원탈퇴 operation::mypage-controller-test/withdraw[snippets='http-request,request-fields,http-response,response-fields'] +[[Mypage-전체-조회]] +=== Mypage 전체 조회 +operation::mypage-controller-test/get_mypage[snippets='http-request,http-response,response-fields'] + [[Mypage-프로필-조회]] === Mypage 프로필 조회 operation::mypage-controller-test/get_profile[snippets='http-request,http-response,response-fields'] diff --git a/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java b/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java index 277100a0..161680db 100644 --- a/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java +++ b/src/test/java/com/moing/backend/domain/mypage/presentation/MypageControllerTest.java @@ -3,18 +3,21 @@ import com.moing.backend.config.CommonControllerTest; import com.moing.backend.domain.mypage.application.dto.request.UpdateProfileRequest; import com.moing.backend.domain.mypage.application.dto.request.WithdrawRequest; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageResponse; +import com.moing.backend.domain.mypage.application.dto.response.GetMyPageTeamBlock; import com.moing.backend.domain.mypage.application.dto.response.GetProfileResponse; -import com.moing.backend.domain.mypage.application.service.AlarmUserCase; -import com.moing.backend.domain.mypage.application.service.ProfileUserCase; -import com.moing.backend.domain.mypage.application.service.SignOutUserCase; -import com.moing.backend.domain.mypage.application.service.WithdrawUserCase; +import com.moing.backend.domain.mypage.application.service.*; import com.moing.backend.domain.team.application.dto.response.CreateTeamResponse; +import com.moing.backend.domain.team.domain.constant.Category; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; +import java.util.ArrayList; +import java.util.List; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -37,6 +40,9 @@ public class MypageControllerTest extends CommonControllerTest { @MockBean private AlarmUserCase alarmUserCase; + @MockBean + private GetMyPageUserCase getMyPageUserCase; + @Test public void sign_out() throws Exception { //when @@ -101,6 +107,61 @@ public void withdraw() throws Exception { ); } + @Test + public void get_mypage() throws Exception{ + //given + List categoryList=new ArrayList<>(); + categoryList.add(Category.SPORTS); + + List getMyPageTeamBlocks=new ArrayList<>(); + GetMyPageTeamBlock blocks= GetMyPageTeamBlock.builder() + .teamId(1L) + .teamName("소모임이름") + .category(Category.SPORTS) + .build(); + getMyPageTeamBlocks.add(blocks); + + GetMyPageResponse output = GetMyPageResponse.builder() + .profileImage("PROFILE_IMAGE_URL") + .introduction("INTRODUCTION") + .nickName("NICKNAME") + .categories(categoryList) + .getMyPageTeamBlocks(getMyPageTeamBlocks) + .build(); + + given(getMyPageUserCase.getMyPageResponse(any())).willReturn(output); + + //when + ResultActions actions = mockMvc.perform( + get("/api/mypage") + .header("Authorization", "Bearer ACCESS_TOKEN") + .contentType(MediaType.APPLICATION_JSON) + ); + + + //then + actions + .andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("접근 토큰") + ), + responseFields( + fieldWithPath("isSuccess").description("true"), + fieldWithPath("message").description("마이페이지를 조회했습니다"), + fieldWithPath("data.profileImage").description("프로필 이미지 URL"), + fieldWithPath("data.nickName").description("닉네임"), + fieldWithPath("data.introduction").description("한줄 소개"), + fieldWithPath("data.categories[0]").description("내 열정의 불 해시태그"), + fieldWithPath("data.getMyPageTeamBlocks[0].teamId").description("소모임 아이디"), + fieldWithPath("data.getMyPageTeamBlocks[0].teamName").description("소모임 이름"), + fieldWithPath("data.getMyPageTeamBlocks[0].category").description("소모임 카테고리") + ) + ) + ); + } + @Test public void get_profile() throws Exception { //given