-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐งช [Test] Admin ๋๊ธ Show ์ฌ๋ถ ๋ณ๊ฒฝ ํ
์คํธ์ฝ๋ ์์ฑ (#764)
- Loading branch information
Showing
2 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
7 changes: 6 additions & 1 deletion
7
...src/main/java/gg/party/api/admin/comment/controller/request/CommentUpdateAdminReqDto.java
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package gg.party.api.admin.comment.controller.request; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CommentUpdateAdminReqDto { | ||
private Boolean isHidden; | ||
|
||
public CommentUpdateAdminReqDto(Boolean isHidden) { | ||
this.isHidden = isHidden; | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
gg-pingpong-api/src/test/java/gg/party/api/admin/comment/CommentAdminControllerTest.java
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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package gg.party.api.admin.comment; | ||
|
||
import static java.lang.Boolean.*; | ||
import static org.assertj.core.api.AssertionsForClassTypes.*; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import gg.auth.utils.AuthTokenProvider; | ||
import gg.data.party.Category; | ||
import gg.data.party.Comment; | ||
import gg.data.party.PartyPenalty; | ||
import gg.data.party.Room; | ||
import gg.data.party.UserRoom; | ||
import gg.data.party.type.RoomType; | ||
import gg.data.user.User; | ||
import gg.data.user.type.RacketType; | ||
import gg.data.user.type.RoleType; | ||
import gg.data.user.type.SnsType; | ||
import gg.party.api.admin.comment.controller.request.CommentUpdateAdminReqDto; | ||
import gg.repo.party.CategoryRepository; | ||
import gg.repo.party.CommentRepository; | ||
import gg.repo.party.PartyPenaltyRepository; | ||
import gg.repo.party.RoomRepository; | ||
import gg.repo.party.UserRoomRepository; | ||
import gg.utils.TestDataUtils; | ||
import gg.utils.annotation.IntegrationTest; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@IntegrationTest | ||
@AutoConfigureMockMvc | ||
@Transactional | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CommentAdminControllerTest { | ||
@Autowired | ||
MockMvc mockMvc; | ||
@Autowired | ||
TestDataUtils testDataUtils; | ||
@Autowired | ||
ObjectMapper objectMapper; | ||
@Autowired | ||
AuthTokenProvider tokenProvider; | ||
@Autowired | ||
RoomRepository roomRepository; | ||
@Autowired | ||
UserRoomRepository userRoomRepository; | ||
@Autowired | ||
CategoryRepository categoryRepository; | ||
@Autowired | ||
PartyPenaltyRepository partyPenaltyRepository; | ||
@Autowired | ||
CommentRepository commentRepository; | ||
User userTester; | ||
User reportedTester; | ||
User adminTester; | ||
String adminAccessToken; | ||
Room testRoom; | ||
Room reportTestRoom; | ||
Comment testComment; | ||
Comment reportComment; | ||
|
||
@Nested | ||
@DisplayName("Comment Show ์ฌ๋ถ ์์ ํ ์คํธ") | ||
class HideComment { | ||
@BeforeEach | ||
void beforeEach() { | ||
userTester = testDataUtils.createNewImageUser("findTester", "findTester", | ||
RacketType.DUAL, SnsType.SLACK, RoleType.USER, "userImage"); | ||
reportedTester = testDataUtils.createNewImageUser("reportedTester", "reportedTester", | ||
RacketType.DUAL, SnsType.SLACK, RoleType.USER, "reportedImage"); | ||
PartyPenalty testPenalty = testDataUtils.createNewPenalty(reportedTester, "test", "test", | ||
LocalDateTime.now(), 60); | ||
adminTester = testDataUtils.createNewImageUser("adminTester", "adminTester", | ||
RacketType.DUAL, SnsType.SLACK, RoleType.ADMIN, "adminImage"); | ||
adminAccessToken = tokenProvider.createToken(adminTester.getId()); | ||
Category testCategory = testDataUtils.createNewCategory("test"); | ||
testRoom = testDataUtils.createNewRoom(userTester, userTester, testCategory, 1, 1, 3, 2, 180, | ||
RoomType.OPEN); | ||
reportTestRoom = testDataUtils.createNewRoom(reportedTester, reportedTester, testCategory, 1, 1, 3, 2, 180, | ||
RoomType.OPEN); | ||
UserRoom testUserRoom = testDataUtils.createNewUserRoom(userTester, testRoom, "testNickname", TRUE); | ||
UserRoom reportUserRoom = testDataUtils.createNewUserRoom(reportedTester, reportTestRoom, "reportNickname", | ||
TRUE); | ||
testComment = testDataUtils.createComment(userTester, testUserRoom, testRoom, "testComment"); | ||
reportComment = testDataUtils.createReportComment(reportedTester, reportUserRoom, reportTestRoom, | ||
"reportComment"); | ||
} | ||
|
||
@Test | ||
@DisplayName("isHidden False -> True ๋ณ๊ฒฝ ์ฑ๊ณต 204") | ||
public void success() throws Exception { | ||
//given | ||
String commentId = testComment.getId().toString(); | ||
String url = "/party/admin/comments/" + commentId; | ||
CommentUpdateAdminReqDto commentUpdateAdminReqDto = new CommentUpdateAdminReqDto(TRUE); | ||
String requestBody = objectMapper.writeValueAsString(commentUpdateAdminReqDto); | ||
//when && then | ||
String contentAsString = mockMvc.perform(patch(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken)) | ||
.andExpect(status().isNoContent()).toString(); | ||
assertThat(testComment.isHidden()).isEqualTo(TRUE); | ||
} | ||
|
||
@Test | ||
@DisplayName("isHidden True -> False ๋ณ๊ฒฝ ์ฑ๊ณต 204") | ||
public void reportCommentSuccess() throws Exception { | ||
//given | ||
String commentId = reportComment.getId().toString(); | ||
String url = "/party/admin/comments/" + commentId; | ||
CommentUpdateAdminReqDto commentUpdateAdminReqDto = new CommentUpdateAdminReqDto(FALSE); | ||
String requestBody = objectMapper.writeValueAsString(commentUpdateAdminReqDto); | ||
//when && then | ||
String contentAsString = mockMvc.perform(patch(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken)) | ||
.andExpect(status().isNoContent()).toString(); | ||
//then | ||
assertThat(reportComment.isHidden()).isEqualTo(FALSE); | ||
} | ||
|
||
@Test | ||
@DisplayName("์๋ Comment๋ก ์ธํ ์๋ฌ 404") | ||
public void fail() throws Exception { | ||
String commentId = "1000"; | ||
String url = "/party/admin/comments/" + commentId; | ||
CommentUpdateAdminReqDto commentUpdateAdminReqDto = new CommentUpdateAdminReqDto(TRUE); | ||
String requestBody = objectMapper.writeValueAsString(commentUpdateAdminReqDto); | ||
//given | ||
String contentAsString = mockMvc.perform(patch(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(requestBody) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken)) | ||
.andExpect(status().isNotFound()).toString(); | ||
} | ||
} | ||
} |