Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TSK-44] feat: gpt 비용 제한을 위한 질문수 제한 #86

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)));
}
}
Loading