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] =?UTF-8?q?test:=20gpt=20=EB=B9=84=EC=9A=A9=20=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=A7=88=EB=AC=B8?= =?UTF-8?q?=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