-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
865 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) | ||
|
@@ -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("팔로우 신청 테스트") | ||
|
@@ -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(), | ||
|
@@ -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(), | ||
|
@@ -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") | ||
))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.