Skip to content

Commit

Permalink
๐Ÿงช [Test] Admin ๋Œ“๊ธ€ Show ์—ฌ๋ถ€ ๋ณ€๊ฒฝ ํ…Œ์ŠคํŠธ์ฝ”๋“œ ์ž‘์„ฑ (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Mar 25, 2024
1 parent a31080c commit 61520af
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 1 deletion.
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;
}
}
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();
}
}
}

0 comments on commit 61520af

Please sign in to comment.