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

✨ add recipe retrieval docs #127

Merged
merged 2 commits into from
Jul 31, 2024
Merged
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 @@ -5,10 +5,10 @@
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
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 io.restassured.RestAssured;
import io.restassured.http.ContentType;
import net.pengcook.RestDocsSetting;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -20,21 +20,63 @@ class RecipeControllerTest extends RestDocsSetting {
@Test
@DisplayName("레시피 개요 목록을 조회한다.")
void readRecipes() {
RestAssured.given().log().all()
.contentType(ContentType.JSON)
RestAssured.given(spec).log().all()
.filter(document(DEFAULT_RESTDOCS_PATH,
"특정 페이지의 레시피 목록을 조회합니다.",
"레시피 조회 API",
queryParameters(
parameterWithName("pageNumber").description("페이지 번호"),
parameterWithName("pageSize").description("페이지 크기")
),
responseFields(
fieldWithPath("[]").description("레시피 목록"),
fieldWithPath("[].recipeId").description("레시피 아이디"),
fieldWithPath("[].title").description("레시피 제목"),
fieldWithPath("[].author").description("작성자 정보"),
fieldWithPath("[].author.authorId").description("작성자 아이디"),
fieldWithPath("[].author.authorName").description("작성자 이름"),
fieldWithPath("[].author.authorImage").description("작성자 이미지"),
fieldWithPath("[].cookingTime").description("조리 시간"),
fieldWithPath("[].thumbnail").description("썸네일 이미지"),
fieldWithPath("[].difficulty").description("난이도"),
fieldWithPath("[].likeCount").description("좋아요 수"),
fieldWithPath("[].description").description("레시피 설명"),
fieldWithPath("[].category").description("카테고리 목록"),
fieldWithPath("[].category[].categoryId").description("카테고리 아이디"),
fieldWithPath("[].category[].categoryName").description("카테고리 이름"),
fieldWithPath("[].ingredient").description("재료 목록"),
fieldWithPath("[].ingredient[].ingredientId").description("재료 아이디"),
fieldWithPath("[].ingredient[].ingredientName").description("재료 이름"),
fieldWithPath("[].ingredient[].requirement").description("재료 필수 여부")
)))
.queryParam("pageNumber", 0)
.queryParam("pageSize", 3)
.when()
.get("/api/recipes?pageNumber=0&pageSize=3")
.get("/api/recipes")
.then().log().all()
.body("size()", is(3));
}

@Test
@DisplayName("레시피 상세 스텝을 조회한다.")
void readRecipeSteps() {
RestAssured.given().log().all()
.contentType(ContentType.JSON)
RestAssured.given(spec).log().all()
.filter(document(DEFAULT_RESTDOCS_PATH,
"특정 레시피의 상세 스텝을 조회합니다.",
"레시피 상세 스텝 조회 API",
pathParameters(
parameterWithName("id").description("레시피 아이디")
),
responseFields(
fieldWithPath("[]").description("레시피 스텝 목록"),
fieldWithPath("[].id").description("레시피 스텝 아이디"),
fieldWithPath("[].recipeId").description("레시피 아이디"),
fieldWithPath("[].image").description("레시피 스텝 이미지"),
fieldWithPath("[].description").description("레시피 스텝 설명"),
fieldWithPath("[].sequence").description("레시피 스텝 순서")
)))
.when()
.get("/api/recipes/1/steps")
.get("/api/recipes/{id}/steps", 1L)
.then().log().all()
.body("size()", is(3));
}
Expand All @@ -44,6 +86,8 @@ void readRecipeSteps() {
void readRecipesOfCategory() {
RestAssured.given(spec).log().all()
.filter(document(DEFAULT_RESTDOCS_PATH,
"특정 카테고리 페이지의 레시피 목록을 조회합니다.",
"카테고리별 레시피 조회 API",
queryParameters(
parameterWithName("category").description("카테고리"),
parameterWithName("pageNumber").description("페이지 번호"),
Expand Down
Loading