Skip to content

Commit

Permalink
๐Ÿ”จ [Refactoring] && ๐Ÿงช [Test] Party ํ…Œ์ŠคํŠธ์ฝ”๋“œ ๋ฆฌํŒฉํ† ๋ง ๋ฐ ์ค‘๋ณต์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์—๋Ÿฌ์ฝ”๋“œ ์ˆ˜์ •์— ๋”ฐ๋ฅธ tโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆest ์ฝ”๋“œ ์ถ”๊ฐ€ (#770)
  • Loading branch information
AreSain authored Mar 26, 2024
1 parent 980f1f6 commit 13480d0
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gg.admin.repo.comment.CommentAdminRepository;
import gg.data.party.Comment;
import gg.party.api.admin.comment.controller.request.CommentUpdateAdminReqDto;
import gg.utils.exception.party.ChangeSameStatusException;
import gg.utils.exception.party.CommentNotFoundException;
import lombok.RequiredArgsConstructor;

Expand All @@ -18,12 +19,16 @@ public class CommentAdminService {
/**
* ๋Œ“๊ธ€ ์ˆจ๊น€
* @param commentId ๋Œ“๊ธ€ ๋ฒˆํ˜ธ
* @exception CommentNotFoundException ์œ ํšจํ•˜์ง€ ์•Š์€ ๋Œ“๊ธ€
* @throws CommentNotFoundException ์œ ํšจํ•˜์ง€ ์•Š์€ ๋Œ“๊ธ€ ์ž…๋ ฅ - 404
* @throws ChangeSameStatusException ๊ฐ™์€ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ - 409
*/
@Transactional
public void modifyHideComment(Long commentId, CommentUpdateAdminReqDto reqDto) {
Comment comment = commentAdminRepository.findById(commentId)
.orElseThrow(CommentNotFoundException::new);
if (reqDto.getIsHidden() == comment.isHidden()) {
throw new ChangeSameStatusException();
}
comment.updateHidden(reqDto.getIsHidden());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import gg.repo.party.CommentRepository;
import gg.repo.party.RoomRepository;
import gg.repo.party.UserRoomRepository;
import gg.utils.exception.party.ChangeSameStatusException;
import gg.utils.exception.party.RoomNotFoundException;
import gg.utils.exception.party.RoomSameStatusException;
import lombok.RequiredArgsConstructor;

@Service
Expand All @@ -39,15 +39,15 @@ public class RoomAdminService {
* @param roomId ๋ฐฉ id
* @param newStatus ๋ฐ”๊ฟ€ status
* @exception RoomNotFoundException ์œ ํšจํ•˜์ง€ ์•Š์€ ๋ฐฉ ์ž…๋ ฅ - 404
* @exception RoomSameStatusException ๊ฐ™์€ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ -409
* @exception ChangeSameStatusException ๊ฐ™์€ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ - 409
*/
@Transactional
public void modifyRoomStatus(Long roomId, RoomType newStatus) {
Room room = roomRepository.findById(roomId)
.orElseThrow(RoomNotFoundException::new);

if (room.getStatus() == newStatus) {
throw new RoomSameStatusException();
throw new ChangeSameStatusException();
}

room.updateRoomStatus(newStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CommentCreateReqDto {
@Size(min = 1, max = 100)
private String content;

public void saveContent(String content) {
public CommentCreateReqDto(String content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class CommentService {
/**
* ๋Œ“๊ธ€ ์ƒ์„ฑ
* @param roomId ๋ฐฉ ๋ฒˆํ˜ธ
* @throws RoomNotFoundException ๋ฐฉ์„ ์ฐพ์„ ์ˆ˜ ์—†์Œ - 404
* @throws RoomNotOpenException ๋ฐฉ์ด ์—ด๋ ค์žˆ์ง€ ์•Š์Œ - 400
* @throws OnPenaltyException ํŒจ๋„ํ‹ฐ ์ƒํƒœ์˜ ์œ ์ € ์ž…๋ ฅ - 403
* @throws RoomNotParticipantException ๋ฐฉ ์ฐธ๊ฐ€์ž๊ฐ€ ์•„๋‹˜ - 400
* @param reqDto ๋Œ“๊ธ€ ์ •๋ณด
*/
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public void success() throws Exception {
CategoryAddAdminReqDto categoryAddAdminReqDto = new CategoryAddAdminReqDto("category");
String jsonRequest = objectMapper.writeValueAsString(categoryAddAdminReqDto);
//when
String contentAsString = mockMvc.perform(post(url)
mockMvc.perform(post(url)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken))
.andExpect(status().isCreated())
.andReturn().getResponse().getContentAsString();
.andReturn().getResponse();
//then
assertThat(categoryRepository.findAll()).size().isEqualTo(2);
}
Expand All @@ -95,11 +95,11 @@ public void fail() throws Exception {
CategoryAddAdminReqDto categoryAddAdminReqDto = new CategoryAddAdminReqDto("category");
String jsonRequest = objectMapper.writeValueAsString(categoryAddAdminReqDto);
//when & then
String contentAsString = mockMvc.perform(post(url)
mockMvc.perform(post(url)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken))
.andExpect(status().isConflict()).toString();
.andExpect(status().isConflict());
}
}

Expand All @@ -124,11 +124,11 @@ public void success() throws Exception {
String categoryID = testCategory.getId().toString();
String url = "/party/admin/categories/" + categoryID;
//when
String contentAsString = mockMvc.perform(delete(url)
mockMvc.perform(delete(url)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken))
.andExpect(status().isNoContent())
.andReturn().getResponse().getContentAsString();
.andReturn().getResponse();
//then
assertThat(categoryRepository.findAll()).size().isEqualTo(1);
assertThat(roomRepository.findById(testRoom.getId()).get().getCategory().getName()).isEqualTo("etc");
Expand All @@ -141,10 +141,10 @@ public void noCategoryFail() throws Exception {
String categoryID = "10";
String url = "/party/admin/categories/" + categoryID;
//when & then
String contentAsString = mockMvc.perform(delete(url)
mockMvc.perform(delete(url)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken))
.andExpect(status().isNotFound()).toString();
.andExpect(status().isNotFound());
}

@Test
Expand All @@ -154,10 +154,10 @@ public void fail() throws Exception {
String categoryID = defaultCategory.getId().toString();
String url = "/party/admin/categories/" + categoryID;
//when & then
String contentAsString = mockMvc.perform(delete(url)
mockMvc.perform(delete(url)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken))
.andExpect(status().isBadRequest()).toString();
.andExpect(status().isBadRequest());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -32,11 +31,6 @@
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;
Expand All @@ -56,16 +50,6 @@ public class CommentAdminControllerTest {
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;
Expand All @@ -84,8 +68,7 @@ void beforeEach() {
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);
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());
Expand All @@ -110,12 +93,13 @@ public void success() throws Exception {
String url = "/party/admin/comments/" + commentId;
CommentUpdateAdminReqDto commentUpdateAdminReqDto = new CommentUpdateAdminReqDto(TRUE);
String requestBody = objectMapper.writeValueAsString(commentUpdateAdminReqDto);
//when && then
String contentAsString = mockMvc.perform(patch(url)
//when
mockMvc.perform(patch(url)
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken))
.andExpect(status().isNoContent()).toString();
.andExpect(status().isNoContent());
//then
assertThat(testComment.isHidden()).isEqualTo(TRUE);
}

Expand All @@ -127,29 +111,46 @@ public void reportCommentSuccess() throws Exception {
String url = "/party/admin/comments/" + commentId;
CommentUpdateAdminReqDto commentUpdateAdminReqDto = new CommentUpdateAdminReqDto(FALSE);
String requestBody = objectMapper.writeValueAsString(commentUpdateAdminReqDto);
//when && then
String contentAsString = mockMvc.perform(patch(url)
//when
mockMvc.perform(patch(url)
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken))
.andExpect(status().isNoContent()).toString();
.andExpect(status().isNoContent());
//then
assertThat(reportComment.isHidden()).isEqualTo(FALSE);
}

@Test
@DisplayName("๊ฐ™์€ ๋‚ด์šฉ์œผ๋กœ ๋ณ€๊ฒฝ์œผ๋กœ ์ธํ•œ ์—๋Ÿฌ 409")
public void duplicationFail() throws Exception {
//given
String commentId = reportComment.getId().toString();
String url = "/party/admin/comments/" + commentId;
CommentUpdateAdminReqDto commentUpdateAdminReqDto = new CommentUpdateAdminReqDto(TRUE);
String requestBody = objectMapper.writeValueAsString(commentUpdateAdminReqDto);
//when && then
mockMvc.perform(patch(url)
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken))
.andExpect(status().isConflict());
}

@Test
@DisplayName("์—†๋Š” Comment๋กœ ์ธํ•œ ์—๋Ÿฌ 404")
public void fail() throws Exception {
//given
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)
//when && then
mockMvc.perform(patch(url)
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + adminAccessToken))
.andExpect(status().isNotFound()).toString();
.andExpect(status().isNotFound());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import gg.party.api.admin.report.controller.response.CommentReportListResDto;
import gg.party.api.admin.report.controller.response.RoomReportListResDto;
import gg.party.api.admin.report.controller.response.UserReportListResDto;
import gg.party.api.admin.report.service.ReportAdminService;
import gg.repo.party.CategoryRepository;
import gg.utils.TestDataUtils;
import gg.utils.annotation.IntegrationTest;
import lombok.RequiredArgsConstructor;
Expand All @@ -52,10 +50,6 @@ public class ReportAdminControllerTest {
ObjectMapper objectMapper;
@Autowired
AuthTokenProvider tokenProvider;
@Autowired
CategoryRepository categoryRepository;
@Autowired
ReportAdminService reportAdminService;
User userTester;
String userAccessToken;
Category testCategory;
Expand Down
Loading

0 comments on commit 13480d0

Please sign in to comment.