From acde9080d121750377e0b9c30ca47ad3efd68280 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Mon, 25 Mar 2024 13:30:19 +0900 Subject: [PATCH 01/11] =?UTF-8?q?[feature]=20=ED=8C=A8=EB=84=90=ED=8B=B0?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../penalty/PartyPenaltyControllerTest.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java new file mode 100644 index 000000000..35f262847 --- /dev/null +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -0,0 +1,120 @@ +package gg.party.api.admin.penalty; + +import static org.mockito.Mockito.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.time.LocalDateTime; + +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.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +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.PartyPenalty; +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.penalty.controller.request.PageReqDto; +import gg.party.api.admin.penalty.controller.request.PartyPenaltyAdminReqDto; +import gg.party.api.admin.penalty.controller.response.PartyPenaltyListAdminResDto; +import gg.party.api.admin.penalty.service.PartyPenaltyAdminService; +import gg.utils.TestDataUtils; +import gg.utils.annotation.IntegrationTest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@IntegrationTest +@AutoConfigureMockMvc +@Transactional +@RequiredArgsConstructor +@Slf4j +public class PartyPenaltyControllerTest { + @Autowired + private MockMvc mockMvc; + @Autowired + private TestDataUtils testDataUtils; + @Autowired + private ObjectMapper objectMapper; + @Autowired + private AuthTokenProvider tokenProvider; + + @MockBean + private PartyPenaltyAdminService partyPenaltyAdminService; + + private User userTester; + User reportedTester; + String userAccessToken; + String reportedAccessToken; + @BeforeEach + void beforeEach() { + userTester = testDataUtils.createNewUser("User1", "emailTester", + RacketType.DUAL, SnsType.SLACK, RoleType.USER); + reportedTester = testDataUtils.createNewUser("reportedUser", "reportedTester", + RacketType.DUAL, SnsType.SLACK, RoleType.USER); + PartyPenalty testPenalty = testDataUtils.createNewPenalty(reportedTester, "test_penalty", "becauseTest", + LocalDateTime.now(), 60); + userAccessToken = tokenProvider.createToken(userTester.getId()); + reportedAccessToken = tokenProvider.createToken(reportedTester.getId()); + } + + @Nested + @DisplayName("패널티 테스트") + @WithMockUser(username = "admin", roles = {"ADMIN"}) + class PenaltyAdminTests { + + @Test + @DisplayName("패널티 조회") + void testRetrievePenaltiesList() throws Exception { + PageReqDto reqDto = new PageReqDto(1, 10); + PartyPenaltyListAdminResDto responseDto = new PartyPenaltyListAdminResDto(); + + when(partyPenaltyAdminService.findAllPenalty(any(PageReqDto.class))).thenReturn(responseDto); + + mockMvc.perform(get("/party/admin/penalties?page=1&size=10") //정확한 페이지, 사이즈 정보 필요 + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isOk()); + + verify(partyPenaltyAdminService).findAllPenalty(any(PageReqDto.class)); + } + + @Test + @DisplayName("패널티 수정") + void testModifyAdminPenalty() throws Exception { + Long penaltyId = 1L; + PartyPenaltyAdminReqDto reqDto = new PartyPenaltyAdminReqDto(); + + mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", penaltyId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isNoContent()); + + verify(partyPenaltyAdminService).modifyAdminPenalty(eq(penaltyId), any(PartyPenaltyAdminReqDto.class)); + } + + @Test + @DisplayName("패널티 부여") + void testAddAdminPenalty() throws Exception { + PartyPenaltyAdminReqDto reqDto = new PartyPenaltyAdminReqDto(); + + mockMvc.perform(post("/party/admin/penalties") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isCreated()); + + verify(partyPenaltyAdminService).addAdminPenalty(any(PartyPenaltyAdminReqDto.class)); + } + } +} From 715b6235a29b00ad3d9efc5fd9471be71934868e Mon Sep 17 00:00:00 2001 From: jungjkim Date: Mon, 25 Mar 2024 14:50:48 +0900 Subject: [PATCH 02/11] =?UTF-8?q?[fix]=20dto=20@Valid=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B3=B4=EC=99=84(db=20=ED=85=8C=EC=8A=A4=ED=8A=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PartyPenaltyAdminController.java | 6 +-- .../request/PartyPenaltyAdminReqDto.java | 7 +++ .../penalty/PartyPenaltyControllerTest.java | 43 +++++++++---------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java index 565d86681..876a94b72 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java @@ -40,7 +40,7 @@ public ResponseEntity penaltyList(@ModelAttribute @ * @param penaltyId 패널티 id */ @PatchMapping("/{penaltyId}") - public ResponseEntity modifyAdminPenalty(@PathVariable Long penaltyId, + public ResponseEntity modifyAdminPenalty(@PathVariable @Valid Long penaltyId, @RequestBody PartyPenaltyAdminReqDto reqDto) { partyPenaltyAdminService.modifyAdminPenalty(penaltyId, reqDto); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); @@ -49,9 +49,9 @@ public ResponseEntity modifyAdminPenalty(@PathVariable Long penaltyId, /** * 패널티 부여 */ - @PostMapping() + @PostMapping public ResponseEntity addAdminPenalty( - @RequestBody PartyPenaltyAdminReqDto reqDto) { + @RequestBody @Valid PartyPenaltyAdminReqDto reqDto) { partyPenaltyAdminService.addAdminPenalty(reqDto); return ResponseEntity.status(HttpStatus.CREATED).build(); } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java index 56256dfda..0a31daa40 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java @@ -19,4 +19,11 @@ public PartyPenalty toEntity(User user, String penaltyType, String message, Loca Integer penaltyTime) { return new PartyPenalty(user, penaltyType, message, startTime, penaltyTime); } + + public PartyPenaltyAdminReqDto(String penaltyType, String message, int penaltyTime, String userIntraId) { + this.penaltyType = penaltyType; + this.message = message; + this.penaltyTime = penaltyTime; + this.userIntraId = userIntraId; + } } diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index 35f262847..6c0080e16 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -1,6 +1,5 @@ package gg.party.api.admin.penalty; -import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -12,7 +11,7 @@ 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.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; @@ -28,17 +27,15 @@ import gg.data.user.type.SnsType; import gg.party.api.admin.penalty.controller.request.PageReqDto; import gg.party.api.admin.penalty.controller.request.PartyPenaltyAdminReqDto; -import gg.party.api.admin.penalty.controller.response.PartyPenaltyListAdminResDto; -import gg.party.api.admin.penalty.service.PartyPenaltyAdminService; +import gg.repo.party.PartyPenaltyRepository; import gg.utils.TestDataUtils; import gg.utils.annotation.IntegrationTest; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @IntegrationTest @AutoConfigureMockMvc +@SpringBootTest @Transactional -@RequiredArgsConstructor @Slf4j public class PartyPenaltyControllerTest { @Autowired @@ -49,21 +46,22 @@ public class PartyPenaltyControllerTest { private ObjectMapper objectMapper; @Autowired private AuthTokenProvider tokenProvider; - - @MockBean - private PartyPenaltyAdminService partyPenaltyAdminService; + @Autowired + private PartyPenaltyRepository partyPenaltyRepository; private User userTester; User reportedTester; String userAccessToken; String reportedAccessToken; + @BeforeEach void beforeEach() { userTester = testDataUtils.createNewUser("User1", "emailTester", RacketType.DUAL, SnsType.SLACK, RoleType.USER); reportedTester = testDataUtils.createNewUser("reportedUser", "reportedTester", RacketType.DUAL, SnsType.SLACK, RoleType.USER); - PartyPenalty testPenalty = testDataUtils.createNewPenalty(reportedTester, "test_penalty", "becauseTest", + PartyPenalty testPenalty = testDataUtils.createNewPenalty(reportedTester, "test_penalty", + "becauseTest", LocalDateTime.now(), 60); userAccessToken = tokenProvider.createToken(userTester.getId()); reportedAccessToken = tokenProvider.createToken(reportedTester.getId()); @@ -78,43 +76,42 @@ class PenaltyAdminTests { @DisplayName("패널티 조회") void testRetrievePenaltiesList() throws Exception { PageReqDto reqDto = new PageReqDto(1, 10); - PartyPenaltyListAdminResDto responseDto = new PartyPenaltyListAdminResDto(); - - when(partyPenaltyAdminService.findAllPenalty(any(PageReqDto.class))).thenReturn(responseDto); mockMvc.perform(get("/party/admin/penalties?page=1&size=10") //정확한 페이지, 사이즈 정보 필요 .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(reqDto))) .andExpect(status().isOk()); - - verify(partyPenaltyAdminService).findAllPenalty(any(PageReqDto.class)); } @Test @DisplayName("패널티 수정") void testModifyAdminPenalty() throws Exception { Long penaltyId = 1L; - PartyPenaltyAdminReqDto reqDto = new PartyPenaltyAdminReqDto(); + + PartyPenalty testPenalty = partyPenaltyRepository.save(new PartyPenalty(reportedTester, + "test_penalty", "becauseTest", + LocalDateTime.now(), 60)); mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", penaltyId) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqDto))) + .content(objectMapper.writeValueAsString(testPenalty))) .andExpect(status().isNoContent()); - - verify(partyPenaltyAdminService).modifyAdminPenalty(eq(penaltyId), any(PartyPenaltyAdminReqDto.class)); } @Test @DisplayName("패널티 부여") void testAddAdminPenalty() throws Exception { - PartyPenaltyAdminReqDto reqDto = new PartyPenaltyAdminReqDto(); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( + "test_penalty", + "Test reason", + 60, + reportedTester.getIntraId() + ); mockMvc.perform(post("/party/admin/penalties") .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqDto))) + .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isCreated()); - - verify(partyPenaltyAdminService).addAdminPenalty(any(PartyPenaltyAdminReqDto.class)); } } } From fd05d94b3b826e9fbb9eb7ce02ebbaac04443a37 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Mon, 25 Mar 2024 16:16:21 +0900 Subject: [PATCH 03/11] =?UTF-8?q?[fix]=20dto=20@Valid=20=EB=B3=B4=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../penalty/controller/PartyPenaltyAdminController.java | 4 ++-- .../controller/request/PartyPenaltyAdminReqDto.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java index 876a94b72..6a507644e 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/PartyPenaltyAdminController.java @@ -40,8 +40,8 @@ public ResponseEntity penaltyList(@ModelAttribute @ * @param penaltyId 패널티 id */ @PatchMapping("/{penaltyId}") - public ResponseEntity modifyAdminPenalty(@PathVariable @Valid Long penaltyId, - @RequestBody PartyPenaltyAdminReqDto reqDto) { + public ResponseEntity modifyAdminPenalty(@PathVariable Long penaltyId, + @RequestBody @Valid PartyPenaltyAdminReqDto reqDto) { partyPenaltyAdminService.modifyAdminPenalty(penaltyId, reqDto); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java index 0a31daa40..3b0c6fd42 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java @@ -2,6 +2,9 @@ import java.time.LocalDateTime; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + import gg.data.party.PartyPenalty; import gg.data.user.User; import lombok.Getter; @@ -10,9 +13,15 @@ @Getter @NoArgsConstructor public class PartyPenaltyAdminReqDto { + @NotNull(message = "Penalty type이 비어있습니다") + @Size(max = 20, message = "Penalty type은 최대 20자입니다") String penaltyType; + @NotNull(message = "message가 비어있습니다") + @Size(max = 100, message = "Penalty type은 최대 100자입니다") String message; + @NotNull(message = "penaltyTime이 비어있습니다") int penaltyTime; + @NotNull(message = "IntraId가 비어있습니다") String userIntraId; public PartyPenalty toEntity(User user, String penaltyType, String message, LocalDateTime startTime, From b9a48a894cb55939ba6f556c774147e506ee3bf4 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Mon, 25 Mar 2024 17:12:46 +0900 Subject: [PATCH 04/11] =?UTF-8?q?[fix]=20test=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/request/PartyPenaltyAdminReqDto.java | 7 ++++--- .../api/admin/penalty/PartyPenaltyControllerTest.java | 11 +++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java index 3b0c6fd42..5b75c5401 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @@ -13,15 +14,15 @@ @Getter @NoArgsConstructor public class PartyPenaltyAdminReqDto { - @NotNull(message = "Penalty type이 비어있습니다") + @NotEmpty(message = "Penalty type이 비어있습니다") @Size(max = 20, message = "Penalty type은 최대 20자입니다") String penaltyType; - @NotNull(message = "message가 비어있습니다") + @NotEmpty(message = "message가 비어있습니다") @Size(max = 100, message = "Penalty type은 최대 100자입니다") String message; @NotNull(message = "penaltyTime이 비어있습니다") int penaltyTime; - @NotNull(message = "IntraId가 비어있습니다") + @NotEmpty(message = "IntraId가 비어있습니다") String userIntraId; public PartyPenalty toEntity(User user, String penaltyType, String message, LocalDateTime startTime, diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index 6c0080e16..653988f2d 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -88,13 +88,16 @@ void testRetrievePenaltiesList() throws Exception { void testModifyAdminPenalty() throws Exception { Long penaltyId = 1L; - PartyPenalty testPenalty = partyPenaltyRepository.save(new PartyPenalty(reportedTester, - "test_penalty", "becauseTest", - LocalDateTime.now(), 60)); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( + "test_penalty", + "Test reason", + 60, + reportedTester.getIntraId() + ); mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", penaltyId) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(testPenalty))) + .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isNoContent()); } From 976947f14d8d02a3c6639b0f4c8ebaca413646c6 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Mon, 25 Mar 2024 17:21:53 +0900 Subject: [PATCH 05/11] =?UTF-8?q?[fix]=20NotEmpty=EC=97=90=EC=84=9C=20NotB?= =?UTF-8?q?lank=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/request/PartyPenaltyAdminReqDto.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java index 5b75c5401..e08174dba 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @@ -14,15 +15,18 @@ @Getter @NoArgsConstructor public class PartyPenaltyAdminReqDto { - @NotEmpty(message = "Penalty type이 비어있습니다") + @NotBlank(message = "Penalty type이 비어있습니다") @Size(max = 20, message = "Penalty type은 최대 20자입니다") String penaltyType; - @NotEmpty(message = "message가 비어있습니다") + + @NotBlank(message = "message가 비어있습니다") @Size(max = 100, message = "Penalty type은 최대 100자입니다") String message; + @NotNull(message = "penaltyTime이 비어있습니다") int penaltyTime; - @NotEmpty(message = "IntraId가 비어있습니다") + + @NotBlank(message = "IntraId가 비어있습니다") String userIntraId; public PartyPenalty toEntity(User user, String penaltyType, String message, LocalDateTime startTime, From 9406f9214ad85f3269565d28156aa0660952f498 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Tue, 26 Mar 2024 14:25:06 +0900 Subject: [PATCH 06/11] =?UTF-8?q?[fix]=20=EC=8A=B9=EC=88=98=EB=8B=98s=20co?= =?UTF-8?q?mments=20(db,=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80,=20mock=EC=96=B4=EB=93=9C=EB=AF=BC=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8=20=EB=93=B1=EB=93=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/PartyPenaltyAdminReqDto.java | 5 +- .../penalty/PartyPenaltyControllerTest.java | 155 +++++++++++++++--- .../gg/repo/party/PartyPenaltyRepository.java | 4 + 3 files changed, 140 insertions(+), 24 deletions(-) diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java index e08174dba..147dcc84f 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/penalty/controller/request/PartyPenaltyAdminReqDto.java @@ -2,8 +2,8 @@ import java.time.LocalDateTime; +import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @@ -20,10 +20,11 @@ public class PartyPenaltyAdminReqDto { String penaltyType; @NotBlank(message = "message가 비어있습니다") - @Size(max = 100, message = "Penalty type은 최대 100자입니다") + @Size(max = 100, message = "message는 최대 100자입니다") String message; @NotNull(message = "penaltyTime이 비어있습니다") + @Min(value = 1, message = "올바른 penaltyTime을 넣어주세요") int penaltyTime; @NotBlank(message = "IntraId가 비어있습니다") diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index 653988f2d..ed803a175 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -1,9 +1,11 @@ package gg.party.api.admin.penalty; +import static org.junit.Assert.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.time.LocalDateTime; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -13,8 +15,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.databind.ObjectMapper; @@ -25,8 +27,8 @@ import gg.data.user.type.RacketType; import gg.data.user.type.RoleType; import gg.data.user.type.SnsType; -import gg.party.api.admin.penalty.controller.request.PageReqDto; import gg.party.api.admin.penalty.controller.request.PartyPenaltyAdminReqDto; +import gg.party.api.admin.penalty.controller.response.PartyPenaltyListAdminResDto; import gg.repo.party.PartyPenaltyRepository; import gg.utils.TestDataUtils; import gg.utils.annotation.IntegrationTest; @@ -50,44 +52,81 @@ public class PartyPenaltyControllerTest { private PartyPenaltyRepository partyPenaltyRepository; private User userTester; - User reportedTester; - String userAccessToken; - String reportedAccessToken; + private User reportedTester; + private User adminUser; + private String adminAccessToken; + private Long testPenaltyId; @BeforeEach void beforeEach() { - userTester = testDataUtils.createNewUser("User1", "emailTester", + userTester = testDataUtils.createNewUser("user1", "emailTester", RacketType.DUAL, SnsType.SLACK, RoleType.USER); reportedTester = testDataUtils.createNewUser("reportedUser", "reportedTester", RacketType.DUAL, SnsType.SLACK, RoleType.USER); + adminUser = testDataUtils.createNewUser("adminUser", "adminTester@example.com", + RacketType.DUAL, SnsType.SLACK, RoleType.ADMIN); PartyPenalty testPenalty = testDataUtils.createNewPenalty(reportedTester, "test_penalty", - "becauseTest", - LocalDateTime.now(), 60); - userAccessToken = tokenProvider.createToken(userTester.getId()); - reportedAccessToken = tokenProvider.createToken(reportedTester.getId()); + "이유는_테스트라서", LocalDateTime.now(), 60); + testPenaltyId = testPenalty.getId(); + adminAccessToken = tokenProvider.createToken(adminUser.getId()); } @Nested @DisplayName("패널티 테스트") - @WithMockUser(username = "admin", roles = {"ADMIN"}) class PenaltyAdminTests { @Test @DisplayName("패널티 조회") void testRetrievePenaltiesList() throws Exception { - PageReqDto reqDto = new PageReqDto(1, 10); + for (int i = 1; i <= 9; i++) { + testDataUtils.createNewPenalty(reportedTester, "test_penalty_" + i, + "test_reason" + i, LocalDateTime.now(), 60); + } + int pageSize = 10; + int pageNumber = 1; + String url = String.format("/party/admin/penalties?page=%d&size=%d", pageNumber, pageSize); + + MvcResult result = mockMvc.perform(get(url) + .header("Authorization", "Bearer " + adminAccessToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + String content = result.getResponse().getContentAsString(); + PartyPenaltyListAdminResDto responseDto = + objectMapper.readValue(content, PartyPenaltyListAdminResDto.class); + + assertEquals(pageSize, responseDto.getPenaltyList().size()); + } - mockMvc.perform(get("/party/admin/penalties?page=1&size=10") //정확한 페이지, 사이즈 정보 필요 - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(reqDto))) - .andExpect(status().isOk()); + @Test + @DisplayName("패널티 조회(pagination)") + void testPaginationPenaltiesList() throws Exception { + for (int i = 1; i <= 15; i++) { + testDataUtils.createNewPenalty(reportedTester, "test_penalty_" + i, + "test_reason" + i, LocalDateTime.now(), 60); + } + int pageSize = 10; + int pageNumber = 2; + String url = String.format("/party/admin/penalties?page=%d&size=%d", pageNumber, pageSize); + + MvcResult result = mockMvc.perform(get(url) + .header("Authorization", "Bearer " + adminAccessToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); + + String content = result.getResponse().getContentAsString(); + PartyPenaltyListAdminResDto responseDto = + objectMapper.readValue(content, PartyPenaltyListAdminResDto.class); + + int expectedPageSize = 6; + assertEquals(expectedPageSize, responseDto.getPenaltyList().size()); } @Test @DisplayName("패널티 수정") void testModifyAdminPenalty() throws Exception { - Long penaltyId = 1L; - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( "test_penalty", "Test reason", @@ -95,26 +134,98 @@ void testModifyAdminPenalty() throws Exception { reportedTester.getIntraId() ); - mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", penaltyId) + mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", testPenaltyId) + .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isNoContent()); + + PartyPenalty updatedPenalty = partyPenaltyRepository.findById(testPenaltyId) + .orElseThrow(() -> new AssertionError("Penalty not found after update")); + + assertEquals(penaltyDto.getPenaltyType(), updatedPenalty.getPenaltyType()); + assertEquals(penaltyDto.getMessage(), updatedPenalty.getMessage()); + assertEquals(penaltyDto.getPenaltyTime(), updatedPenalty.getPenaltyTime().intValue()); } @Test - @DisplayName("패널티 부여") - void testAddAdminPenalty() throws Exception { + @DisplayName("패널티 수정 - 실패 시나리오(없는 유저)") + void testModifyAdminPenalty_NotFound() throws Exception { + Long nonExistentPenaltyId = 999L; + + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( + "test_penalty", + "test_reason", + 60, + "nonexistentIntraId" + ); + + mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", nonExistentPenaltyId) + .header("Authorization", "Bearer " + adminAccessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(penaltyDto))) + .andExpect(status().isNotFound()); + } + + @Test + @DisplayName("패널티 부여 (일반적인 상황)") + void testGiveAdminPenalty() throws Exception { PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( "test_penalty", "Test reason", 60, - reportedTester.getIntraId() + userTester.getIntraId() ); + long penaltyCountBefore = partyPenaltyRepository.count(); + mockMvc.perform(post("/party/admin/penalties") + .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isCreated()); + + long penaltyCountAfter = partyPenaltyRepository.count(); + assertEquals(penaltyCountBefore + 1, penaltyCountAfter); + } + + @Test + @DisplayName("패널티 부여 (패널티된 유저에게 추가 패널티 부여)") + void testAddAdminPenalty() throws Exception { + PartyPenaltyAdminReqDto morePenaltyDto = new PartyPenaltyAdminReqDto( + "test_penalty", + "Test reason", + 60, + reportedTester.getIntraId() + ); + + mockMvc.perform(post("/party/admin/penalties") + .header("Authorization", "Bearer " + adminAccessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(morePenaltyDto))) + .andExpect(status().isCreated()); + + List penalties = partyPenaltyRepository.findAllByUserId(reportedTester.getId()); + int totalPenaltyTime = penalties.stream().mapToInt(PartyPenalty::getPenaltyTime).sum(); + + assertEquals(120, totalPenaltyTime); + } + + @Test + @DisplayName("패널티 부여 - 실패 시나리오(없는 유저)") + void testAddAdminPenalty_UserNotFound() throws Exception { + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( + "test_penalty", + "Test reason", + 60, + "nonexistentIntraId" + ); + + mockMvc.perform(post("/party/admin/penalties") + .header("Authorization", "Bearer " + adminAccessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(penaltyDto))) + .andExpect(status().isNotFound()); } } } diff --git a/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java b/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java index 7ec1aba49..0b2f23e09 100644 --- a/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java +++ b/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java @@ -1,9 +1,13 @@ package gg.repo.party; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import gg.data.party.PartyPenalty; public interface PartyPenaltyRepository extends JpaRepository { PartyPenalty findByUserId(Long id); + + List findAllByUserId(Long userId); } From 9dd6b3120ee79c816cde1c9e8535435d4386c413 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Tue, 26 Mar 2024 14:35:28 +0900 Subject: [PATCH 07/11] [fix] given then when --- .../penalty/PartyPenaltyControllerTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index ed803a175..2292592ad 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -78,6 +78,7 @@ class PenaltyAdminTests { @Test @DisplayName("패널티 조회") void testRetrievePenaltiesList() throws Exception { + //given for (int i = 1; i <= 9; i++) { testDataUtils.createNewPenalty(reportedTester, "test_penalty_" + i, "test_reason" + i, LocalDateTime.now(), 60); @@ -86,12 +87,14 @@ void testRetrievePenaltiesList() throws Exception { int pageNumber = 1; String url = String.format("/party/admin/penalties?page=%d&size=%d", pageNumber, pageSize); + //when MvcResult result = mockMvc.perform(get(url) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn(); + //then String content = result.getResponse().getContentAsString(); PartyPenaltyListAdminResDto responseDto = objectMapper.readValue(content, PartyPenaltyListAdminResDto.class); @@ -101,6 +104,7 @@ void testRetrievePenaltiesList() throws Exception { @Test @DisplayName("패널티 조회(pagination)") + //given void testPaginationPenaltiesList() throws Exception { for (int i = 1; i <= 15; i++) { testDataUtils.createNewPenalty(reportedTester, "test_penalty_" + i, @@ -110,12 +114,14 @@ void testPaginationPenaltiesList() throws Exception { int pageNumber = 2; String url = String.format("/party/admin/penalties?page=%d&size=%d", pageNumber, pageSize); + //then MvcResult result = mockMvc.perform(get(url) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn(); + //when String content = result.getResponse().getContentAsString(); PartyPenaltyListAdminResDto responseDto = objectMapper.readValue(content, PartyPenaltyListAdminResDto.class); @@ -127,6 +133,7 @@ void testPaginationPenaltiesList() throws Exception { @Test @DisplayName("패널티 수정") void testModifyAdminPenalty() throws Exception { + //given PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( "test_penalty", "Test reason", @@ -134,12 +141,14 @@ void testModifyAdminPenalty() throws Exception { reportedTester.getIntraId() ); + //then mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", testPenaltyId) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isNoContent()); + //when PartyPenalty updatedPenalty = partyPenaltyRepository.findById(testPenaltyId) .orElseThrow(() -> new AssertionError("Penalty not found after update")); @@ -151,6 +160,7 @@ void testModifyAdminPenalty() throws Exception { @Test @DisplayName("패널티 수정 - 실패 시나리오(없는 유저)") void testModifyAdminPenalty_NotFound() throws Exception { + //given Long nonExistentPenaltyId = 999L; PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( @@ -160,6 +170,7 @@ void testModifyAdminPenalty_NotFound() throws Exception { "nonexistentIntraId" ); + //then mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", nonExistentPenaltyId) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) @@ -170,6 +181,7 @@ void testModifyAdminPenalty_NotFound() throws Exception { @Test @DisplayName("패널티 부여 (일반적인 상황)") void testGiveAdminPenalty() throws Exception { + //given PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( "test_penalty", "Test reason", @@ -179,12 +191,14 @@ void testGiveAdminPenalty() throws Exception { long penaltyCountBefore = partyPenaltyRepository.count(); + //then mockMvc.perform(post("/party/admin/penalties") .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isCreated()); + //when long penaltyCountAfter = partyPenaltyRepository.count(); assertEquals(penaltyCountBefore + 1, penaltyCountAfter); } @@ -192,6 +206,7 @@ void testGiveAdminPenalty() throws Exception { @Test @DisplayName("패널티 부여 (패널티된 유저에게 추가 패널티 부여)") void testAddAdminPenalty() throws Exception { + //given PartyPenaltyAdminReqDto morePenaltyDto = new PartyPenaltyAdminReqDto( "test_penalty", "Test reason", @@ -199,12 +214,14 @@ void testAddAdminPenalty() throws Exception { reportedTester.getIntraId() ); + //then mockMvc.perform(post("/party/admin/penalties") .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(morePenaltyDto))) .andExpect(status().isCreated()); + //when List penalties = partyPenaltyRepository.findAllByUserId(reportedTester.getId()); int totalPenaltyTime = penalties.stream().mapToInt(PartyPenalty::getPenaltyTime).sum(); @@ -214,6 +231,7 @@ void testAddAdminPenalty() throws Exception { @Test @DisplayName("패널티 부여 - 실패 시나리오(없는 유저)") void testAddAdminPenalty_UserNotFound() throws Exception { + //given PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( "test_penalty", "Test reason", @@ -221,6 +239,7 @@ void testAddAdminPenalty_UserNotFound() throws Exception { "nonexistentIntraId" ); + //then mockMvc.perform(post("/party/admin/penalties") .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) From 45b020e53f0544b857cbdc2f5a006b1d183d64a6 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Tue, 26 Mar 2024 15:20:23 +0900 Subject: [PATCH 08/11] [fix] given when then --- .../penalty/PartyPenaltyControllerTest.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index 2292592ad..a3eb54f02 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -76,7 +76,7 @@ void beforeEach() { class PenaltyAdminTests { @Test - @DisplayName("패널티 조회") + @DisplayName("패널티 조회 - 200") void testRetrievePenaltiesList() throws Exception { //given for (int i = 1; i <= 9; i++) { @@ -103,9 +103,9 @@ void testRetrievePenaltiesList() throws Exception { } @Test - @DisplayName("패널티 조회(pagination)") - //given + @DisplayName("패널티 조회(pagination) - 200") void testPaginationPenaltiesList() throws Exception { + //given for (int i = 1; i <= 15; i++) { testDataUtils.createNewPenalty(reportedTester, "test_penalty_" + i, "test_reason" + i, LocalDateTime.now(), 60); @@ -114,14 +114,14 @@ void testPaginationPenaltiesList() throws Exception { int pageNumber = 2; String url = String.format("/party/admin/penalties?page=%d&size=%d", pageNumber, pageSize); - //then + //when MvcResult result = mockMvc.perform(get(url) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn(); - //when + //then String content = result.getResponse().getContentAsString(); PartyPenaltyListAdminResDto responseDto = objectMapper.readValue(content, PartyPenaltyListAdminResDto.class); @@ -131,7 +131,7 @@ void testPaginationPenaltiesList() throws Exception { } @Test - @DisplayName("패널티 수정") + @DisplayName("패널티 수정 - 204") void testModifyAdminPenalty() throws Exception { //given PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( @@ -141,16 +141,15 @@ void testModifyAdminPenalty() throws Exception { reportedTester.getIntraId() ); - //then + //when mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", testPenaltyId) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isNoContent()); - //when - PartyPenalty updatedPenalty = partyPenaltyRepository.findById(testPenaltyId) - .orElseThrow(() -> new AssertionError("Penalty not found after update")); + //then + PartyPenalty updatedPenalty = partyPenaltyRepository.findById(testPenaltyId).orElseThrow(); assertEquals(penaltyDto.getPenaltyType(), updatedPenalty.getPenaltyType()); assertEquals(penaltyDto.getMessage(), updatedPenalty.getMessage()); @@ -158,7 +157,7 @@ void testModifyAdminPenalty() throws Exception { } @Test - @DisplayName("패널티 수정 - 실패 시나리오(없는 유저)") + @DisplayName("패널티 수정 - 실패 시나리오(없는 유저) - 404") void testModifyAdminPenalty_NotFound() throws Exception { //given Long nonExistentPenaltyId = 999L; @@ -170,7 +169,7 @@ void testModifyAdminPenalty_NotFound() throws Exception { "nonexistentIntraId" ); - //then + //when mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", nonExistentPenaltyId) .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) @@ -179,7 +178,7 @@ void testModifyAdminPenalty_NotFound() throws Exception { } @Test - @DisplayName("패널티 부여 (일반적인 상황)") + @DisplayName("패널티 부여 (일반적인 상황) - 201") void testGiveAdminPenalty() throws Exception { //given PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( @@ -191,20 +190,20 @@ void testGiveAdminPenalty() throws Exception { long penaltyCountBefore = partyPenaltyRepository.count(); - //then + //when mockMvc.perform(post("/party/admin/penalties") .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(penaltyDto))) .andExpect(status().isCreated()); - //when + //then long penaltyCountAfter = partyPenaltyRepository.count(); assertEquals(penaltyCountBefore + 1, penaltyCountAfter); } @Test - @DisplayName("패널티 부여 (패널티된 유저에게 추가 패널티 부여)") + @DisplayName("패널티 부여 (패널티된 유저에게 추가 패널티 부여) - 201") void testAddAdminPenalty() throws Exception { //given PartyPenaltyAdminReqDto morePenaltyDto = new PartyPenaltyAdminReqDto( @@ -214,14 +213,14 @@ void testAddAdminPenalty() throws Exception { reportedTester.getIntraId() ); - //then + //when mockMvc.perform(post("/party/admin/penalties") .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(morePenaltyDto))) .andExpect(status().isCreated()); - //when + //then List penalties = partyPenaltyRepository.findAllByUserId(reportedTester.getId()); int totalPenaltyTime = penalties.stream().mapToInt(PartyPenalty::getPenaltyTime).sum(); @@ -229,7 +228,7 @@ void testAddAdminPenalty() throws Exception { } @Test - @DisplayName("패널티 부여 - 실패 시나리오(없는 유저)") + @DisplayName("패널티 부여 - 실패 시나리오(없는 유저) - 404") void testAddAdminPenalty_UserNotFound() throws Exception { //given PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( @@ -239,7 +238,7 @@ void testAddAdminPenalty_UserNotFound() throws Exception { "nonexistentIntraId" ); - //then + //when mockMvc.perform(post("/party/admin/penalties") .header("Authorization", "Bearer " + adminAccessToken) .contentType(MediaType.APPLICATION_JSON) From 74b8a66912cd50ca4df9383f0917631abe9ad6c5 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Tue, 26 Mar 2024 15:22:13 +0900 Subject: [PATCH 09/11] [fix] checkstyle --- .../api/admin/penalty/PartyPenaltyControllerTest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index a3eb54f02..7a8018f63 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -134,12 +134,7 @@ void testPaginationPenaltiesList() throws Exception { @DisplayName("패널티 수정 - 204") void testModifyAdminPenalty() throws Exception { //given - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( - "test_penalty", - "Test reason", - 60, - reportedTester.getIntraId() - ); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, reportedTester.getIntraId()); //when mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", testPenaltyId) From 7d1cb52c696ea6d13e8b8d1db6cfdddcf0f08e8e Mon Sep 17 00:00:00 2001 From: jungjkim Date: Tue, 26 Mar 2024 15:24:52 +0900 Subject: [PATCH 10/11] [fix] checkstyle --- .../api/admin/penalty/PartyPenaltyControllerTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index 7a8018f63..a3eb54f02 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -134,7 +134,12 @@ void testPaginationPenaltiesList() throws Exception { @DisplayName("패널티 수정 - 204") void testModifyAdminPenalty() throws Exception { //given - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, reportedTester.getIntraId()); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( + "test_penalty", + "Test reason", + 60, + reportedTester.getIntraId() + ); //when mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", testPenaltyId) From 9abe0112b4b8393eb4eab4f6f4764a5842da504e Mon Sep 17 00:00:00 2001 From: seungsje Date: Tue, 26 Mar 2024 16:50:51 +0900 Subject: [PATCH 11/11] =?UTF-8?q?[fix]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A4=84=20=EB=B0=94=EA=BF=88=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../penalty/PartyPenaltyControllerTest.java | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java index a3eb54f02..973a6fdfd 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/admin/penalty/PartyPenaltyControllerTest.java @@ -50,7 +50,6 @@ public class PartyPenaltyControllerTest { private AuthTokenProvider tokenProvider; @Autowired private PartyPenaltyRepository partyPenaltyRepository; - private User userTester; private User reportedTester; private User adminUser; @@ -134,12 +133,8 @@ void testPaginationPenaltiesList() throws Exception { @DisplayName("패널티 수정 - 204") void testModifyAdminPenalty() throws Exception { //given - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( - "test_penalty", - "Test reason", - 60, - reportedTester.getIntraId() - ); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, + reportedTester.getIntraId()); //when mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", testPenaltyId) @@ -162,12 +157,8 @@ void testModifyAdminPenalty_NotFound() throws Exception { //given Long nonExistentPenaltyId = 999L; - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( - "test_penalty", - "test_reason", - 60, - "nonexistentIntraId" - ); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, + reportedTester.getIntraId()); //when mockMvc.perform(patch("/party/admin/penalties/{penaltyId}", nonExistentPenaltyId) @@ -181,12 +172,8 @@ void testModifyAdminPenalty_NotFound() throws Exception { @DisplayName("패널티 부여 (일반적인 상황) - 201") void testGiveAdminPenalty() throws Exception { //given - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( - "test_penalty", - "Test reason", - 60, - userTester.getIntraId() - ); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, + userTester.getIntraId()); long penaltyCountBefore = partyPenaltyRepository.count(); @@ -206,12 +193,8 @@ void testGiveAdminPenalty() throws Exception { @DisplayName("패널티 부여 (패널티된 유저에게 추가 패널티 부여) - 201") void testAddAdminPenalty() throws Exception { //given - PartyPenaltyAdminReqDto morePenaltyDto = new PartyPenaltyAdminReqDto( - "test_penalty", - "Test reason", - 60, - reportedTester.getIntraId() - ); + PartyPenaltyAdminReqDto morePenaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, + reportedTester.getIntraId()); //when mockMvc.perform(post("/party/admin/penalties") @@ -231,12 +214,8 @@ void testAddAdminPenalty() throws Exception { @DisplayName("패널티 부여 - 실패 시나리오(없는 유저) - 404") void testAddAdminPenalty_UserNotFound() throws Exception { //given - PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto( - "test_penalty", - "Test reason", - 60, - "nonexistentIntraId" - ); + PartyPenaltyAdminReqDto penaltyDto = new PartyPenaltyAdminReqDto("test_penalty", "Test reason", 60, + "nonexistentIntraId"); //when mockMvc.perform(post("/party/admin/penalties")