Skip to content

Commit

Permalink
feat: test docs 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
minsu20 committed Oct 22, 2023
1 parent 5b2da5c commit d413ef9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/docs/asciidoc/Mypage-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -101,6 +107,61 @@ public void withdraw() throws Exception {
);
}

@Test
public void get_mypage() throws Exception{
//given
List<Category> categoryList=new ArrayList<>();
categoryList.add(Category.SPORTS);

List<GetMyPageTeamBlock> 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
Expand Down

0 comments on commit d413ef9

Please sign in to comment.