diff --git a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java index a492f8ddb..b3a59ab78 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -2,48 +2,66 @@ import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; import static com.funeat.acceptance.common.CommonSteps.정상_생성; -import static com.funeat.acceptance.product.ProductSteps.간편식사; -import static com.funeat.acceptance.recipe.RecipeSteps.레시피_추가_요청; +import static com.funeat.acceptance.recipe.RecipeSteps.레시피_생성_요청; import static com.funeat.acceptance.recipe.RecipeSteps.여러_사진_요청; +import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점_1점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점_1점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점_1점_생성; +import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; +import com.funeat.acceptance.auth.LoginSteps; import com.funeat.acceptance.common.AcceptanceTest; -import com.funeat.acceptance.common.LoginSteps; -import com.funeat.product.domain.Category; import com.funeat.product.domain.Product; -import com.funeat.recipe.dto.RecipeCreateRequest; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @SuppressWarnings("NonAsciiCharacters") public class RecipeAcceptanceTest extends AcceptanceTest { - @Test - void 레시피를_작성한다() { - // given - 카테고리_추가_요청(간편식사); - final var product1 = new Product("삼각김밥1", 1000L, "image.png", "맛있는 삼각김밥1", 간편식사); - final var product2 = new Product("삼각김밥2", 2000L, "image.png", "맛있는 삼각김밥2", 간편식사); - final var product3 = new Product("삼각김밥3", 1500L, "image.png", "맛있는 삼각김밥3", 간편식사); - final var products = List.of(product1, product2, product3); - 복수_상품_추가_요청(products); - final var loginCookie = LoginSteps.로그인_쿠키를_얻는다(); - - // when - final var request = new RecipeCreateRequest("제일로 맛있는 레시피", - List.of(product1.getId(), product2.getId(), product3.getId()), - "우선 밥을 넣어요. 그리고 밥을 또 넣어요. 그리고 밥을 또 넣으면.. 끝!!"); - final var images = 여러_사진_요청(3); - final var response = 레시피_추가_요청(request, images, loginCookie); - - // then - STATUS_CODE를_검증한다(response, 정상_생성); - } + @Nested + class writeRecipe_테스트 { + + @Nested + class 성공_테스트 { + + @Test + void 레시피를_작성한다() { + // given + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product1 = 상품_삼각김밥_가격1000원_평점_1점_생성(category); + final var product2 = 상품_삼각김밥_가격3000원_평점_1점_생성(category); + final var product3 = 상품_삼각김밥_가격2000원_평점_1점_생성(category); + 복수_상품_저장(product1, product2, product3); + + final var productIds = 상품_아이디_변환(product1, product2, product3); + final var request = 레시피추가요청_생성(productIds); + + final var images = 여러_사진_요청(3); + + final var loginCookie = LoginSteps.로그인_쿠키를_얻는다(); + + // when + final var response = 레시피_생성_요청(request, images, loginCookie); + + // then + STATUS_CODE를_검증한다(response, 정상_생성); + } + } - private Long 카테고리_추가_요청(final Category category) { - return categoryRepository.save(category).getId(); + @Nested + class 실패_테스트 { + } } - private void 복수_상품_추가_요청(final List products) { - productRepository.saveAll(products); + private List 상품_아이디_변환(final Product... products) { + return Stream.of(products) + .map(Product::getId) + .collect(Collectors.toList()); } } diff --git a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java index e41385bd2..94fde48ab 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java @@ -7,19 +7,18 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; -import io.restassured.specification.RequestSpecification; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; public class RecipeSteps { - public static ExtractableResponse 레시피_추가_요청(final RecipeCreateRequest recipeRequest, - final List imageList, + public static ExtractableResponse 레시피_생성_요청(final RecipeCreateRequest recipeRequest, + final List images, final String loginCookie) { final var request = given() .cookie("JSESSIONID", loginCookie); - imageList.forEach(request::multiPart); + images.forEach(request::multiPart); return request .multiPart("recipeRequest", recipeRequest, "application/json") .when() diff --git a/backend/src/test/java/com/funeat/common/ServiceTest.java b/backend/src/test/java/com/funeat/common/ServiceTest.java index 803e8a317..f13aa9fa7 100644 --- a/backend/src/test/java/com/funeat/common/ServiceTest.java +++ b/backend/src/test/java/com/funeat/common/ServiceTest.java @@ -18,7 +18,6 @@ import com.funeat.product.persistence.ProductRepository; import com.funeat.recipe.persistence.RecipeImageRepository; import com.funeat.recipe.persistence.RecipeRepository; -import com.funeat.review.application.ImageService; import com.funeat.review.application.ReviewService; import com.funeat.review.domain.Review; import com.funeat.review.domain.ReviewTag; diff --git a/backend/src/test/java/com/funeat/fixture/RecipeFixture.java b/backend/src/test/java/com/funeat/fixture/RecipeFixture.java new file mode 100644 index 000000000..dca3cfbdf --- /dev/null +++ b/backend/src/test/java/com/funeat/fixture/RecipeFixture.java @@ -0,0 +1,11 @@ +package com.funeat.fixture; + +import com.funeat.recipe.dto.RecipeCreateRequest; +import java.util.List; + +public class RecipeFixture { + + public static RecipeCreateRequest 레시피추가요청_생성(final List productIds) { + return new RecipeCreateRequest("제일로 맛있는 레시피", productIds, "밥 추가, 밥 추가, 밥 추가.. 끝!!"); + } +}