Skip to content

Commit

Permalink
Merge pull request #227 from techeer-sv/FE/#215
Browse files Browse the repository at this point in the history
FE/#215 메인 페이지, ProjectCard 마이그레이션
  • Loading branch information
Yujin-Baek authored Sep 29, 2023
2 parents c69984c + 3135764 commit 1f747c6
Show file tree
Hide file tree
Showing 14 changed files with 695 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.graphy.backend.domain.auth.util.MemberInfo;
import com.graphy.backend.domain.follow.service.FollowService;
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.member.dto.response.GetMemberListResponse;
import com.graphy.backend.test.MockApiTest;
import com.graphy.backend.test.util.WithMockCustomUser;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -17,15 +19,23 @@
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.web.context.WebApplicationContext;

import java.util.Arrays;
import java.util.List;

import static com.graphy.backend.domain.member.domain.Role.ROLE_USER;
import static com.graphy.backend.test.config.ApiDocumentUtil.getDocumentRequest;
import static com.graphy.backend.test.config.ApiDocumentUtil.getDocumentResponse;
import static org.hamcrest.Matchers.hasSize;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest(FollowController.class)
@ExtendWith(RestDocumentationExtension.class)
Expand All @@ -42,7 +52,7 @@ public void setup(RestDocumentationContextProvider provider) {
memberInfo = new MemberInfo(Member.builder().id(1L).email("[email protected]").password("password").role(ROLE_USER).build());
}

private static String baseUrl = "/api/v1/follow";
private static final String BASE_URL = "/api/v1/follow";

