Skip to content

Commit

Permalink
test: gpt 비용 제한을 위한 질문수 제한 test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoya324 committed Sep 25, 2024
1 parent 7882ca7 commit f169f8b
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)));
}
}

0 comments on commit f169f8b

Please sign in to comment.