From 269b6772934ba2d7ff30649eaf6df6bc696ad761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Wed, 25 Sep 2024 21:52:00 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20gpt=20=EB=B9=84=EC=9A=A9=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=EC=88=98=20=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iphak/maru_egg/question/dto/request/QuestionRequest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java b/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java index 0d1a743..d3404a7 100644 --- a/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java +++ b/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java @@ -3,6 +3,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import mju.iphak.maru_egg.question.domain.QuestionCategory; import mju.iphak.maru_egg.question.domain.QuestionType; @@ -19,6 +20,7 @@ public record QuestionRequest( @Schema(description = "질문 내용", example = "수시 입학 요강에 대해 알려주세요.") @NotBlank(message = "질문은 비어있을 수 없습니다.") + @Size(max = 1000) String content ) { } \ No newline at end of file From 7882ca7eee8c8d506d51a66d2a8335362ce77d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Wed, 25 Sep 2024 22:01:56 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20gpt=20=EB=B9=84=EC=9A=A9=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=EC=88=98=20=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iphak/maru_egg/question/dto/request/QuestionRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java b/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java index d3404a7..fe8c2ba 100644 --- a/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java +++ b/src/main/java/mju/iphak/maru_egg/question/dto/request/QuestionRequest.java @@ -20,7 +20,7 @@ public record QuestionRequest( @Schema(description = "질문 내용", example = "수시 입학 요강에 대해 알려주세요.") @NotBlank(message = "질문은 비어있을 수 없습니다.") - @Size(max = 1000) + @Size(max = 1000, message = "크기가 0에서 1000 사이여야 합니다.") String content ) { } \ No newline at end of file From f169f8be345266c69ae03b40e0bfec81838c7c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Wed, 25 Sep 2024 22:02:11 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test:=20gpt=20=EB=B9=84=EC=9A=A9=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=EC=88=98=20=EC=A0=9C=ED=95=9C=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../question/api/QuestionControllerTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/mju/iphak/maru_egg/question/api/QuestionControllerTest.java b/src/test/java/mju/iphak/maru_egg/question/api/QuestionControllerTest.java index 94f4840..3cf4ded 100644 --- a/src/test/java/mju/iphak/maru_egg/question/api/QuestionControllerTest.java +++ b/src/test/java/mju/iphak/maru_egg/question/api/QuestionControllerTest.java @@ -137,6 +137,20 @@ private void initializeTestData() { .andExpect(jsonPath("$.data").isArray()); } + @Test + void 질문_생성_API_검증_오류_1000자_초과() throws Exception { + // given + String oversizedContent = "a".repeat(1001); // 1001자로 생성 + QuestionRequest request = new QuestionRequest(QuestionType.SUSI, QuestionCategory.ADMISSION_GUIDELINE, + oversizedContent); + + // when + ResultActions resultActions = performPostRequest("/api/questions", request); + + // then + verifyValidationError(resultActions, "content", "크기가 0에서 1000 사이여야 합니다"); + } + private ResultActions performPostRequest(String url, Object content) throws Exception { return mvc.perform(post(url) .contentType(MediaType.APPLICATION_JSON) @@ -177,4 +191,12 @@ private void verifyQuestionListResponse(ResultActions resultActions, String expe .andExpect(jsonPath("$[0].answer.content").isNotEmpty()) .andExpect(jsonPath("$[0].answer.renewalYear").isNotEmpty()); } + + private void verifyValidationError(ResultActions resultActions, String field, String expectedMessage) throws + Exception { + resultActions + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value(org.hamcrest.Matchers.containsString(expectedMessage))) + .andExpect(jsonPath("$.message").value(org.hamcrest.Matchers.containsString(field))); + } } \ No newline at end of file