@Test
@DisplayName("팔로우 신청 테스트")
Expand All @@ -51,7 +61,7 @@ void followTest() throws Exception {
Long id = 1L;

// when & then
mvc.perform(post(baseUrl + "/{id}", id).principal(new TestingAuthenticationToken("testEmail", "testPassword")))
mvc.perform(post(BASE_URL + "/{id}", id).principal(new TestingAuthenticationToken("testEmail", "testPassword")))
.andExpect(status().isCreated())
.andDo(document("follow/add/success",
getDocumentRequest(),
Expand All @@ -73,7 +83,7 @@ void unfollowTest() throws Exception {
Long id = 1L;

//then
mvc.perform(RestDocumentationRequestBuilders.delete(baseUrl + "/{id}", id).principal(new TestingAuthenticationToken("testEmail", "testPassword")))
mvc.perform(RestDocumentationRequestBuilders.delete(BASE_URL + "/{id}", id).principal(new TestingAuthenticationToken("testEmail", "testPassword")))
.andExpect(status().isNoContent())
.andDo(document("follow/remove/success",
getDocumentRequest(),
Expand All @@ -88,84 +98,99 @@ void unfollowTest() throws Exception {
)));
}

// @Test
// @DisplayName("팔로잉 리스트 조회 테스트")
// void getFollowingListTest() throws Exception {
// // given
// GetMemberListResponse following1 = new GetMemberListResponse() {
// public Long getId() {
// return 1L;
// }
// public String getNickname() {
// return "memberA";
// }
// };
//
// GetMemberListResponse following2 = new GetMemberListResponse() {
// public Long getId() {
// return 2L;
// }
// public String getNickname() {
// return "memberB";
// }
// };
//
// List<GetMemberListResponse> followingList = Arrays.asList(following1, following2);
//
// // when
// given(followService.findFollowingList(any(Member.class))).willReturn(followingList);
//
// //then
// mvc.perform(get(baseUrl + "/following").with(user(memberInfo)))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$.data", hasSize(2)))
// .andExpect(jsonPath("$.data[0].id").exists())
// .andExpect(jsonPath("$.data[0].nickname").value("memberA"))
// .andExpect(jsonPath("$.data[1].id").exists())
// .andExpect(jsonPath("$.data[1].nickname").value("memberB"))
// .andDo(document("followingList-get",
// preprocessResponse(prettyPrint()))
// );
// }

// @Test
// @WithAnonymousUser
// @DisplayName("팔로워 리스트 조회 테스트")
// void getFollowerListTest() throws Exception {
// // given
// GetMemberListResponse follower1 = new GetMemberListResponse() {
// public Long getId() {
// return 1L;
// }
// public String getNickname() {
// return "memberA";
// }
// };
//
// GetMemberListResponse follower2 = new GetMemberListResponse() {
// public Long getId() {
// return 2L;
// }
// public String getNickname() {
// return "memberB";
// }
// };
//
// List<GetMemberListResponse> followerList = Arrays.asList(follower1, follower2);
//
// // when
// given(followService.findFollowerList(any(Member.class))).willReturn(followerList);
//
// //then
// mvc.perform(get(baseUrl + "/follower").principal(new TestingAuthenticationToken("testEmail", "testPassword")))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$.data", hasSize(2)))
// .andExpect(jsonPath("$.data[0].id").exists())
// .andExpect(jsonPath("$.data[0].nickname").value("memberA"))
// .andExpect(jsonPath("$.data[1].id").exists())
// .andExpect(jsonPath("$.data[1].nickname").value("memberB"))
// .andDo(document("followerList-get",
// preprocessResponse(prettyPrint()))
// );
// }
@Test
@WithMockCustomUser
@DisplayName("팔로잉 리스트 조회 테스트")
void getFollowingListTest() throws Exception {
// given
GetMemberListResponse following1 = new GetMemberListResponse() {
public Long getId() {
return 1L;
}
public String getNickname() {
return "memberA";
}
};

GetMemberListResponse following2 = new GetMemberListResponse() {
public Long getId() {
return 2L;
}
public String getNickname() {
return "memberB";
}
};

List<GetMemberListResponse> followingList = Arrays.asList(following1, following2);

// when
given(followService.findFollowingList(any(Member.class))).willReturn(followingList);

//then
mvc.perform(get(BASE_URL + "/following"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data", hasSize(2)))
.andExpect(jsonPath("$.data[0].id").exists())
.andExpect(jsonPath("$.data[0].nickname").value("memberA"))
.andExpect(jsonPath("$.data[1].id").exists())
.andExpect(jsonPath("$.data[1].nickname").value("memberB"))
.andDo(document("follow/followingList/success",
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("code").description("상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("data").description("응답 데이터"),
fieldWithPath("data[].id").description("팔로잉하는 사용자의 ID"),
fieldWithPath("data[].nickname").description("팔로잉하는 사용자의 nickname")
)));
}

@Test
@WithMockCustomUser
@DisplayName("팔로워 리스트 조회 테스트")
void getFollowerListTest() throws Exception {
// given
GetMemberListResponse follower1 = new GetMemberListResponse() {
public Long getId() {
return 1L;
}
public String getNickname() {
return "memberA";
}
};

GetMemberListResponse follower2 = new GetMemberListResponse() {
public Long getId() {
return 2L;
}
public String getNickname() {
return "memberB";
}
};

List<GetMemberListResponse> followerList = Arrays.asList(follower1, follower2);

// when
given(followService.findFollowerList(any(Member.class))).willReturn(followerList);

//then
mvc.perform(get(BASE_URL + "/follower").principal(new TestingAuthenticationToken("testEmail", "testPassword")))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data", hasSize(2)))
.andExpect(jsonPath("$.data[0].id").exists())
.andExpect(jsonPath("$.data[0].nickname").value("memberA"))
.andExpect(jsonPath("$.data[1].id").exists())
.andExpect(jsonPath("$.data[1].nickname").value("memberB"))
.andDo(document("follow/followingList/success",
getDocumentRequest(),
getDocumentResponse(),
responseFields(
fieldWithPath("code").description("상태 코드"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("data").description("응답 데이터"),
fieldWithPath("data[].id").description("팔로워 사용자의 ID"),
fieldWithPath("data[].nickname").description("팔로워 사용자의 nickname")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setup(RestDocumentationContextProvider provider) {

@Test
@DisplayName("닉네임으로 사용자를 조회한다")
public void findMemberTest() throws Exception {
void findMemberTest() throws Exception {
// given
GetMemberResponse response1 = GetMemberResponse.builder()
.nickname(member1.getNickname())
Expand Down Expand Up @@ -122,7 +122,7 @@ public void findMemberTest() throws Exception {

@Test
@DisplayName("현재 로그인한 사용자의 정보로 마이페이지를 조회한다")
public void getMyPageTest() throws Exception {
void getMyPageTest() throws Exception {
GetMyPageResponse result = GetMyPageResponse.builder()
.nickname(member1.getNickname())
.introduction(member1.getIntroduction())
Expand Down
Loading

0 comments on commit 1f747c6

Please sign in to comment.