Skip to content

Commit

Permalink
Merge pull request #86 from MARU-EGG/feat/질문-크기-제한
Browse files Browse the repository at this point in the history
[TSK-44] feat: gpt 비용 제한을 위한 질문수 제한
  • Loading branch information
Hoya324 authored Sep 25, 2024
2 parents e2f77c9 + f169f8b commit d18a1f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,6 +20,7 @@ public record QuestionRequest(

@Schema(description = "질문 내용", example = "수시 입학 요강에 대해 알려주세요.")
@NotBlank(message = "질문은 비어있을 수 없습니다.")
@Size(max = 1000, message = "크기가 0에서 1000 사이여야 합니다.")
String content
) {
}
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 d18a1f2

Please sign in to comment.