Skip to content

Commit

Permalink
docs: 책과 연관된 리뷰 조회 API Docs 추가 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwooo committed May 24, 2024
1 parent f823362 commit 5b17ef4
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 11 deletions.
14 changes: 14 additions & 0 deletions src/docs/asciidoc/api/review/review.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
[[review-create]]

=== 도서와 연관된 리뷰 조회

==== HTTP Request

include::{snippets}/review/get-related-book/http-request.adoc[]
include::{snippets}/review/get-related-book/path-parameters.adoc[]
include::{snippets}/review/get-related-book/query-parameters.adoc[]

==== HTTP Response

include::{snippets}/review/get-related-book/http-response.adoc[]
include::{snippets}/review/get-related-book/response-fields.adoc[]

=== 한줄평 생성

==== HTTP Request
Expand Down
121 changes: 110 additions & 11 deletions src/test/java/com/jisungin/docs/review/ReviewControllerDocsTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
package com.jisungin.docs.review;

import com.jisungin.api.review.ReviewController;
import com.jisungin.api.review.request.ReviewCreateRequest;
import com.jisungin.application.review.ReviewService;
import com.jisungin.docs.RestDocsSupport;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.jisungin.api.review.ReviewController;
import com.jisungin.api.review.request.ReviewCreateRequest;
import com.jisungin.application.OffsetLimit;
import com.jisungin.application.SliceResponse;
import com.jisungin.application.review.ReviewService;
import com.jisungin.application.review.response.ReviewWithRatingResponse;
import com.jisungin.docs.RestDocsSupport;
import java.util.List;
import java.util.stream.LongStream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.restdocs.payload.JsonFieldType;

public class ReviewControllerDocsTest extends RestDocsSupport {

private final ReviewService reviewService = mock(ReviewService.class);
Expand All @@ -29,6 +43,91 @@ protected Object initController() {
return new ReviewController(reviewService);
}

@DisplayName("도서와 연관된 리뷰 조회 API")
@Test
void findBookReviews() throws Exception {
// given
String isbn = "000000000001";

List<ReviewWithRatingResponse> response = LongStream.rangeClosed(1, 10)
.mapToObj(i -> ReviewWithRatingResponse.builder()
.reviewId(i)
.ratingId(i)
.username("작성자 " + i)
.profileImage("http://www.profile-image.com/" + i)
.reviewContent("리뷰 내용 " + i)
.starRating(3.5)
.likeCount(20L)
.build())
.toList();

given(reviewService.findBookReviews(anyString(), any(OffsetLimit.class)))
.willReturn(SliceResponse.of(response, 0, 10, true));

// when // then
mockMvc.perform(
get("/v1/books/{isbn}/reviews", isbn)
.param("page", "1")
.param("size", "10")
.param("order", "like")
.accept(MediaType.APPLICATION_JSON)
)
.andDo(print())
.andExpect(status().isOk())
.andDo(document("review/get-related-book",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
pathParameters(
parameterWithName("isbn")
.description("도서 ISBN")
),
queryParameters(
parameterWithName("page")
.description("페이지 번호"),
parameterWithName("size")
.description("페이지 사이즈"),
parameterWithName("order").description(
"정렬 기준: like(좋아요 순), recent(최신순), rating_desc(별점 높은 순), rating_asc(별점 낮은 순)")
),
responseFields(
fieldWithPath("code").type(JsonFieldType.NUMBER)
.description("코드"),
fieldWithPath("status").type(JsonFieldType.STRING)
.description("상태"),
fieldWithPath("message").type(JsonFieldType.STRING)
.description("메세지"),
fieldWithPath("data").type(JsonFieldType.OBJECT)
.description("응답 데이터"),
fieldWithPath("data.hasContent").type(JsonFieldType.BOOLEAN)
.description("데이터 존재 여부"),
fieldWithPath("data.number").type(JsonFieldType.NUMBER)
.description("현재 페이지 번호"),
fieldWithPath("data.size").type(JsonFieldType.NUMBER)
.description("현재 페이지 사이즈"),
fieldWithPath("data.isFirst").type(JsonFieldType.BOOLEAN)
.description("첫 번째 페이지 여부"),
fieldWithPath("data.isLast").type(JsonFieldType.BOOLEAN)
.description("마지막 페에지 여부"),
fieldWithPath("data.content[]").type(JsonFieldType.ARRAY)
.description("슬라이싱 데이터"),
fieldWithPath("data.content[].reviewId").type(JsonFieldType.NUMBER)
.description("리뷰 ID"),
fieldWithPath("data.content[].ratingId").type(JsonFieldType.NUMBER)
.description("별점 ID"),
fieldWithPath("data.content[].username").type(JsonFieldType.STRING)
.description("작성자 이름"),
fieldWithPath("data.content[].profileImage").type(JsonFieldType.STRING)
.description("작성자 프로필 이미지 URL"),
fieldWithPath("data.content[].reviewContent").type(JsonFieldType.STRING)
.description("리뷰 작성 내용"),
fieldWithPath("data.content[].starRating").type(JsonFieldType.NUMBER)
.description("별점 점수"),
fieldWithPath("data.content[].likeCount").type(JsonFieldType.NUMBER)
.description("좋아요 개수")
))
);
}

@DisplayName("한줄평을 생성하는 API")
@Test
void createReview() throws Exception {
Expand Down

0 comments on commit 5b17ef4

Please sign in to comment.