Skip to content

Commit

Permalink
✨ [Feat] ReportRequest 검증 및 테스트 케이스 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjin3395 committed Jan 17, 2025
1 parent e70f2a9 commit 38ef9a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import org.hibernate.validator.constraints.Length;
Expand All @@ -27,6 +28,7 @@ public class ReportRequest {

@Min(value = 1, message = "path code는 1 이상의 값이어야 합니다.")
@Max(value = 3, message = "path code는 3 이하의 값이어야 합니다.")
@NotNull(message = "path code는 필수 값 입니다.")
Integer pathCode;

Long boardId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,37 @@ void addReportFailedWhenContentsSizeExceeds() throws Exception {
.andExpect(jsonPath("$.message").value("contents는 1000자 이내여야 합니다."));
}

@DisplayName("실패: 경로 코드 값이 없는 경우 에러 응답을 반환한다.")
@Test
void addReportFailedWhenPathCodeIsNull() throws Exception {
// given
List<Integer> reportCodeList = List.of(1, 2, 3);

ReportRequest request = ReportRequest.builder()
.reportCodeList(reportCodeList)
.contents("contents")
.pathCode(null)
.boardId(null)
.build();

ReportInsertResponse response = ReportInsertResponse.builder()
.reportId(1L)
.message("신고가 정상적으로 접수 되었습니다.")
.build();

given(reportFacadeService.addReport(any(Member.class), eq(TARGET_MEMBER_ID),
any(ReportRequest.class))).willReturn(response);

// when // then
mockMvc.perform(post(API_URL_PREFIX + "/{memberId}", TARGET_MEMBER_ID)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value("VALID_ERROR"))
.andExpect(jsonPath("$.message").value("path code는 필수 값 입니다."));

}

@DisplayName("실패: 경로 코드가 1보다 작은 경우 에러 응답을 반환한다.")
@Test
void addReportFailedWhenPathCodeLessThanMin() throws Exception {
Expand Down Expand Up @@ -277,7 +308,7 @@ void addReportFailedSucceeds() throws Exception {
.andExpect(jsonPath("$.data.message").value("신고가 정상적으로 접수 되었습니다."));
}

@DisplayName("텍스트, 경로 코드, 게시글 id가 null일 때 성공")
@DisplayName("텍스트, 게시글 id가 null일 때 성공")
@Test
void addReportFailedSucceedsWhenNull() throws Exception {
// given
Expand All @@ -286,7 +317,7 @@ void addReportFailedSucceedsWhenNull() throws Exception {
ReportRequest request = ReportRequest.builder()
.reportCodeList(reportCodeList)
.contents(null)
.pathCode(null)
.pathCode(1)
.boardId(null)
.build();

Expand Down

0 comments on commit 38ef9a8

Please sign in to comment.