Skip to content

Commit

Permalink
refactor: 레시피 테스트 리팩터링
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed Aug 9, 2023
1 parent 9de9146 commit d4a495e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Product> products) {
productRepository.saveAll(products);
private List<Long> 상품_아이디_변환(final Product... products) {
return Stream.of(products)
.map(Product::getId)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> 레시피_가_요청(final RecipeCreateRequest recipeRequest,
final List<MultiPartSpecification> imageList,
public static ExtractableResponse<Response> 레시피_생성_요청(final RecipeCreateRequest recipeRequest,
final List<MultiPartSpecification> 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()
Expand Down
1 change: 0 additions & 1 deletion backend/src/test/java/com/funeat/common/ServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions backend/src/test/java/com/funeat/fixture/RecipeFixture.java
Original file line number Diff line number Diff line change
@@ -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<Long> productIds) {
return new RecipeCreateRequest("제일로 맛있는 레시피", productIds, "밥 추가, 밥 추가, 밥 추가.. 끝!!");
}
}

0 comments on commit d4a495e

Please sign in to comment.