Skip to content

Commit

Permalink
test: 문서화 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
BGuga committed Nov 2, 2023
1 parent c7214ad commit c96aefd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
14 changes: 12 additions & 2 deletions backend/src/documentation/adoc/quiz.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ include::{snippets}/quiz/detail/http-response.adoc[]

==== Request

include::{snippets}/quiz/list/http-request.adoc[]
include::{snippets}/quiz/list-keyword/http-request.adoc[]

==== Response

include::{snippets}/quiz/list/http-response.adoc[]
include::{snippets}/quiz/list-keyword/http-response.adoc[]

=== 커리큘럼별 퀴즈 목록 조회

==== Request

include::{snippets}/quiz/list-curriculum/http-request.adoc[]

==== Response

include::{snippets}/quiz/list-curriculum/http-response.adoc[]

=== 퀴즈 삭제

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@


import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;

import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import wooteco.prolog.NewDocumentation;
import wooteco.prolog.roadmap.application.QuizService;
import wooteco.prolog.roadmap.application.dto.CurriculumQuizResponse;
import wooteco.prolog.roadmap.application.dto.QuizRequest;
import wooteco.prolog.roadmap.application.dto.QuizResponse;
import wooteco.prolog.roadmap.application.dto.QuizzesResponse;
Expand Down Expand Up @@ -61,10 +68,47 @@ public class QuizDocumentation extends NewDocumentation {

given
.when().get("/sessions/{sessionId}/keywords/{keywordId}/quizs", 1L, 1L)
.then().log().all().apply(document("quiz/list"))
.then().log().all().apply(document("quiz/list-keyword"))
.statusCode(HttpStatus.OK.value());
}

@Test
void Curriculum별_Quiz_조회() {
given(quizService.findQuizzesByCurriculumId(anyLong()))
.willReturn(makeMockResponse());

given
.when().get("/curriculums/{curriculumId}/quizzes", 1L)
.then().log().all().apply(document("quiz/list-curriculum"))
.statusCode(HttpStatus.OK.value());
}

private List<CurriculumQuizResponse> makeMockResponse() {
CurriculumQuizResponse response1 = new CurriculumQuizResponse() {
@Override
public Long getId() {
return 1L;
}

@Override
public String getQuestion() {
return "question1";
}
};
CurriculumQuizResponse response2 = new CurriculumQuizResponse() {
@Override
public Long getId() {
return 2L;
}

@Override
public String getQuestion() {
return "question2";
}
};
return Arrays.asList(response1, response2);
}

@Test
void 퀴즈_수정() {
doNothing().when(quizService).updateQuiz(any(), any());
Expand Down

0 comments on commit c96aefd

Please sign in to comment.