From b0bbed324136b048d128780a05eeae75f96f573f Mon Sep 17 00:00:00 2001 From: Dabeen Jeong Date: Tue, 19 Sep 2023 17:29:56 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20refactor:=20=EC=9D=B8=EC=88=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=A6=AC=ED=8C=A9=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20(#653)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 멤버 생성 Fixture를 사용하게 변경 * refactor: 로그인 쿠키를 얻는 방식 변경 * refactor: ReviewSteps 수정, 리뷰 인수테스트 리팩터링 * refactor: MemberAcceptanceTest, AuthAcceptanceTest 리팩터링 * refactor: CategoryAcceptanceTest 리팩터링 * refactor: TagAcceptanceTest 리팩터링 * refactor: MemberAcceptanceTst 꿀조합 리팩터링 * refactor: 데이터를 순차적으로 저장하도록 saveAll 대신 save 사용하는걸로 변경 * refactor: ProductAcceptanceTest 리팩터링 * refactor: 페이지 요청 생성 방식 변경 * refactor: 레시피 요청 로직 리팩터링 * refactor: 인수 테스트 코드 리팩터링 * fix: PageRequest 생성 메서드의 파라미터 타입 변경 * refactor: 로그인 쿠키를 얻는 메서드명 이름 변경 * refactor: 유저 닉네임 생성 요청을 공통 메서드로 분리 * style: 코드 포맷 적용 * refactor: softAssertions -> soft 네이밍 변경 * refactor: 인수테스트에 API가 없는 저장 메서드만 남기고, 리포지토리 저C장 메서드 삭제,레시피 이미지 메서드 생성 * refactor: 페이지를_검증하다_메서드를 공통 메서드로 적용 * refactor: 리뷰 인수 테스트에 페이지 검증, 결과 검증 분리 * refactor: 여러명이 리뷰와 레시피에 좋아요 누르는 기능 공통 메서드화 * refactor: 로그인 쿠키가 멤버를 생성하므로 필요없는 로직 제거 * refactor: 태그 인수테스트 검증 값을 숫자에서 이름으로 변경 * feat: Fixture 데이터 추가 * refactor: ReviewAcceptanceTest 변수명 최대한 한글로 설정 * refactor: TagAcceptanceTest 변수명 최대한 한글로 작성 * refactor: RecipeAcceptanceTest 변수명 최대한 한글로 작성 * refactor: CategoryAcceptanceTest 변수명 최대한 한글로 작성 * refactor: ProductAcceptanceTest 변수명 최대한 한글로 작성 * refactor: MemberAcceptanceTest 변수명 최대한 한글로 작성 * refactor: 통과하지 않는 테스트 수정 * refactor: AuthAcceptanceTest 변수 한글로 작성 * refactor: 카카오 로그인이 아닌 OAUTH 로그인으로 테스트 메서드 네이밍 수정 --- .../acceptance/auth/AuthAcceptanceTest.java | 59 +- .../funeat/acceptance/auth/LoginSteps.java | 9 +- .../acceptance/common/AcceptanceTest.java | 83 -- .../funeat/acceptance/common/CommonSteps.java | 33 +- .../common/TestPlatformUserProvider.java | 3 +- .../member/MemberAcceptanceTest.java | 445 ++----- .../funeat/acceptance/member/MemberSteps.java | 4 +- .../product/CategoryAcceptanceTest.java | 49 +- .../product/ProductAcceptanceTest.java | 1087 ++++++----------- .../acceptance/product/ProductSteps.java | 17 +- .../recipe/RecipeAcceptanceTest.java | 821 ++++--------- .../funeat/acceptance/recipe/RecipeSteps.java | 38 +- .../review/ReviewAcceptanceTest.java | 895 +++++--------- .../funeat/acceptance/review/ReviewSteps.java | 25 +- .../acceptance/tag/TagAcceptanceTest.java | 46 +- .../auth/application/AuthServiceTest.java | 2 +- .../com/funeat/fixture/CategoryFixture.java | 4 + .../java/com/funeat/fixture/ImageFixture.java | 8 + .../com/funeat/fixture/MemberFixture.java | 10 + .../java/com/funeat/fixture/PageFixture.java | 89 +- .../com/funeat/fixture/ProductFixture.java | 14 + .../com/funeat/fixture/RecipeFixture.java | 28 +- .../com/funeat/fixture/ReviewFixture.java | 24 +- .../java/com/funeat/fixture/ScoreFixture.java | 11 + .../member/application/MemberServiceTest.java | 36 +- .../com/funeat/member/domain/MemberTest.java | 6 +- .../domain/favorite/RecipeFavoriteTest.java | 24 +- .../RecipeFavoriteRepositoryTest.java | 12 +- .../funeat/product/domain/ProductTest.java | 6 +- .../persistence/ProductRepositoryTest.java | 17 +- .../recipe/application/RecipeServiceTest.java | 63 +- .../persistence/RecipeRepositoryTest.java | 16 +- .../review/application/ReviewServiceTest.java | 46 +- .../persistence/ReviewRepositoryTest.java | 11 +- 34 files changed, 1473 insertions(+), 2568 deletions(-) create mode 100644 backend/src/test/java/com/funeat/fixture/ScoreFixture.java diff --git a/backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java index c05956af3..20c547dd1 100644 --- a/backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java @@ -2,7 +2,7 @@ import static com.funeat.acceptance.auth.LoginSteps.로그아웃_요청; import static com.funeat.acceptance.auth.LoginSteps.로그인_시도_요청; -import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; import static com.funeat.acceptance.auth.LoginSteps.카카오_로그인_버튼_클릭; import static com.funeat.acceptance.common.CommonSteps.LOCATION_헤더에서_리다이렉트_주소_추출; import static com.funeat.acceptance.common.CommonSteps.REDIRECT_URL을_검증한다; @@ -10,7 +10,7 @@ import static com.funeat.acceptance.common.CommonSteps.리다이렉션_영구_이동; import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.정상_처리; -import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; +import static com.funeat.fixture.MemberFixture.멤버1; import static org.assertj.core.api.Assertions.assertThat; import com.funeat.acceptance.common.AcceptanceTest; @@ -26,23 +26,26 @@ @SuppressWarnings("NonAsciiCharacters") public class AuthAcceptanceTest extends AcceptanceTest { + private static final String 마이페이지 = "/members"; + private static final String 메인페이지 = "/"; + @Autowired private AuthService authService; @Nested - class kakaoLogin_성공_테스트 { + class login_성공_테스트 { @Test - void 멤버가_카카오_로그인_버튼을_누르면_카카오_로그인_페이지로_리다이렉트할_수_있다() { + void 멤버가_로그인_버튼을_누르면_OAUTH_로그인_페이지로_리다이렉트할_수_있다() { // given - final var expected = authService.getLoginRedirectUri(); + final var OAUTH_로그인_페이지 = authService.getLoginRedirectUri(); // when - final var response = 카카오_로그인_버튼_클릭(); + final var 응답 = 카카오_로그인_버튼_클릭(); // then - STATUS_CODE를_검증한다(response, 리다이렉션_영구_이동); - REDIRECT_URL을_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 리다이렉션_영구_이동); + REDIRECT_URL을_검증한다(응답, OAUTH_로그인_페이지); } } @@ -51,33 +54,25 @@ class loginAuthorizeUser_성공_테스트 { @Test void 신규_유저라면_마이페이지_경로를_헤더에_담아_응답을_보낸다() { - // given - final var code = "member1"; - final var loginCookie = "12345"; - - // when - final var response = 로그인_시도_요청(code, loginCookie); + // given && when + final var 응답 = 로그인_시도_요청(멤버1); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 헤더에_리다이렉트가_존재하는지_검증한다(response, "/members"); + STATUS_CODE를_검증한다(응답, 정상_처리); + 헤더에_리다이렉트가_존재하는지_검증한다(응답, 마이페이지); } @Test void 기존_유저라면_메인페이지_경로를_헤더에_담아_응답을_보낸다() { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var code = "member1"; - final var loginCookie = 로그인_쿠키를_얻는다(); + 로그인_쿠키_획득(멤버1); // when - final var response = 로그인_시도_요청(code, loginCookie); + final var 응답 = 로그인_시도_요청(멤버1); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 헤더에_리다이렉트가_존재하는지_검증한다(response, "/"); + STATUS_CODE를_검증한다(응답, 정상_처리); + 헤더에_리다이렉트가_존재하는지_검증한다(응답, 메인페이지); } } @@ -86,16 +81,12 @@ class logout_성공_테스트 { @Test void 로그아웃을_하다() { - // given - final var loginCookie = 로그인_쿠키를_얻는다(); - final var expected = "/"; - - // when - final var response = 로그아웃_요청(loginCookie); + // given && when + final var 응답 = 로그아웃_요청(로그인_쿠키_획득(멤버1)); // then - STATUS_CODE를_검증한다(response, 리다이렉션_영구_이동); - REDIRECT_URL을_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 리다이렉션_영구_이동); + REDIRECT_URL을_검증한다(응답, 메인페이지); } } @@ -106,10 +97,10 @@ class logout_실패_테스트 { @NullAndEmptySource void 쿠키가_존재하지_않을_때_로그아웃을_하면_예외가_발생한다(final String cookie) { // given & when - final var response = 로그아웃_요청(cookie); + final var 응답 = 로그아웃_요청(cookie); // then - STATUS_CODE를_검증한다(response, 인증되지_않음); + STATUS_CODE를_검증한다(응답, 인증되지_않음); } } diff --git a/backend/src/test/java/com/funeat/acceptance/auth/LoginSteps.java b/backend/src/test/java/com/funeat/acceptance/auth/LoginSteps.java index 53195d8cf..dd75b30ab 100644 --- a/backend/src/test/java/com/funeat/acceptance/auth/LoginSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/auth/LoginSteps.java @@ -18,10 +18,9 @@ public class LoginSteps { .extract(); } - public static ExtractableResponse 로그인_시도_요청(final String code, final String loginCookie) { + public static ExtractableResponse 로그인_시도_요청(final Long memberId) { return given() - .cookie("FUNEAT", loginCookie) - .param("code", code) + .param("code", String.valueOf(memberId)) .when() .get("/api/login/oauth2/code/kakao") .then() @@ -37,9 +36,9 @@ public class LoginSteps { .extract(); } - public static String 로그인_쿠키를_얻는다() { + public static String 로그인_쿠키_획득(final Long memberId) { return RestAssured.given() - .queryParam("code", "test") + .queryParam("code", String.valueOf(memberId)) .when() .get("/api/login/oauth2/code/kakao") .then() diff --git a/backend/src/test/java/com/funeat/acceptance/common/AcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/common/AcceptanceTest.java index 666dc092d..17c6d725b 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/AcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/common/AcceptanceTest.java @@ -2,28 +2,21 @@ import com.funeat.common.DataClearExtension; import com.funeat.member.domain.Member; -import com.funeat.member.domain.favorite.ReviewFavorite; import com.funeat.member.persistence.MemberRepository; import com.funeat.member.persistence.RecipeFavoriteRepository; import com.funeat.member.persistence.ReviewFavoriteRepository; import com.funeat.product.domain.Category; import com.funeat.product.domain.Product; -import com.funeat.product.domain.ProductRecipe; import com.funeat.product.persistence.CategoryRepository; import com.funeat.product.persistence.ProductRecipeRepository; import com.funeat.product.persistence.ProductRepository; -import com.funeat.recipe.domain.Recipe; -import com.funeat.recipe.domain.RecipeImage; import com.funeat.recipe.persistence.RecipeImageRepository; import com.funeat.recipe.persistence.RecipeRepository; -import com.funeat.review.domain.Review; -import com.funeat.review.domain.ReviewTag; import com.funeat.review.persistence.ReviewRepository; import com.funeat.review.persistence.ReviewTagRepository; import com.funeat.tag.domain.Tag; import com.funeat.tag.persistence.TagRepository; import io.restassured.RestAssured; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -84,91 +77,15 @@ void setUp() { return productRepository.save(product).getId(); } - protected void 복수_상품_저장(final Product... productsToSave) { - final var products = List.of(productsToSave); - - productRepository.saveAll(products); - } - protected Long 단일_카테고리_저장(final Category category) { return categoryRepository.save(category).getId(); } - protected void 복수_카테고리_저장(final Category... categoriesToSave) { - final var categories = List.of(categoriesToSave); - - categoryRepository.saveAll(categories); - } - protected Long 단일_멤버_저장(final Member member) { return memberRepository.save(member).getId(); } - protected void 복수_멤버_저장(final Member... membersToSave) { - final var members = List.of(membersToSave); - - memberRepository.saveAll(members); - } - - protected Long 단일_리뷰_저장(final Review review) { - return reviewRepository.save(review).getId(); - } - - protected void 복수_리뷰_저장(final Review... reviewsToSave) { - final var reviews = List.of(reviewsToSave); - - reviewRepository.saveAll(reviews); - } - protected Long 단일_태그_저장(final Tag tag) { return tagRepository.save(tag).getId(); } - - protected void 복수_태그_저장(final Tag... tagsToSave) { - final var tags = List.of(tagsToSave); - - tagRepository.saveAll(tags); - } - - protected Long 단일_리뷰_태그_저장(final ReviewTag reviewTag) { - return reviewTagRepository.save(reviewTag).getId(); - } - - protected void 복수_리뷰_태그_저장(final ReviewTag... reviewTagsToSave) { - final var reviewTags = List.of(reviewTagsToSave); - - reviewTagRepository.saveAll(reviewTags); - } - - protected Long 단일_리뷰_좋아요_저장(final ReviewFavorite reviewFavorite) { - return reviewFavoriteRepository.save(reviewFavorite).getId(); - } - - protected void 복수_리뷰_좋아요_저장(final ReviewFavorite... reviewFavoritesToSave) { - final var reviewFavorites = List.of(reviewFavoritesToSave); - - reviewFavoriteRepository.saveAll(reviewFavorites); - } - - protected void 단일_꿀조합_저장(final Recipe recipe) { - recipeRepository.save(recipe); - } - - protected void 복수_꿀조합_저장(final Recipe... recipesToSave) { - final var recipeFavorites = List.of(recipesToSave); - - recipeRepository.saveAll(recipeFavorites); - } - - protected void 복수_꿀조합_이미지_저장(final RecipeImage... recipeImageToSave) { - final var recipeFavorites = List.of(recipeImageToSave); - - recipeImageRepository.saveAll(recipeFavorites); - } - - protected void 복수_꿀조합_상품_저장(final ProductRecipe... productRecipeImageToSave) { - final var productRecipes = List.of(productRecipeImageToSave); - - productRecipeRepository.saveAll(productRecipes); - } } diff --git a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java index 8c88808ef..32dcb85e2 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java @@ -2,10 +2,13 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.funeat.common.dto.PageDto; import io.restassured.builder.MultiPartSpecBuilder; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; +import java.util.ArrayList; +import java.util.List; import org.springframework.http.HttpStatus; @SuppressWarnings("NonAsciiCharacters") @@ -42,14 +45,6 @@ public class CommonSteps { assertThat(actual).isEqualTo(expected); } - public static MultiPartSpecification 사진_명세_요청() { - return new MultiPartSpecBuilder("image".getBytes()) - .fileName("testImage.png") - .controlName("image") - .mimeType("image/png") - .build(); - } - public static MultiPartSpecification 사진_명세_요청(final String name) { return new MultiPartSpecBuilder("image".getBytes()) .fileName(String.format("%s.png", name)) @@ -57,4 +52,26 @@ public class CommonSteps { .mimeType("image/png") .build(); } + + public static List 여러개_사진_명세_요청(final String... names) { + final var images = new ArrayList(); + + for (final String name : names) { + images.add(new MultiPartSpecBuilder("image".getBytes()) + .fileName(String.format("%s.png", name)) + .controlName("image") + .mimeType("image/png") + .build() + ); + } + + return images; + } + + public static void 페이지를_검증한다(final ExtractableResponse response, final PageDto expected) { + final var actual = response.jsonPath().getObject("page", PageDto.class); + + assertThat(actual).usingRecursiveComparison() + .isEqualTo(expected); + } } diff --git a/backend/src/test/java/com/funeat/acceptance/common/TestPlatformUserProvider.java b/backend/src/test/java/com/funeat/acceptance/common/TestPlatformUserProvider.java index ba0964e5f..269e27d55 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/TestPlatformUserProvider.java +++ b/backend/src/test/java/com/funeat/acceptance/common/TestPlatformUserProvider.java @@ -11,7 +11,8 @@ public class TestPlatformUserProvider implements PlatformUserProvider { @Override public UserInfoDto getPlatformUser(final String code) { - return new UserInfoDto(1L, code, String.format("www.%s.com", code)); + return new UserInfoDto(Long.valueOf(code), String.format("member%s", code), + String.format("www.member%s.com", code)); } @Override diff --git a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java index 07e3d82c7..9af331623 100644 --- a/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java @@ -1,45 +1,60 @@ package com.funeat.acceptance.member; -import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; import static com.funeat.acceptance.common.CommonSteps.사진_명세_요청; +import static com.funeat.acceptance.common.CommonSteps.여러개_사진_명세_요청; import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_처리; +import static com.funeat.acceptance.common.CommonSteps.페이지를_검증한다; import static com.funeat.acceptance.member.MemberSteps.사용자_꿀조합_조회_요청; import static com.funeat.acceptance.member.MemberSteps.사용자_리뷰_조회_요청; import static com.funeat.acceptance.member.MemberSteps.사용자_정보_수정_요청; import static com.funeat.acceptance.member.MemberSteps.사용자_정보_조회_요청; +import static com.funeat.acceptance.recipe.RecipeSteps.레시피_작성_요청; +import static com.funeat.acceptance.review.ReviewSteps.리뷰_작성_요청; import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND; import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; +import static com.funeat.fixture.ImageFixture.이미지1; +import static com.funeat.fixture.ImageFixture.이미지2; +import static com.funeat.fixture.ImageFixture.이미지3; +import static com.funeat.fixture.MemberFixture.멤버1; +import static com.funeat.fixture.MemberFixture.멤버2; import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; -import static com.funeat.fixture.ProductFixture.레시피_안에_들어가는_상품_생성; +import static com.funeat.fixture.MemberFixture.유저닉네임수정요청_생성; +import static com.funeat.fixture.PageFixture.FIRST_PAGE; +import static com.funeat.fixture.PageFixture.PAGE_SIZE; +import static com.funeat.fixture.PageFixture.마지막페이지O; +import static com.funeat.fixture.PageFixture.응답_페이지_생성; +import static com.funeat.fixture.PageFixture.첫페이지O; +import static com.funeat.fixture.PageFixture.총_데이터_개수; +import static com.funeat.fixture.PageFixture.총_페이지; +import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점5점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; -import static com.funeat.fixture.RecipeFixture.레시피이미지_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test1_평점1점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test2_평점2점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test3_평점3점_재구매O_생성; +import static com.funeat.fixture.RecipeFixture.레시피; +import static com.funeat.fixture.RecipeFixture.레시피1; +import static com.funeat.fixture.RecipeFixture.레시피2; +import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; +import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; +import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매X_생성; +import static com.funeat.fixture.ScoreFixture.점수_1점; +import static com.funeat.fixture.ScoreFixture.점수_2점; +import static com.funeat.fixture.ScoreFixture.점수_3점; +import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.acceptance.common.AcceptanceTest; -import com.funeat.common.dto.PageDto; import com.funeat.member.domain.Member; import com.funeat.member.dto.MemberProfileResponse; import com.funeat.member.dto.MemberRecipeDto; -import com.funeat.member.dto.MemberRecipeProductDto; -import com.funeat.member.dto.MemberRequest; import com.funeat.member.dto.MemberReviewDto; -import com.funeat.recipe.domain.Recipe; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -53,18 +68,12 @@ class getMemberProfile_성공_테스트 { @Test void 사용자_정보를_확인하다() { - // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var loginCookie = 로그인_쿠키를_얻는다(); - - // when - final var response = 사용자_정보_조회_요청(loginCookie); + // given && when + final var 응답 = 사용자_정보_조회_요청(로그인_쿠키_획득(멤버1)); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 사용자_정보_조회를_검증하다(response, member); + STATUS_CODE를_검증한다(응답, 정상_처리); + 사용자_정보_조회를_검증하다(응답, 멤버_멤버1_생성()); } } @@ -75,11 +84,12 @@ class getMemberProfile_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_사용자_정보를_확인시_예외가_발생한다(final String cookie) { // given & when - final var response = 사용자_정보_조회_요청(cookie); + final var 응답 = 사용자_정보_조회_요청(cookie); // then - STATUS_CODE를_검증한다(response, 인증되지_않음); - 비로그인_사용자는_승인되지_않음을_검증하다(response); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } } @@ -88,53 +98,29 @@ class putMemberProfile_성공_테스트 { @Test void 사용자_정보를_수정하다() { - // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var loginCookie = 로그인_쿠키를_얻는다(); - final var image = 사진_명세_요청(); - final var request = new MemberRequest("after"); - - // when - final var response = 사용자_정보_수정_요청(loginCookie, image, request); + // given && when + final var 응답 = 사용자_정보_수정_요청(로그인_쿠키_획득(멤버1), 사진_명세_요청(이미지1), 유저닉네임수정요청_생성("after")); // then - STATUS_CODE를_검증한다(response, 정상_처리); + STATUS_CODE를_검증한다(응답, 정상_처리); } @Test void 사용자_닉네임을_수정하다() { - // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var loginCookie = 로그인_쿠키를_얻는다(); - final var image = 사진_명세_요청(); - final var request = new MemberRequest("after"); - - // when - final var response = 사용자_정보_수정_요청(loginCookie, image, request); + // given && when + final var 응답 = 사용자_정보_수정_요청(로그인_쿠키_획득(멤버1), 사진_명세_요청(이미지1), 유저닉네임수정요청_생성("member1")); // then - STATUS_CODE를_검증한다(response, 정상_처리); + STATUS_CODE를_검증한다(응답, 정상_처리); } @Test void 사용자_이미지를_수정하다() { - // given - final var member = new Member("member1", "testImage.png", "1"); - 단일_멤버_저장(member); - - final var loginCookie = 로그인_쿠키를_얻는다(); - final var image = 사진_명세_요청(); - final var request = new MemberRequest(member.getNickname()); - - // when - final var response = 사용자_정보_수정_요청(loginCookie, image, request); + // given && when + final var 응답 = 사용자_정보_수정_요청(로그인_쿠키_획득(멤버1), 사진_명세_요청(이미지2), 유저닉네임수정요청_생성("after")); // then - STATUS_CODE를_검증한다(response, 정상_처리); + STATUS_CODE를_검증한다(응답, 정상_처리); } } @@ -144,38 +130,25 @@ class putMemberProfile_실패_테스트 { @ParameterizedTest @NullAndEmptySource void 로그인_하지않은_사용자가_사용자_정보_수정시_예외가_발생한다(final String cookie) { - // given - final var image = 사진_명세_요청(); - final var request = new MemberRequest("after"); - - // when - final var response = 사용자_정보_수정_요청(cookie, image, request); + // given && when + final var 응답 = 사용자_정보_수정_요청(cookie, 사진_명세_요청(이미지1), 유저닉네임수정요청_생성("after")); // then - STATUS_CODE를_검증한다(response, 인증되지_않음); - 비로그인_사용자는_승인되지_않음을_검증하다(response); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @ParameterizedTest @NullAndEmptySource void 사용자가_사용자_정보_수정할때_닉네임_미기입시_예외가_발생한다(final String nickname) { - // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var loginCookie = 로그인_쿠키를_얻는다(); - final var image = 사진_명세_요청(); - final var request = new MemberRequest(nickname); - - // when - final var response = 사용자_정보_수정_요청(loginCookie, image, request); + // given && when + final var 응답 = 사용자_정보_수정_요청(로그인_쿠키_획득(멤버1), 사진_명세_요청(이미지1), 유저닉네임수정요청_생성(nickname)); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "닉네임을 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "닉네임을 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } } @@ -185,72 +158,45 @@ class getMemberReviews_성공_테스트 { @Test void 사용자가_작성한_리뷰를_조회하다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - 복수_멤버_저장(member1, member2); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var review1_1 = 리뷰_이미지test2_평점2점_재구매X_생성(member1, product3, 0L); - final var review2_1 = 리뷰_이미지test1_평점1점_재구매X_생성(member1, product2, 0L); - final var review2_2 = 리뷰_이미지test1_평점1점_재구매X_생성(member2, product2, 0L); - final var review3_1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product1, 0L); - final var review3_2 = 리뷰_이미지test3_평점3점_재구매O_생성(member2, product1, 0L); - 복수_리뷰_저장(review1_1, review2_1, review2_2, review3_1, review3_2); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var member1SortedReviews = List.of(review3_1, review2_1, review1_1); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매X_생성(점수_2점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_1점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(2L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 사용자_리뷰_조회_요청(loginCookie, "createdAt,desc", 0); - final var page = new PageDto(3L, 1L, true, true, 0L, 10L); + final var 응답 = 사용자_리뷰_조회_요청(로그인_쿠키_획득(멤버1), 최신순, FIRST_PAGE); // then - final var expectedReviews = member1SortedReviews.stream() - .map(MemberReviewDto::toDto) - .collect(Collectors.toList()); - - STATUS_CODE를_검증한다(response, 정상_처리); - 사용자_리뷰_조회_결과를_검증한다(response, expectedReviews, page); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 사용자_리뷰_조회_결과를_검증한다(응답, 2); } @Test void 사용자가_작성한_리뷰가_없을때_리뷰는_빈상태로_조회된다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - 복수_멤버_저장(member1, member2); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매X_생성(점수_2점, List.of(태그))); - final var review1_1 = 리뷰_이미지test2_평점2점_재구매X_생성(member2, product3, 0L); - final var review1_2 = 리뷰_이미지test3_평점3점_재구매O_생성(member2, product1, 0L); - 복수_리뷰_저장(review1_1, review1_2); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(0L), 총_페이지(0L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 사용자_리뷰_조회_요청(loginCookie, "createdAt,desc", 0); - final var page = new PageDto(0L, 0L, true, true, 0L, 10L); + final var 응답 = 사용자_리뷰_조회_요청(로그인_쿠키_획득(멤버1), 최신순, FIRST_PAGE); // then - final var expectedReviews = Collections.emptyList(); - - STATUS_CODE를_검증한다(response, 정상_처리); - 사용자_리뷰_조회_결과를_검증한다(response, expectedReviews, page); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 사용자_리뷰_조회_결과를_검증한다(응답, 0); } } @@ -261,11 +207,12 @@ class getMemberReviews_실패_테스트 { @NullAndEmptySource void 로그인하지_않은_사용자가_작성한_리뷰를_조회할때_예외가_발생한다(final String cookie) { // given & when - final var response = 사용자_리뷰_조회_요청(cookie, "createdAt,desc", 0); + final var 응답 = 사용자_리뷰_조회_요청(cookie, 최신순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 인증되지_않음); - 비로그인_사용자는_승인되지_않음을_검증하다(response); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } } @@ -275,159 +222,64 @@ class getMemberRecipes_성공_테스트 { @Test void 사용자가_작성한_꿀조합을_조회하다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - 복수_멤버_저장(member1, member2); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1_3 = new Recipe("test-title", "test-content", member1); - final var recipe1_4 = new Recipe("test-title", "test-content", member1); - final var recipe1_1 = new Recipe("test-title", "test-content", member1); - final var recipe1_2 = new Recipe("test-title", "test-content", member1); - final var recipe2_1 = new Recipe("test-title", "test-content", member2); - 복수_꿀조합_저장(recipe1_3, recipe1_4, recipe1_1, recipe1_2, recipe2_1); - - final var product_recipe_1_3_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_3); - final var product_recipe_1_3_2 = 레시피_안에_들어가는_상품_생성(product2, recipe1_3); - - final var product_recipe_1_4_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_4); - final var product_recipe_1_4_2 = 레시피_안에_들어가는_상품_생성(product3, recipe1_4); - - final var product_recipe_1_1_1 = 레시피_안에_들어가는_상품_생성(product2, recipe1_1); - final var product_recipe_1_1_2 = 레시피_안에_들어가는_상품_생성(product3, recipe1_1); - - final var product_recipe_1_2_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_2); - final var product_recipe_1_2_2 = 레시피_안에_들어가는_상품_생성(product2, recipe1_2); - final var product_recipe_1_2_3 = 레시피_안에_들어가는_상품_생성(product3, recipe1_2); - - final var product_recipe_2_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe2_1); - final var product_recipe_2_1_2 = 레시피_안에_들어가는_상품_생성(product2, recipe2_1); - final var product_recipe_2_1_3 = 레시피_안에_들어가는_상품_생성(product3, recipe2_1); - 복수_꿀조합_상품_저장(product_recipe_1_3_1, product_recipe_1_3_2, product_recipe_1_4_1, product_recipe_1_4_2, - product_recipe_1_1_1, product_recipe_1_1_2, product_recipe_1_2_1, product_recipe_1_2_2, - product_recipe_1_2_3, product_recipe_2_1_1, product_recipe_2_1_2, product_recipe_2_1_3); - - final var recipeImage1_3 = 레시피이미지_생성(recipe1_3); - final var recipeImage1_4 = 레시피이미지_생성(recipe1_4); - final var recipeImage1_1 = 레시피이미지_생성(recipe1_1); - final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); - final var recipeImage2_1 = 레시피이미지_생성(recipe2_1); - 복수_꿀조합_이미지_저장(recipeImage1_3, recipeImage1_4, recipeImage1_1, recipeImage1_2, recipeImage2_1); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버2), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(2L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var member1SortedRecipes = List.of(recipe1_2, recipe1_1, recipe1_4, recipe1_3); - final var response = 사용자_꿀조합_조회_요청(loginCookie, "createdAt,desc", 0); - final var page = new PageDto(4L, 1L, true, true, 0L, 10L); - final var expectedRecipeResponses = member1SortedRecipes.stream() - .map(recipe -> { - final var findRecipeImages = recipeImageRepository.findByRecipe(recipe); - final var productsByRecipe = productRecipeRepository.findProductByRecipe(recipe); - final var memberRecipeProductDtos = productsByRecipe.stream() - .map(MemberRecipeProductDto::toDto) - .collect(Collectors.toList()); - return MemberRecipeDto.toDto(recipe, findRecipeImages, memberRecipeProductDtos); - }) - .collect(Collectors.toList()); + final var 응답 = 사용자_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), 최신순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 사용자_꿀조합_조회_결과를_검증한다(response, expectedRecipeResponses, page); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 사용자_꿀조합_조회_결과를_검증한다(응답, List.of(레시피2, 레시피1)); } @Test void 사용자가_작성한_꿀조합이_없을때_꿀조합은_빈상태로_조회된다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - 복수_멤버_저장(member1, member2); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); + 레시피_작성_요청(로그인_쿠키_획득(멤버2), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); - final var recipe2_1 = new Recipe("test-title", "test-content", member2); - 단일_꿀조합_저장(recipe2_1); - - final var product_recipe_2_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe2_1); - final var product_recipe_2_1_2 = 레시피_안에_들어가는_상품_생성(product2, recipe2_1); - final var product_recipe_2_1_3 = 레시피_안에_들어가는_상품_생성(product3, recipe2_1); - 복수_꿀조합_상품_저장(product_recipe_2_1_1, product_recipe_2_1_2, product_recipe_2_1_3); - - final var recipeImage2_1 = 레시피이미지_생성(recipe2_1); - 복수_꿀조합_이미지_저장(recipeImage2_1); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(0L), 총_페이지(0L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 사용자_꿀조합_조회_요청(loginCookie, "createdAt,desc", 0); - final var page = new PageDto(0L, 0L, true, true, 0L, 10L); + final var 응답 = 사용자_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), 최신순, FIRST_PAGE); // then - final var expectedRecipes = Collections.emptyList(); - - STATUS_CODE를_검증한다(response, 정상_처리); - 사용자_꿀조합_조회_결과를_검증한다(response, expectedRecipes, page); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 사용자_꿀조합_조회_결과를_검증한다(응답, Collections.emptyList()); } @Test void 사용자가_작성한_꿀조합에_이미지가_없을때_꿀조합은_이미지없이_조회된다() { // given - final var member1 = 멤버_멤버1_생성(); - 단일_멤버_저장(member1); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); - final var recipe1_1 = new Recipe("test-title", "test-content", member1); - 단일_꿀조합_저장(recipe1_1); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), null, 레시피추가요청_생성(상품)); - final var product_recipe_2_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_1); - final var product_recipe_2_1_2 = 레시피_안에_들어가는_상품_생성(product2, recipe1_1); - final var product_recipe_2_1_3 = 레시피_안에_들어가는_상품_생성(product3, recipe1_1); - 복수_꿀조합_상품_저장(product_recipe_2_1_1, product_recipe_2_1_2, product_recipe_2_1_3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(1L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 사용자_꿀조합_조회_요청(loginCookie, "createdAt,desc", 0); - final var page = new PageDto(1L, 1L, true, true, 0L, 10L); + final var 응답 = 사용자_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), 최신순, FIRST_PAGE); // then - final var expectedRecipes = List.of(recipe1_1); - final var expectedRecipeResponses = expectedRecipes.stream() - .map(recipe -> { - final var findRecipeImages = recipeImageRepository.findByRecipe(recipe); - final var productsByRecipe = productRecipeRepository.findProductByRecipe(recipe); - final var memberRecipeProductDtos = productsByRecipe.stream() - .map(MemberRecipeProductDto::toDto) - .collect(Collectors.toList()); - return MemberRecipeDto.toDto(recipe, findRecipeImages, memberRecipeProductDtos); - }) - .collect(Collectors.toList()); - final var actualRecipeImage = response.jsonPath().getList("recipes", MemberRecipeDto.class).get(0) - .getImage(); - - STATUS_CODE를_검증한다(response, 정상_처리); - 사용자_꿀조합_조회_결과를_검증한다(response, expectedRecipeResponses, page); - assertThat(actualRecipeImage).isNull(); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 사용자_꿀조합_조회_결과를_검증한다(응답, List.of(레시피)); + 조회한_꿀조합의_이미지가_없는지_확인한다(응답); } } @@ -438,54 +290,35 @@ class getMemberRecipes_실패_테스트 { @NullAndEmptySource void 로그인하지_않은_사용자가_작성한_꿀조합을_조회할때_예외가_발생한다(final String cookie) { // given & when - final var response = 사용자_꿀조합_조회_요청(cookie, "createdAt,desc", 0); + final var 응답 = 사용자_꿀조합_조회_요청(cookie, 최신순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 인증되지_않음); - 비로그인_사용자는_승인되지_않음을_검증하다(response); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } } - private void 사용자_리뷰_조회_결과를_검증한다(final ExtractableResponse response, final List reviews, - final PageDto page) { - 페이지를_검증한다(response, page); - 사용자_리뷰_목록을_검증한다(response, reviews); - } - - private void 페이지를_검증한다(final ExtractableResponse response, final PageDto expected) { - final var actual = response.jsonPath().getObject("page", PageDto.class); - - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - - private void 사용자_리뷰_목록을_검증한다(final ExtractableResponse response, final List expectedReviews) { + private void 사용자_리뷰_조회_결과를_검증한다(final ExtractableResponse response, final int expectedReviewSize) { final var actual = response.jsonPath().getList("reviews", MemberReviewDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expectedReviews); + assertThat(actual.size()).isEqualTo(expectedReviewSize); } - private void 사용자_꿀조합_조회_결과를_검증한다(final ExtractableResponse response, final List recipes, - final PageDto page) { - 페이지를_검증한다(response, page); - 사용자_꿀조합_목록을_검증한다(response, recipes); - } + private void 사용자_꿀조합_조회_결과를_검증한다(final ExtractableResponse response, final List recipeIds) { + final var actual = response.jsonPath() + .getList("recipes", MemberRecipeDto.class); - private void 사용자_꿀조합_목록을_검증한다(final ExtractableResponse response, final List expected) { - - final var actual = response.jsonPath().getList("recipes", MemberRecipeDto.class); - - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(MemberRecipeDto::getId) + .containsExactlyElementsOf(recipeIds); } private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, final String expectedMessage) { - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) + assertSoftly(soft -> { + soft.assertThat(response.jsonPath().getString("code")) .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) + soft.assertThat(response.jsonPath().getString("message")) .isEqualTo(expectedMessage); }); } @@ -498,26 +331,18 @@ class getMemberRecipes_실패_테스트 { final var actualNickname = response.jsonPath().getString("nickname"); final var actualProfileImage = response.jsonPath().getString("profileImage"); - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualNickname) + assertSoftly(soft -> { + soft.assertThat(actualNickname) .isEqualTo(expectedNickname); - softAssertions.assertThat(actualProfileImage) + soft.assertThat(actualProfileImage) .isEqualTo(expectedProfileImage); }); } - private void 비로그인_사용자는_승인되지_않음을_검증하다(final ExtractableResponse response) { - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - final var actualCode = response.jsonPath().getString("code"); - final var actualMessage = response.jsonPath().getString("message"); + private void 조회한_꿀조합의_이미지가_없는지_확인한다(final ExtractableResponse response) { + final var actual = response.jsonPath() + .getString("image"); - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualCode) - .isEqualTo(expectedCode); - softAssertions.assertThat(actualMessage) - .isEqualTo(expectedMessage); - }); + assertThat(actual).isNull(); } } diff --git a/backend/src/test/java/com/funeat/acceptance/member/MemberSteps.java b/backend/src/test/java/com/funeat/acceptance/member/MemberSteps.java index 69d454ef1..32ad97500 100644 --- a/backend/src/test/java/com/funeat/acceptance/member/MemberSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/member/MemberSteps.java @@ -40,7 +40,7 @@ public class MemberSteps { } public static ExtractableResponse 사용자_리뷰_조회_요청(final String loginCookie, final String sort, - final Integer page) { + final Long page) { return given() .when() .cookie("FUNEAT", loginCookie) @@ -52,7 +52,7 @@ public class MemberSteps { } public static ExtractableResponse 사용자_꿀조합_조회_요청(final String loginCookie, final String sort, - final Integer page) { + final Long page) { return given() .when() .cookie("FUNEAT", loginCookie) diff --git a/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java index 3c95eae80..3ee19b4f9 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java @@ -5,19 +5,20 @@ import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.product.CategorySteps.카테고리_목록_조회_요청; import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; +import static com.funeat.fixture.CategoryFixture.음식; import static com.funeat.fixture.CategoryFixture.카테고리_CU_생성; import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; import static com.funeat.fixture.CategoryFixture.카테고리_과자류_생성; import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.acceptance.common.AcceptanceTest; -import com.funeat.product.domain.Category; import com.funeat.product.dto.CategoryResponse; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.util.List; -import java.util.stream.Collectors; +import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -34,18 +35,17 @@ class getAllCategoriesByType_성공_테스트 { @Test void 공통_상품_카테고리의_목록을_조회한다() { // given - final var 간편식사 = 카테고리_간편식사_생성(); - final var 즉석조리 = 카테고리_즉석조리_생성(); - final var 과자류 = 카테고리_과자류_생성(); - final var CU = 카테고리_CU_생성(); - 복수_카테고리_저장(간편식사, 즉석조리, 과자류, CU); + final var 간편식사 = 단일_카테고리_저장(카테고리_간편식사_생성()); + final var 즉석조리 = 단일_카테고리_저장(카테고리_즉석조리_생성()); + final var 과자류 = 단일_카테고리_저장(카테고리_과자류_생성()); + final var CU = 단일_카테고리_저장(카테고리_CU_생성()); // when - final var response = 카테고리_목록_조회_요청("food"); + final var 응답 = 카테고리_목록_조회_요청(음식); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 공통_상품_카테고리_목록_조회_결과를_검증한다(response, List.of(간편식사, 즉석조리, 과자류)); + STATUS_CODE를_검증한다(응답, 정상_처리); + 공통_상품_카테고리_목록_조회_결과를_검증한다(응답, List.of(간편식사, 즉석조리, 과자류), List.of(CU)); } } @@ -57,25 +57,32 @@ class getAllCategoriesByType_실패_테스트 { @ValueSource(strings = {"a", "foo"}) void 존재하지_않는_카테고리의_목록을_조회할때_예외가_발생한다(final String type) { // given & when - final var response = 카테고리_목록_조회_요청(type); + final var 응답 = 카테고리_목록_조회_요청(type); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - assertThat(response.jsonPath().getString("code")).isEqualTo(expectedCode); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + REQUEST_VALID_ERROR_CODE.getMessage()); } } private void 공통_상품_카테고리_목록_조회_결과를_검증한다(final ExtractableResponse response, - final List categories) { - final var expected = categories.stream() - .map(CategoryResponse::toResponse) - .collect(Collectors.toList()); + final List includeCategoryIds, final List excludeCategoryIds) { final var actual = response.jsonPath() .getList("", CategoryResponse.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(CategoryResponse::getId) + .containsExactlyElementsOf(includeCategoryIds) + .doesNotContainAnyElementsOf(excludeCategoryIds); + } + + private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, + final String expectedMessage) { + assertSoftly(soft -> { + soft.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + soft.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); } } diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java index 4a3b2943c..f6469f384 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java @@ -1,50 +1,88 @@ package com.funeat.acceptance.product; -import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; import static com.funeat.acceptance.common.CommonSteps.사진_명세_요청; +import static com.funeat.acceptance.common.CommonSteps.여러개_사진_명세_요청; import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; +import static com.funeat.acceptance.common.CommonSteps.페이지를_검증한다; import static com.funeat.acceptance.product.ProductSteps.상품_검색_결과_조회_요청; import static com.funeat.acceptance.product.ProductSteps.상품_랭킹_조회_요청; import static com.funeat.acceptance.product.ProductSteps.상품_레시피_목록_요청; import static com.funeat.acceptance.product.ProductSteps.상품_상세_조회_요청; import static com.funeat.acceptance.product.ProductSteps.상품_자동_완성_검색_요청; import static com.funeat.acceptance.product.ProductSteps.카테고리별_상품_목록_조회_요청; -import static com.funeat.acceptance.review.ReviewSteps.단일_리뷰_요청; +import static com.funeat.acceptance.recipe.RecipeSteps.레시피_작성_요청; +import static com.funeat.acceptance.recipe.RecipeSteps.여러명이_레시피_좋아요_요청; +import static com.funeat.acceptance.review.ReviewSteps.리뷰_작성_요청; +import static com.funeat.fixture.CategoryFixture.존재하지_않는_카테고리; import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; -import static com.funeat.fixture.ProductFixture.레시피_안에_들어가는_상품_생성; +import static com.funeat.fixture.ImageFixture.이미지1; +import static com.funeat.fixture.ImageFixture.이미지2; +import static com.funeat.fixture.ImageFixture.이미지3; +import static com.funeat.fixture.ImageFixture.이미지4; +import static com.funeat.fixture.ImageFixture.이미지5; +import static com.funeat.fixture.ImageFixture.이미지6; +import static com.funeat.fixture.ImageFixture.이미지7; +import static com.funeat.fixture.MemberFixture.멤버1; +import static com.funeat.fixture.MemberFixture.멤버2; +import static com.funeat.fixture.MemberFixture.멤버3; +import static com.funeat.fixture.PageFixture.FIRST_PAGE; +import static com.funeat.fixture.PageFixture.PAGE_SIZE; +import static com.funeat.fixture.PageFixture.SECOND_PAGE; +import static com.funeat.fixture.PageFixture.가격_내림차순; +import static com.funeat.fixture.PageFixture.가격_오름차순; +import static com.funeat.fixture.PageFixture.과거순; +import static com.funeat.fixture.PageFixture.리뷰수_내림차순; +import static com.funeat.fixture.PageFixture.마지막페이지O; +import static com.funeat.fixture.PageFixture.마지막페이지X; +import static com.funeat.fixture.PageFixture.응답_페이지_생성; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.첫페이지O; +import static com.funeat.fixture.PageFixture.첫페이지X; +import static com.funeat.fixture.PageFixture.총_데이터_개수; +import static com.funeat.fixture.PageFixture.총_페이지; +import static com.funeat.fixture.PageFixture.최신순; +import static com.funeat.fixture.PageFixture.평균_평점_내림차순; +import static com.funeat.fixture.PageFixture.평균_평점_오름차순; +import static com.funeat.fixture.ProductFixture.상품1; +import static com.funeat.fixture.ProductFixture.상품10; +import static com.funeat.fixture.ProductFixture.상품11; +import static com.funeat.fixture.ProductFixture.상품2; +import static com.funeat.fixture.ProductFixture.상품3; +import static com.funeat.fixture.ProductFixture.상품4; +import static com.funeat.fixture.ProductFixture.상품5; +import static com.funeat.fixture.ProductFixture.상품6; +import static com.funeat.fixture.ProductFixture.상품7; +import static com.funeat.fixture.ProductFixture.상품8; +import static com.funeat.fixture.ProductFixture.상품9; import static com.funeat.fixture.ProductFixture.상품_망고빙수_가격5000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점1점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점5점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점4점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점5점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점1점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점3점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점4점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격4000원_평점2점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점5점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격4000원_평점4점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격5000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격5000원_평점3점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격5000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_애플망고_가격3000원_평점5점_생성; -import static com.funeat.fixture.RecipeFixture.레시피_생성; -import static com.funeat.fixture.RecipeFixture.레시피이미지_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test1_평점1점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test2_평점2점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test3_평점3점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test4_평점4점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test4_평점4점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test5_평점5점_재구매X_생성; +import static com.funeat.fixture.ProductFixture.존재하지_않는_상품; +import static com.funeat.fixture.RecipeFixture.레시피1; +import static com.funeat.fixture.RecipeFixture.레시피2; +import static com.funeat.fixture.RecipeFixture.레시피3; +import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; +import static com.funeat.fixture.RecipeFixture.좋아요O; +import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매X_생성; -import static com.funeat.fixture.TagFixture.태그_간식_ETC_생성; +import static com.funeat.fixture.ScoreFixture.점수_1점; +import static com.funeat.fixture.ScoreFixture.점수_2점; +import static com.funeat.fixture.ScoreFixture.점수_3점; +import static com.funeat.fixture.ScoreFixture.점수_4점; +import static com.funeat.fixture.ScoreFixture.점수_5점; import static com.funeat.fixture.TagFixture.태그_단짠단짠_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static com.funeat.product.exception.CategoryErrorCode.CATEGORY_NOT_FOUND; @@ -53,30 +91,24 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.acceptance.common.AcceptanceTest; -import com.funeat.common.dto.PageDto; -import com.funeat.product.domain.Product; +import com.funeat.product.domain.Category; import com.funeat.product.dto.ProductInCategoryDto; import com.funeat.product.dto.ProductResponse; import com.funeat.product.dto.RankingProductDto; import com.funeat.product.dto.SearchProductDto; import com.funeat.product.dto.SearchProductResultDto; import com.funeat.recipe.dto.RecipeDto; -import com.funeat.tag.domain.Tag; +import com.funeat.tag.dto.TagDto; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @SuppressWarnings("NonAsciiCharacters") class ProductAcceptanceTest extends AcceptanceTest { - private static final Long PAGE_SIZE = 10L; - private static final Long FIRST_PAGE = 0L; - @Nested class getAllProductsInCategory_성공_테스트 { @@ -86,69 +118,41 @@ class 가격_기준_내림차순으로_카테고리별_상품_목록_조회 { @Test void 상품_가격이_서로_다르면_가격_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격4000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격5000원_평점4점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product7 = 상품_삼각김밥_가격4000원_평점2점_생성(category); - final var product8 = 상품_삼각김밥_가격5000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격3000원_평점3점_생성(category); - final var product10 = 상품_삼각김밥_가격3000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product8, product5, product7, product4, product10, product9, - product3, product2, product11, product6); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격3000원_평점5점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격2000원_평점3점_생성(카테고리)); + final var 상품3 = 단일_상품_저장(상품_삼각김밥_가격4000원_평점4점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "price", "desc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(1L, 가격_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(상품3, 상품1, 상품2)); } @Test void 상품_가격이_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product7 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product8 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var product10 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product11, product10, product9, product8, product7, product6, - product5, product4, product3, product2); + final var 카테고리 = 카테고리_간편식사_생성(); + final var 카테고리_아이디 = 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 상품3 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "price", "desc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(카테고리_아이디, 가격_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(상품3, 상품2, 상품1)); } } @@ -158,69 +162,41 @@ class 가격_기준_오름차순으로_카테고리별_상품_목록_조회 { @Test void 상품_가격이_서로_다르면_가격_기준_오름차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격4000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격5000원_평점4점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product7 = 상품_삼각김밥_가격4000원_평점2점_생성(category); - final var product8 = 상품_삼각김밥_가격5000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격3000원_평점3점_생성(category); - final var product10 = 상품_삼각김밥_가격3000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product11, product6, product1, product3, product2, product10, - product9, product7, product4, product8); + final var 카테고리 = 카테고리_간편식사_생성(); + final var 카테고리_아이디 = 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격4000원_평점4점_생성(카테고리)); + final var 상품3 = 단일_상품_저장(상품_삼각김밥_가격2000원_평점3점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "price", "asc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(카테고리_아이디, 가격_오름차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(상품1, 상품3, 상품2)); } @Test void 상품_가격이_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product7 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product8 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var product10 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product11, product10, product9, product8, product7, product6, - product5, product4, product3, product2); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(3L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "price", "asc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(1L, 가격_오름차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(3L, 2L, 1L)); } } @@ -230,69 +206,41 @@ class 평점_기준_내림차순으로_카테고리별_상품_목록_조회 { @Test void 상품_평점이_서로_다르면_평점_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격2000원_평점4점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product7 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product8 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격3000원_평점3점_생성(category); - final var product10 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product1, product5, product4, product9, product2, product7, - product6, product11, product10, product8); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점5점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(3L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "averageRating", "desc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(1L, 평균_평점_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(2L, 1L, 3L)); } @Test void 상품_평점이_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product5 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product7 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product8 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격3000원_평점1점_생성(category); - final var product10 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product11, product10, product9, product8, product7, product6, - product5, product4, product3, product2); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(3L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "averageRating", "desc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(1L, 평균_평점_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(3L, 2L, 1L)); } } @@ -302,69 +250,41 @@ class 평점_기준_오름차순으로_카테고리별_상품_목록_조회 { @Test void 상품_평점이_서로_다르면_평점_기준_오름차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격2000원_평점4점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product7 = 상품_삼각김밥_가격1000원_평점2점_생성(category); - final var product8 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격3000원_평점3점_생성(category); - final var product10 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product11, product10, product8, product3, product7, product6, - product9, product2, product5, product4); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점3점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(3L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "averageRating", "asc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(1L, 평균_평점_오름차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(1L, 3L, 2L)); } @Test void 상품_평점이_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product5 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product6 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product7 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product8 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product9 = 상품_삼각김밥_가격3000원_평점1점_생성(category); - final var product10 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - final var product11 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product11, product10, product9, product8, product7, product6, - product5, product4, product3, product2); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(3L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "averageRating", "asc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(1L, 평균_평점_오름차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(3L, 2L, 1L)); } } @@ -374,74 +294,46 @@ class 리뷰수_기준_내림차순으로_카테고리별_상품_목록_조회 { @Test void 리뷰수가_서로_다르면_리뷰수_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); + final var 카테고리 = 카테고리_간편식사_생성(); + final var 카테고리_아이디 = 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격2000원_평점3점_생성(카테고리)); + final var 상품3 = 단일_상품_저장(상품_삼각김밥_가격2000원_평점1점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품1, 사진_명세_요청(이미지1), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품2, 사진_명세_요청(이미지2), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품2, 사진_명세_요청(이미지3), 리뷰추가요청_재구매O_생성(점수_2점, List.of(태그))); - final var review1_1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product1, 0L); - final var review1_2 = 리뷰_이미지test3_평점3점_재구매O_생성(member2, product1, 0L); - final var review1_3 = 리뷰_이미지test4_평점4점_재구매O_생성(member3, product1, 0L); - final var review2_1 = 리뷰_이미지test1_평점1점_재구매X_생성(member1, product2, 0L); - final var review2_2 = 리뷰_이미지test1_평점1점_재구매X_생성(member2, product2, 0L); - final var review3_1 = 리뷰_이미지test2_평점2점_재구매X_생성(member1, product3, 0L); - final var review3_2 = 리뷰_이미지test2_평점2점_재구매X_생성(member2, product3, 0L); - final var review3_3 = 리뷰_이미지test2_평점2점_재구매X_생성(member3, product3, 0L); - 복수_리뷰_저장(review1_1, review1_2, review1_3, review2_1, review2_2, review3_1, review3_2, review3_3); - - final var pageDto = new PageDto(3L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product3, product1, product2); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "reviewCount", "desc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(카테고리_아이디, 리뷰수_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(상품2, 상품1, 상품3)); } @Test void 리뷰수가_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - final var categoryId = 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격5000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격3000원_평점1점_생성(category); - final var product4 = 상품_삼각김밥_가격2000원_평점4점_생성(category); - final var product5 = 상품_삼각김밥_가격3000원_평점4점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5); + final var 카테고리 = 카테고리_간편식사_생성(); + final var 카테고리_아이디 = 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격5000원_평점3점_생성(카테고리)); + final var 상품3 = 단일_상품_저장(상품_삼각김밥_가격3000원_평점1점_생성(카테고리)); - final var member1 = 멤버_멤버1_생성(); - 단일_멤버_저장(member1); - - final var review1_1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product1, 0L); - final var review2_1 = 리뷰_이미지test1_평점1점_재구매X_생성(member1, product2, 0L); - final var review3_1 = 리뷰_이미지test2_평점2점_재구매X_생성(member1, product3, 0L); - 복수_리뷰_저장(review1_1, review2_1, review3_1); - - final var pageDto = new PageDto(5L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); - - final var expectedProducts = List.of(product3, product2, product1, product5, product4); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 카테고리별_상품_목록_조회_요청(categoryId, "reviewCount", "desc", 0); + final var 응답 = 카테고리별_상품_목록_조회_요청(카테고리_아이디, 리뷰수_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 카테고리별_상품_목록_조회_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 카테고리별_상품_목록_조회_결과를_검증한다(응답, List.of(상품3, 상품2, 상품1)); } } } @@ -451,66 +343,37 @@ class getAllProductsInCategory_실패_테스트 { @Test void 상품을_정렬할때_카테고리가_존재하지_않으면_예외가_발생한다() { - // given - final var notExistCategoryId = 99999L; - - // when - final var response = 카테고리별_상품_목록_조회_요청(notExistCategoryId, "price", "desc", 0); + // given && when + final var 응답 = 카테고리별_상품_목록_조회_요청(존재하지_않는_카테고리, 가격_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, CATEGORY_NOT_FOUND.getCode(), CATEGORY_NOT_FOUND.getMessage()); + STATUS_CODE를_검증한다(응답, 찾을수_없음); + ERROR_CODE와_MESSAGE를_검증한다(응답, CATEGORY_NOT_FOUND.getCode(), CATEGORY_NOT_FOUND.getMessage()); } } - private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, - final String expectedMessage) { - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) - .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) - .isEqualTo(expectedMessage); - }); - } - @Nested class getProductDetail_성공_테스트 { @Test void 상품_상세_정보를_조회한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_단짠단짠_TASTE_생성(); - final var tag3 = 태그_간식_ETC_생성(); - 복수_태그_저장(tag1, tag2, tag3); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그1 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + final var 태그2 = 단일_태그_저장(태그_단짠단짠_TASTE_생성()); - final var image = 사진_명세_요청(); - - final var request1 = 리뷰추가요청_재구매X_생성(4L, 태그_아이디_변환(tag1, tag2, tag3)); - final var request2 = 리뷰추가요청_재구매X_생성(4L, 태그_아이디_변환(tag2, tag3)); - final var request3 = 리뷰추가요청_재구매X_생성(3L, 태그_아이디_변환(tag2)); - - final var loginCookie = 로그인_쿠키를_얻는다(); - - 단일_리뷰_요청(productId, image, request1, loginCookie); - 단일_리뷰_요청(productId, image, request2, loginCookie); - 단일_리뷰_요청(productId, image, request3, loginCookie); - - final var expectedReviewCount = 3L; - final var expectedTags = List.of(tag2, tag3, tag1); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매X_생성(점수_4점, List.of(태그1, 태그2))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매X_생성(점수_4점, List.of(태그2))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_1점, List.of(태그2))); // when - final var response = 상품_상세_조회_요청(productId); + final var 응답 = 상품_상세_조회_요청(상품); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 상품_상세_정보_조회_결과를_검증한다(response, product, expectedReviewCount, expectedTags); + STATUS_CODE를_검증한다(응답, 정상_처리); + 상품_상세_정보_조회_결과를_검증한다(응답); } } @@ -519,15 +382,12 @@ class getProductDetail_실패_테스트 { @Test void 존재하지_않는_상품_상세_정보를_조회할때_예외가_발생한다() { - // given - final var notExistProductId = 99999L; - - // when - final var response = 상품_상세_조회_요청(notExistProductId); + // given && when + final var 응답 = 상품_상세_조회_요청(존재하지_않는_상품); // then - STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOT_FOUND.getCode(), PRODUCT_NOT_FOUND.getMessage()); + STATUS_CODE를_검증한다(응답, 찾을수_없음); + ERROR_CODE와_MESSAGE를_검증한다(응답, PRODUCT_NOT_FOUND.getCode(), PRODUCT_NOT_FOUND.getMessage()); } } @@ -537,37 +397,28 @@ class getRankingProducts_성공_테스트 { @Test void 전체_상품들_중에서_랭킹_TOP3를_조회할_수_있다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product2 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product3 = 상품_삼각김밥_가격1000원_평점4점_생성(category); - final var product4 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3, product4); - - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var review1_1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product1, 0L); - final var review1_2 = 리뷰_이미지test3_평점3점_재구매O_생성(member2, product1, 0L); - final var review1_3 = 리뷰_이미지test4_평점4점_재구매O_생성(member3, product1, 0L); - final var review2_1 = 리뷰_이미지test4_평점4점_재구매X_생성(member1, product2, 0L); - final var review2_2 = 리뷰_이미지test4_평점4점_재구매X_생성(member2, product2, 0L); - final var review3_1 = 리뷰_이미지test2_평점2점_재구매X_생성(member1, product3, 0L); - final var review3_2 = 리뷰_이미지test5_평점5점_재구매X_생성(member2, product3, 0L); - 복수_리뷰_저장(review1_1, review1_2, review1_3, review2_1, review2_2, review3_1, review3_2); - - final var expectedProduct = List.of(product2, product1, product3); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점4점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + final var 상품3 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점4점_생성(카테고리)); + final var 상품4 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품1, 사진_명세_요청(이미지1), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품1, 사진_명세_요청(이미지2), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품1, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품2, 사진_명세_요청(이미지4), 리뷰추가요청_재구매X_생성(점수_5점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품2, 사진_명세_요청(이미지5), 리뷰추가요청_재구매X_생성(점수_5점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품3, 사진_명세_요청(이미지6), 리뷰추가요청_재구매X_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품3, 사진_명세_요청(이미지7), 리뷰추가요청_재구매X_생성(점수_5점, List.of(태그))); // when - final var response = 상품_랭킹_조회_요청(); + final var 응답 = 상품_랭킹_조회_요청(); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 상품_랭킹_조회_결과를_검증한다(response, expectedProduct); + STATUS_CODE를_검증한다(응답, 정상_처리); + 상품_랭킹_조회_결과를_검증한다(응답, List.of(상품2, 상품3, 상품1)); } } @@ -577,106 +428,83 @@ class searchProducts_성공_테스트 { @Test void 검색어가_포함된_상품들을_검색한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - 복수_상품_저장(product1, product2); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_애플망고_가격3000원_평점5점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); - final var pageDto = new PageDto(2L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); - final var expectedProducts = List.of(product2, product1); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(2L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_자동_완성_검색_요청("망고", 0); + final var 응답 = 상품_자동_완성_검색_요청("망고", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 상품_자동_완성_검색_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 상품_자동_완성_검색_결과를_검증한다(응답, List.of(상품2, 상품1)); } @Test void 검색어가_포함된_상품이_없으면_빈_리스트를_반환한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - 복수_상품_저장(product1, product2); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 반복_애플망고_상품_저장(2, 카테고리); - final var pageDto = new PageDto(0L, 0L, true, true, FIRST_PAGE, PAGE_SIZE); - final var expectedProducts = Collections.emptyList(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(0L), 총_페이지(0L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_자동_완성_검색_요청("김밥", 0); + final var 응답 = 상품_자동_완성_검색_요청("김밥", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 상품_자동_완성_검색_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 상품_자동_완성_검색_결과를_검증한다(응답, Collections.emptyList()); } @Test void 페이지가_넘어가도_중복없이_결과를_조회한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product2 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product4 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product5 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product6 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product7 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product8 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product9 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product10 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product11 = 상품_애플망고_가격3000원_평점5점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + 반복_애플망고_상품_저장(10, 카테고리); + + final var 예상_응답_페이지1 = 응답_페이지_생성(총_데이터_개수(11L), 총_페이지(2L), 첫페이지O, 마지막페이지X, FIRST_PAGE, PAGE_SIZE); + final var 예상_응답_페이지2 = 응답_페이지_생성(총_데이터_개수(11L), 총_페이지(2L), 첫페이지X, 마지막페이지O, SECOND_PAGE, PAGE_SIZE); // when - final var response1 = 상품_자동_완성_검색_요청("망고", 0); - final var response2 = 상품_자동_완성_검색_요청("망고", 1); + final var 응답1 = 상품_자동_완성_검색_요청("망고", FIRST_PAGE); + final var 응답2 = 상품_자동_완성_검색_요청("망고", SECOND_PAGE); // then - 결과값이_이전_요청_결과값에_중복되는지_검증(response1, response2); + STATUS_CODE를_검증한다(응답1, 정상_처리); + 페이지를_검증한다(응답1, 예상_응답_페이지1); + + STATUS_CODE를_검증한다(응답2, 정상_처리); + 페이지를_검증한다(응답2, 예상_응답_페이지2); + + 결과값이_이전_요청_결과값에_중복되는지_검증(응답1, 응답2); } @Test void 페이지가_넘어가도_시작되는_단어_우선_조회한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product2 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product4 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product5 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product6 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product7 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product8 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product9 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product10 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product11 = 상품_망고빙수_가격5000원_평점4점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, 0L, PAGE_SIZE); - final var expectedProducts = List.of(product11, product1, product10, product9, product8, product7, product6, - product5, product4, product3); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + 반복_애플망고_상품_저장(9, 카테고리); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(11L), 총_페이지(2L), 첫페이지O, 마지막페이지X, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_자동_완성_검색_요청("망고", 0); + final var 응답 = 상품_자동_완성_검색_요청("망고", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 상품_자동_완성_검색_결과를_검증한다(response, expectedProducts); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 상품_자동_완성_검색_결과를_검증한다(응답, List.of(상품11, 상품1, 상품10, 상품9, 상품8, 상품7, 상품6, 상품5, 상품4, 상품3)); } } @@ -686,369 +514,240 @@ class getSearchResults_성공_테스트 { @Test void 상품_검색_결과들을_조회한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - 복수_상품_저장(product1, product2); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_간식_ETC_생성(); - 복수_태그_저장(tag1, tag2); - - final var image = 사진_명세_요청(); - - final var request1 = 리뷰추가요청_재구매X_생성(5L, 태그_아이디_변환(tag1, tag2)); - final var request2 = 리뷰추가요청_재구매X_생성(5L, 태그_아이디_변환(tag1)); - final var request3 = 리뷰추가요청_재구매X_생성(4L, 태그_아이디_변환(tag2)); - - final var loginCookie = 로그인_쿠키를_얻는다(); - - 단일_리뷰_요청(product1.getId(), image, request1, loginCookie); - 단일_리뷰_요청(product1.getId(), image, request2, loginCookie); - 단일_리뷰_요청(product2.getId(), image, request3, loginCookie); - - final var pageDto = new PageDto(2L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_애플망고_가격3000원_평점5점_생성(카테고리)); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var expectedDto1 = SearchProductResultDto.toDto(product1, 2L); - final var expectedDto2 = SearchProductResultDto.toDto(product2, 1L); - final var expected = List.of(expectedDto2, expectedDto1); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(2L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_검색_결과_조회_요청("망고", 0); + final var response = 상품_검색_결과_조회_요청("망고", FIRST_PAGE); // then STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 상품_검색_결과를_검증한다(response, expected); + 페이지를_검증한다(response, 예상_응답_페이지); + 상품_검색_결과를_검증한다(response, List.of(상품2, 상품1)); } @Test void 검색_결과에_상품이_없으면_빈_리스트를_반환한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_애플망고_가격3000원_평점5점_생성(카테고리)); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); - final var product1 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - 복수_상품_저장(product1, product2); - - final var pageDto = new PageDto(0L, 0L, true, true, FIRST_PAGE, PAGE_SIZE); - final var expected = Collections.emptyList(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(0L), 총_페이지(0L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_검색_결과_조회_요청("김밥", 0); + final var 응답 = 상품_검색_결과_조회_요청("김밥", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 상품_검색_결과를_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 상품_검색_결과를_검증한다(응답, Collections.emptyList()); } @Test void 페이지가_넘어가도_중복없이_상품_결과를_조회한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product2 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product4 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product5 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product6 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product7 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product8 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product9 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product10 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product11 = 상품_애플망고_가격3000원_평점5점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + 반복_애플망고_상품_저장(10, 카테고리); + + final var 예상_응답_페이지1 = 응답_페이지_생성(총_데이터_개수(11L), 총_페이지(2L), 첫페이지O, 마지막페이지X, FIRST_PAGE, PAGE_SIZE); + final var 예상_응답_페이지2 = 응답_페이지_생성(총_데이터_개수(11L), 총_페이지(2L), 첫페이지X, 마지막페이지O, SECOND_PAGE, PAGE_SIZE); // when - final var response1 = 상품_검색_결과_조회_요청("망고", 0); - final var response2 = 상품_검색_결과_조회_요청("망고", 1); + final var 응답1 = 상품_검색_결과_조회_요청("망고", FIRST_PAGE); + final var 응답2 = 상품_검색_결과_조회_요청("망고", SECOND_PAGE); // then - 결과값이_이전_요청_결과값에_중복되는지_검증(response1, response2); + STATUS_CODE를_검증한다(응답1, 정상_처리); + 페이지를_검증한다(응답1, 예상_응답_페이지1); + + STATUS_CODE를_검증한다(응답2, 정상_처리); + 페이지를_검증한다(응답2, 예상_응답_페이지2); + + 결과값이_이전_요청_결과값에_중복되는지_검증(응답1, 응답2); } @Test void 페이지가_넘어가도_시작되는_단어_우선_조회한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product2 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product4 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product5 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product6 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product7 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product8 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product9 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product10 = 상품_애플망고_가격3000원_평점5점_생성(category); - final var product11 = 상품_망고빙수_가격5000원_평점4점_생성(category); - 복수_상품_저장(product1, product2, product3, product4, product5, product6, product7, product8, product9, - product10, product11); - - final var pageDto = new PageDto(11L, 2L, true, false, 0L, PAGE_SIZE); - final var expectedDto1 = SearchProductResultDto.toDto(product11, 0L); - final var expectedDto2 = SearchProductResultDto.toDto(product1, 0L); - final var expectedDto3 = SearchProductResultDto.toDto(product10, 0L); - final var expectedDto4 = SearchProductResultDto.toDto(product9, 0L); - final var expectedDto5 = SearchProductResultDto.toDto(product8, 0L); - final var expectedDto6 = SearchProductResultDto.toDto(product7, 0L); - final var expectedDto7 = SearchProductResultDto.toDto(product6, 0L); - final var expectedDto8 = SearchProductResultDto.toDto(product5, 0L); - final var expectedDto9 = SearchProductResultDto.toDto(product4, 0L); - final var expectedDto10 = SearchProductResultDto.toDto(product3, 0L); - final var expected = List.of(expectedDto1, expectedDto2, expectedDto3, expectedDto4, expectedDto5, - expectedDto6, expectedDto7, expectedDto8, expectedDto9, expectedDto10); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + 반복_애플망고_상품_저장(9, 카테고리); + 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(11L), 총_페이지(2L), 첫페이지O, 마지막페이지X, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_검색_결과_조회_요청("망고", 0); + final var response = 상품_검색_결과_조회_요청("망고", FIRST_PAGE); // then STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 상품_검색_결과를_검증한다(response, expected); + 페이지를_검증한다(response, 예상_응답_페이지); + 상품_검색_결과를_검증한다(response, List.of(상품11, 상품1, 상품10, 상품9, 상품8, 상품7, 상품6, 상품5, 상품4, 상품3)); } } - private void 결과값이_이전_요청_결과값에_중복되는지_검증(final ExtractableResponse response1, - final ExtractableResponse response2) { - final var lastResponses = response1.jsonPath() - .getList("products", SearchProductResultDto.class); - final var currentResponse = response2.jsonPath() - .getList("products", SearchProductResultDto.class).get(0); - - assertThat(lastResponses).usingRecursiveFieldByFieldElementComparator() - .doesNotContain(currentResponse); - } - - /** - * AssertJ assertions "allMatch" and "doesNotContains" should also test for emptiness - */ @Nested class getProductRecipes_성공_테스트 { @Test void 해당_상품의_꿀조합_목록을_좋아요가_많은_순으로_조회할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1 = 레시피_생성(member, 1L); - final var recipe2 = 레시피_생성(member, 3L); - final var recipe3 = 레시피_생성(member, 2L); - 복수_꿀조합_저장(recipe1, recipe2, recipe3); - - final var product_recipe_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1); - final var product_recipe_1_2 = 레시피_안에_들어가는_상품_생성(product1, recipe2); - final var product_recipe_2_1 = 레시피_안에_들어가는_상품_생성(product2, recipe1); - final var product_recipe_3_1 = 레시피_안에_들어가는_상품_생성(product3, recipe1); - final var product_recipe_3_2 = 레시피_안에_들어가는_상품_생성(product3, recipe2); - 복수_꿀조합_상품_저장(product_recipe_1_1, product_recipe_2_1, product_recipe_3_1, product_recipe_1_2, - product_recipe_3_2); - - final var recipeImage1_1 = 레시피이미지_생성(recipe1); - final var recipeImage2_1 = 레시피이미지_생성(recipe2); - final var recipeImage2_2 = 레시피이미지_생성(recipe2); - 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage2_1, recipeImage2_2); - - final var pageDto = new PageDto(2L, 1L, true, true, 0L, 10L); - final var sortingRecipes = List.of( - RecipeDto.toDto(recipe2, List.of(recipeImage2_1, recipeImage2_2), List.of(product1, product3)), - RecipeDto.toDto(recipe1, List.of(recipeImage1_1), List.of(product1, product2, product3)) - ); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + 여러명이_레시피_좋아요_요청(List.of(멤버1), 레시피1, 좋아요O); + 여러명이_레시피_좋아요_요청(List.of(멤버2, 멤버3), 레시피2, 좋아요O); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_레시피_목록_요청(product1.getId(), "favoriteCount", "desc", 0); + final var response = 상품_레시피_목록_요청(상품, 좋아요수_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(response, 정상_처리); - 상품_레시피_목록_조회_결과를_검증한다(response, sortingRecipes, pageDto); + 페이지를_검증한다(response, 예상_응답_페이지); + 상품_레시피_목록_조회_결과를_검증한다(response, List.of(레시피2, 레시피1, 레시피3)); } @Test void 해당_상품의_꿀조합_목록을_최신순으로_조회할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1 = 레시피_생성(member, 1L); - final var recipe2 = 레시피_생성(member, 3L); - final var recipe3 = 레시피_생성(member, 2L); - 복수_꿀조합_저장(recipe1, recipe2, recipe3); - - final var product_recipe_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1); - final var product_recipe_1_2 = 레시피_안에_들어가는_상품_생성(product1, recipe2); - final var product_recipe_2_1 = 레시피_안에_들어가는_상품_생성(product2, recipe1); - final var product_recipe_3_1 = 레시피_안에_들어가는_상품_생성(product3, recipe1); - final var product_recipe_3_2 = 레시피_안에_들어가는_상품_생성(product3, recipe2); - 복수_꿀조합_상품_저장(product_recipe_1_1, product_recipe_2_1, product_recipe_3_1, product_recipe_1_2, - product_recipe_3_2); - - final var recipeImage1_1 = 레시피이미지_생성(recipe1); - final var recipeImage2_1 = 레시피이미지_생성(recipe2); - final var recipeImage2_2 = 레시피이미지_생성(recipe2); - 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage2_1, recipeImage2_2); - - final var pageDto = new PageDto(2L, 1L, true, true, 0L, 10L); - final var sortingRecipes = List.of( - RecipeDto.toDto(recipe2, List.of(recipeImage2_1, recipeImage2_2), List.of(product1, product3)), - RecipeDto.toDto(recipe1, List.of(recipeImage1_1), List.of(product1, product2, product3)) - ); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_레시피_목록_요청(product1.getId(), "createdAt", "desc", 0); + final var response = 상품_레시피_목록_요청(상품, 최신순, FIRST_PAGE); // then STATUS_CODE를_검증한다(response, 정상_처리); - 상품_레시피_목록_조회_결과를_검증한다(response, sortingRecipes, pageDto); + 페이지를_검증한다(response, 예상_응답_페이지); + 상품_레시피_목록_조회_결과를_검증한다(response, List.of(레시피3, 레시피2, 레시피1)); } @Test void 해당_상품의_꿀조합_목록을_오래된순으로_조회할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1 = 레시피_생성(member, 1L); - final var recipe2 = 레시피_생성(member, 3L); - final var recipe3 = 레시피_생성(member, 2L); - 복수_꿀조합_저장(recipe1, recipe2, recipe3); - - final var product_recipe_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1); - final var product_recipe_1_2 = 레시피_안에_들어가는_상품_생성(product1, recipe2); - final var product_recipe_2_1 = 레시피_안에_들어가는_상품_생성(product2, recipe1); - final var product_recipe_3_1 = 레시피_안에_들어가는_상품_생성(product3, recipe1); - final var product_recipe_3_2 = 레시피_안에_들어가는_상품_생성(product3, recipe2); - 복수_꿀조합_상품_저장(product_recipe_1_1, product_recipe_2_1, product_recipe_3_1, product_recipe_1_2, - product_recipe_3_2); - - final var recipeImage1_1 = 레시피이미지_생성(recipe1); - final var recipeImage2_1 = 레시피이미지_생성(recipe2); - final var recipeImage2_2 = 레시피이미지_생성(recipe2); - 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage2_1, recipeImage2_2); - - final var pageDto = new PageDto(2L, 1L, true, true, 0L, 10L); - final var sortingRecipes = List.of( - RecipeDto.toDto(recipe1, List.of(recipeImage1_1), List.of(product1, product2, product3)), - RecipeDto.toDto(recipe2, List.of(recipeImage2_1, recipeImage2_2), List.of(product1, product3)) - ); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 상품_레시피_목록_요청(product1.getId(), "createdAt", "asc", 0); + final var 응답 = 상품_레시피_목록_요청(상품, 과거순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 상품_레시피_목록_조회_결과를_검증한다(response, sortingRecipes, pageDto); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 상품_레시피_목록_조회_결과를_검증한다(응답, List.of(레시피1, 레시피2, 레시피3)); } } - private List 태그_아이디_변환(final Tag... tags) { - return Arrays.stream(tags) - .map(Tag::getId) - .collect(Collectors.toList()); - } - - private void 페이지를_검증한다(final ExtractableResponse response, final PageDto expected) { - final var actual = response.jsonPath().getObject("page", PageDto.class); - - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - - private void 카테고리별_상품_목록_조회_결과를_검증한다(final ExtractableResponse response, final List products) { - final var expected = products.stream() - .map(product -> ProductInCategoryDto.toDto(product, 0L)) - .collect(Collectors.toList()); + private void 카테고리별_상품_목록_조회_결과를_검증한다(final ExtractableResponse response, final List productIds) { final var actual = response.jsonPath() .getList("products", ProductInCategoryDto.class); - assertThat(actual).usingRecursiveComparison() - .ignoringFields("reviewCount") - .isEqualTo(expected); + assertThat(actual).extracting(ProductInCategoryDto::getId) + .containsExactlyElementsOf(productIds); } - private void 상품_상세_정보_조회_결과를_검증한다(final ExtractableResponse response, final Product product, - final Long expectedReviewCount, final List expectedTags) { - final var expected = ProductResponse.toResponse(product, expectedReviewCount, expectedTags); - final var actual = response.as(ProductResponse.class); + private void ERROR_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, + final String expectedMessage) { + assertSoftly(soft -> { + soft.assertThat(response.jsonPath().getString("code")) + .isEqualTo(expectedCode); + soft.assertThat(response.jsonPath().getString("message")) + .isEqualTo(expectedMessage); + }); + } - assertThat(actual).usingRecursiveComparison() - .ignoringFields("averageRating") - .isEqualTo(expected); + private void 상품_상세_정보_조회_결과를_검증한다(final ExtractableResponse response) { + final var actual = response.as(ProductResponse.class); + final var actualTags = response.jsonPath() + .getList("tags", TagDto.class); + + assertSoftly(soft -> { + soft.assertThat(actual.getId()).isEqualTo(1L); + soft.assertThat(actual.getName()).isEqualTo("삼각김밥"); + soft.assertThat(actual.getPrice()).isEqualTo(1000L); + soft.assertThat(actual.getImage()).isEqualTo("image.png"); + soft.assertThat(actual.getContent()).isEqualTo("맛있는 삼각김밥"); + soft.assertThat(actual.getAverageRating()).isEqualTo(3.0); + soft.assertThat(actual.getReviewCount()).isEqualTo(3L); + soft.assertThat(actualTags).extracting("id").containsExactly(2L, 1L); + }); } - private void 상품_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List products) { - final var expected = products.stream() - .map(RankingProductDto::toDto) - .collect(Collectors.toList()); + private void 상품_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List productIds) { final var actual = response.jsonPath() .getList("products", RankingProductDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(RankingProductDto::getId) + .isEqualTo(productIds); } - private void 상품_자동_완성_검색_결과를_검증한다(final ExtractableResponse response, final List products) { - final var expected = products.stream() - .map(product -> SearchProductDto.toDto((Product) product)) - .collect(Collectors.toList()); + private void 상품_자동_완성_검색_결과를_검증한다(final ExtractableResponse response, final List productIds) { final var actual = response.jsonPath() .getList("products", SearchProductDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(SearchProductDto::getId) + .isEqualTo(productIds); } - private void 상품_검색_결과를_검증한다(final ExtractableResponse response, final List expected) { - final var actual = response.jsonPath() + private void 결과값이_이전_요청_결과값에_중복되는지_검증(final ExtractableResponse response1, + final ExtractableResponse response2) { + final var lastResponses = response1.jsonPath() .getList("products", SearchProductResultDto.class); + final var currentResponse = response2.jsonPath() + .getList("products", SearchProductResultDto.class).get(0); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(lastResponses).usingRecursiveFieldByFieldElementComparator() + .doesNotContain(currentResponse); } - private void 상품_레시피_목록_조회_결과를_검증한다(final ExtractableResponse response, final List recipes, - final PageDto pageDto) { - 페이지를_검증한다(response, pageDto); - 상품_레시피_목록을_검증한다(response, recipes); + private void 상품_검색_결과를_검증한다(final ExtractableResponse response, final List productIds) { + final var actual = response.jsonPath() + .getList("products", SearchProductResultDto.class); + + assertThat(actual).extracting(SearchProductResultDto::getId) + .containsExactlyElementsOf(productIds); } - private void 상품_레시피_목록을_검증한다(final ExtractableResponse response, final List expected) { + private void 상품_레시피_목록_조회_결과를_검증한다(final ExtractableResponse response, final List recipeIds) { final var actual = response.jsonPath().getList("recipes", RecipeDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(RecipeDto::getId) + .containsExactlyElementsOf(recipeIds); + } + + private void 반복_애플망고_상품_저장(final int repeat, final Category category) { + for (int i = 0; i < repeat; i++) { + 단일_상품_저장(상품_애플망고_가격3000원_평점5점_생성(category)); + } } } diff --git a/backend/src/test/java/com/funeat/acceptance/product/ProductSteps.java b/backend/src/test/java/com/funeat/acceptance/product/ProductSteps.java index 610be9bce..8092bc187 100644 --- a/backend/src/test/java/com/funeat/acceptance/product/ProductSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/product/ProductSteps.java @@ -2,16 +2,17 @@ import static io.restassured.RestAssured.given; + import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; @SuppressWarnings("NonAsciiCharacters") public class ProductSteps { - public static ExtractableResponse 카테고리별_상품_목록_조회_요청(final Long categoryId, final String sortType, - final String sortOrderType, final int page) { + public static ExtractableResponse 카테고리별_상품_목록_조회_요청(final Long categoryId, final String sort, + final Long page) { return given() - .queryParam("sort", sortType + "," + sortOrderType) + .queryParam("sort", sort) .queryParam("page", page) .when() .get("/api/categories/{category_id}/products", categoryId) @@ -35,7 +36,7 @@ public class ProductSteps { .extract(); } - public static ExtractableResponse 상품_자동_완성_검색_요청(final String query, final int page) { + public static ExtractableResponse 상품_자동_완성_검색_요청(final String query, final Long page) { return given() .queryParam("query", query) .queryParam("page", page) @@ -45,7 +46,7 @@ public class ProductSteps { .extract(); } - public static ExtractableResponse 상품_검색_결과_조회_요청(final String query, final int page) { + public static ExtractableResponse 상품_검색_결과_조회_요청(final String query, final Long page) { return given() .queryParam("query", query) .queryParam("page", page) @@ -55,10 +56,10 @@ public class ProductSteps { .extract(); } - public static ExtractableResponse 상품_레시피_목록_요청(final Long productId, final String sortType, - final String sortOrderType, final int page) { + public static ExtractableResponse 상품_레시피_목록_요청(final Long productId, final String sort, + final Long page) { return given() - .queryParam("sort", sortType + "," + sortOrderType) + .queryParam("sort", sort) .queryParam("page", page) .when() .get("/api/products/{productId}/recipes", productId) 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 99dfa78a5..dc39065cb 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeAcceptanceTest.java @@ -1,39 +1,59 @@ package com.funeat.acceptance.recipe; -import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.여러개_사진_명세_요청; import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; import static com.funeat.acceptance.common.CommonSteps.정상_생성; import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.common.CommonSteps.정상_처리_NO_CONTENT; import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; +import static com.funeat.acceptance.common.CommonSteps.페이지를_검증한다; 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.acceptance.recipe.RecipeSteps.레시피_상세_정보_요청; -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.acceptance.recipe.RecipeSteps.레시피_추가_요청하고_id_반환; -import static com.funeat.acceptance.recipe.RecipeSteps.여러_사진_요청; +import static com.funeat.acceptance.recipe.RecipeSteps.여러명이_레시피_좋아요_요청; import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND; import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; -import static com.funeat.fixture.ProductFixture.레시피_안에_들어가는_상품_생성; +import static com.funeat.fixture.ImageFixture.이미지1; +import static com.funeat.fixture.ImageFixture.이미지2; +import static com.funeat.fixture.ImageFixture.이미지3; +import static com.funeat.fixture.ImageFixture.이미지4; +import static com.funeat.fixture.MemberFixture.멤버1; +import static com.funeat.fixture.MemberFixture.멤버2; +import static com.funeat.fixture.MemberFixture.멤버3; +import static com.funeat.fixture.PageFixture.FIRST_PAGE; +import static com.funeat.fixture.PageFixture.PAGE_SIZE; +import static com.funeat.fixture.PageFixture.과거순; +import static com.funeat.fixture.PageFixture.마지막페이지O; +import static com.funeat.fixture.PageFixture.응답_페이지_생성; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.첫페이지O; +import static com.funeat.fixture.PageFixture.총_데이터_개수; +import static com.funeat.fixture.PageFixture.총_페이지; +import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.ProductFixture.상품_망고빙수_가격5000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점5점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; -import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_애플망고_가격3000원_평점5점_생성; -import static com.funeat.fixture.RecipeFixture.레시피_생성; -import static com.funeat.fixture.RecipeFixture.레시피이미지_생성; +import static com.funeat.fixture.RecipeFixture.레시피; +import static com.funeat.fixture.RecipeFixture.레시피1; +import static com.funeat.fixture.RecipeFixture.레시피2; +import static com.funeat.fixture.RecipeFixture.레시피3; +import static com.funeat.fixture.RecipeFixture.레시피4; +import static com.funeat.fixture.RecipeFixture.레시피_본문; +import static com.funeat.fixture.RecipeFixture.레시피_제목; import static com.funeat.fixture.RecipeFixture.레시피좋아요요청_생성; import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; +import static com.funeat.fixture.RecipeFixture.존재하지_않는_레시피; +import static com.funeat.fixture.RecipeFixture.좋아요O; +import static com.funeat.fixture.RecipeFixture.좋아요X; import static com.funeat.recipe.exception.RecipeErrorCode.RECIPE_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -41,8 +61,8 @@ import com.funeat.acceptance.common.AcceptanceTest; import com.funeat.common.dto.PageDto; import com.funeat.member.domain.Member; -import com.funeat.product.domain.Product; import com.funeat.recipe.domain.Recipe; +import com.funeat.recipe.dto.ProductRecipeDto; import com.funeat.recipe.dto.RankingRecipeDto; import com.funeat.recipe.dto.RecipeAuthorDto; import com.funeat.recipe.dto.RecipeCreateRequest; @@ -54,67 +74,44 @@ import java.util.Collections; 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; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.NullSource; @SuppressWarnings("NonAsciiCharacters") public class RecipeAcceptanceTest extends AcceptanceTest { - private static final Long PAGE_SIZE = 10L; - private static final Long FIRST_PAGE = 0L; - @Nested class writeRecipe_성공_테스트 { @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 = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); // when - final var response = 레시피_생성_요청(request, images, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); // then - STATUS_CODE를_검증한다(response, 정상_생성); + STATUS_CODE를_검증한다(응답, 정상_생성); } @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 loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); // when - final var response = 레시피_생성_요청(request, null, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), null, 레시피추가요청_생성(상품)); // then - STATUS_CODE를_검증한다(response, 정상_생성); + STATUS_CODE를_검증한다(응답, 정상_생성); } } @@ -125,159 +122,103 @@ class writeRecipe_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_레시피_작성시_예외가_발생한다(final String cookie) { // 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 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); // when - final var response = 레시피_생성_요청(request, images, cookie); + final var 응답 = 레시피_작성_요청(cookie, 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); // then - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - STATUS_CODE를_검증한다(response, 인증되지_않음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @ParameterizedTest @NullAndEmptySource void 사용자가_레시피_작성할때_레시피이름_미기입시_예외가_발생한다(final String title) { // 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 = new RecipeCreateRequest(title, productIds, "밥 추가, 밥 추가, 밥 추가.. 끝!!"); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var images = 여러_사진_요청(3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 요청 = 레시피추가요청_생성(title, List.of(상품), 레시피_본문); // when - final var response = 레시피_생성_요청(request, images, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "꿀조합 이름을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "꿀조합 이름을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } - @Test - void 사용자가_레시피_작성할때_상품들이_NULL일시_예외가_발생한다() { + @NullSource + @ParameterizedTest + void 사용자가_레시피_작성할때_상품들이_NULL일시_예외가_발생한다(final List productIds) { // given - final var request = new RecipeCreateRequest("title", null, "밥 추가, 밥 추가, 밥 추가.. 끝!!"); - - final var images = 여러_사진_요청(3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 요청 = 레시피추가요청_생성(레시피_제목, productIds, 레시피_본문); // when - final var response = 레시피_생성_요청(request, images, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "상품 ID 목록을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "상품 ID 목록을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 사용자가_레시피_작성할때_상품들이_비어있을시_예외가_발생한다() { // given - final var request = new RecipeCreateRequest("title", Collections.emptyList(), "밥 추가, 밥 추가, 밥 추가.. 끝!!"); - - final var images = 여러_사진_요청(3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 요청 = new RecipeCreateRequest(레시피_제목, Collections.emptyList(), 레시피_본문); // when - final var response = 레시피_생성_요청(request, images, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "적어도 1개의 상품 ID가 필요합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "적어도 1개의 상품 ID가 필요합니다. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @ParameterizedTest @NullAndEmptySource void 사용자가_레시피_작성할때_내용이_비어있을시_예외가_발생한다(final String content) { // 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 = new RecipeCreateRequest("title", productIds, content); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var images = 여러_사진_요청(3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 요청 = 레시피추가요청_생성(레시피_제목, List.of(상품), content); // when - final var response = 레시피_생성_요청(request, images, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "꿀조합 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "꿀조합 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 사용자가_레시피_작성할때_레시피내용이_500자_초과시_예외가_발생한다() { // 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 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var images = 여러_사진_요청(3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 레시피내용_501자 = ".".repeat(500) + "a"; + final var 요청 = 레시피추가요청_생성("title", List.of(상품), 레시피내용_501자); // when - final var maxContent = "tests".repeat(100) + "a"; - final var request = new RecipeCreateRequest("title", productIds, maxContent); - final var response = 레시피_생성_요청(request, images, loginCookie); + final var 응답 = 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "꿀조합 내용은 최대 500자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "꿀조합 내용은 최대 500자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage()); } } @@ -287,35 +228,19 @@ class getRecipeDetail_성공_테스트 { @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); - final var products = List.of(product1, product2, product3); - 복수_상품_저장(product1, product2, product3); - final var productIds = 상품_아이디_변환(product1, product2, product3); - final var totalPrice = 상품_총가격_계산(product1, product2, product3); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격3000원_평점1점_생성(카테고리)); - final var loginCookie = 로그인_쿠키를_얻는다(); - - final var createRequest = 레시피추가요청_생성(productIds); - final var images = 여러_사진_요청(3); - final var recipeId = 레시피_추가_요청하고_id_반환(createRequest, images, loginCookie); - - final var recipe = recipeRepository.findRecipeWithMemberById(recipeId); - final var findImages = recipeImageRepository.findByRecipe(recipe); - - final var expected = RecipeDetailResponse.toResponse(recipe, findImages, products, totalPrice, false); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품1, 상품2)); // when - final var response = 레시피_상세_정보_요청(loginCookie, recipeId); - final var actual = response.as(RecipeDetailResponse.class); + final var 응답 = 레시피_상세_정보_요청(로그인_쿠키_획득(멤버1), 레시피); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 레시피_상세_정보_조회_결과를_검증한다(actual, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 레시피_상세_정보_조회_결과를_검증한다(응답); } } @@ -326,44 +251,29 @@ class getRecipeDetail_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_레시피_상세_조회시_예외가_발생한다(final String cookie) { // 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 loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var createRequest = 레시피추가요청_생성(productIds); - final var images = 여러_사진_요청(3); - final var recipeId = 레시피_추가_요청하고_id_반환(createRequest, images, loginCookie); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); // when - final var response = 레시피_상세_정보_요청(cookie, recipeId); + final var 응답 = 레시피_상세_정보_요청(cookie, 레시피); // then - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - STATUS_CODE를_검증한다(response, 인증되지_않음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @Test void 존재하지_않는_레시피_사용자가_레시피_상세_조회시_예외가_발생한다() { - // given - final var notExistRecipeId = 99999L; - final var loginCookie = 로그인_쿠키를_얻는다(); - - // when - final var response = 레시피_상세_정보_요청(loginCookie, notExistRecipeId); + // given && when + final var 응답 = 레시피_상세_정보_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_레시피); // then - STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, RECIPE_NOT_FOUND.getCode(), RECIPE_NOT_FOUND.getMessage()); + STATUS_CODE를_검증한다(응답, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, RECIPE_NOT_FOUND.getCode(), RECIPE_NOT_FOUND.getMessage()); } } @@ -373,65 +283,34 @@ class likeRecipe_성공_테스트 { @Test void 레시피에_좋아요를_할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - 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 loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var createRequest = 레시피추가요청_생성(productIds); - final var images = 여러_사진_요청(3); - final var recipeId = 레시피_추가_요청하고_id_반환(createRequest, images, loginCookie); - - final var favoriteRequest = 레시피좋아요요청_생성(true); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); // when - final var response = 레시피_좋아요_요청(loginCookie, recipeId, favoriteRequest); + final var 응답 = 레시피_좋아요_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피좋아요요청_생성(좋아요O)); // then - STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT); - 레시피_좋아요_결과를_검증한다(member, recipeId, 1L, true); + STATUS_CODE를_검증한다(응답, 정상_처리_NO_CONTENT); } @Test void 레시피에_좋아요를_취소할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - 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 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var loginCookie = 로그인_쿠키를_얻는다(); - - final var createRequest = 레시피추가요청_생성(productIds); - final var images = 여러_사진_요청(3); - final var recipeId = 레시피_추가_요청하고_id_반환(createRequest, images, loginCookie); - - final var favoriteRequest = 레시피좋아요요청_생성(true); - 레시피_좋아요_요청(loginCookie, recipeId, favoriteRequest); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_좋아요_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피좋아요요청_생성(좋아요O)); // when - final var cancelFavoriteRequest = 레시피좋아요요청_생성(false); - final var response = 레시피_좋아요_요청(loginCookie, recipeId, cancelFavoriteRequest); + final var 응답 = 레시피_좋아요_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피좋아요요청_생성(좋아요X)); // then - STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT); - 레시피_좋아요_결과를_검증한다(member, recipeId, 0L, false); + STATUS_CODE를_검증한다(응답, 정상_처리_NO_CONTENT); } } @@ -442,88 +321,47 @@ class likeRecipe_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_레시피에_좋아요를_할때_예외가_발생한다(final String cookie) { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - 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 loginCookie = 로그인_쿠키를_얻는다(); - - final var createRequest = 레시피추가요청_생성(productIds); - final var images = 여러_사진_요청(3); - final var recipeId = 레시피_추가_요청하고_id_반환(createRequest, images, loginCookie); - - final var favoriteRequest = 레시피좋아요요청_생성(true); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); // when - final var response = 레시피_좋아요_요청(cookie, recipeId, favoriteRequest); + final var 응답 = 레시피_좋아요_요청(cookie, 레시피, 레시피좋아요요청_생성(좋아요O)); // then - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - STATUS_CODE를_검증한다(response, 인증되지_않음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @Test void 사용자가_레시피에_좋아요를_할때_좋아요_미기입시_예외가_발생한다() { // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - 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 loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var createRequest = 레시피추가요청_생성(productIds); - final var images = 여러_사진_요청(3); - final var recipeId = 레시피_추가_요청하고_id_반환(createRequest, images, loginCookie); - - final var favoriteRequest = 레시피좋아요요청_생성(null); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); // when - final var response = 레시피_좋아요_요청(loginCookie, recipeId, favoriteRequest); + final var 응답 = 레시피_좋아요_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피좋아요요청_생성(null)); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "좋아요를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "좋아요를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 존재하지_않는_레시피에_사용자가_좋아요를_할때_예외가_발생한다() { - // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - final var loginCookie = 로그인_쿠키를_얻는다(); - - final var favoriteRequest = 레시피좋아요요청_생성(true); - - // when - final var wrongRecipeId = 999L; - final var response = 레시피_좋아요_요청(loginCookie, wrongRecipeId, favoriteRequest); + // given && when + final var 응답 = 레시피_좋아요_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_레시피, 레시피좋아요요청_생성(좋아요O)); // then - STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, RECIPE_NOT_FOUND.getCode(), RECIPE_NOT_FOUND.getMessage()); + STATUS_CODE를_검증한다(응답, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, RECIPE_NOT_FOUND.getCode(), RECIPE_NOT_FOUND.getMessage()); } } @@ -533,103 +371,65 @@ class getSearchResults_성공_테스트 { @Test void 검색어에_해당하는_상품이_포함된_레시피가_2개면_레시피_2개를_반환한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - 복수_상품_저장(product1, product2, product3); - final var productIds1 = 상품_아이디_변환(product1, product2); - final var productIds2 = 상품_아이디_변환(product1, product3); - - final var loginCookie = 로그인_쿠키를_얻는다(); - - final var createRequest1 = 레시피추가요청_생성(productIds1); - final var createRequest2 = 레시피추가요청_생성(productIds2); - final var images = 여러_사진_요청(3); - final var recipeId1 = 레시피_추가_요청하고_id_반환(createRequest1, images, loginCookie); - final var recipeId2 = 레시피_추가_요청하고_id_반환(createRequest2, images, loginCookie); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); - final var pageDto = new PageDto(2L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품1)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품1, 상품2)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품2)); - final var expectedDto1 = 예상_레시피_검색_결과_변환(loginCookie, recipeId1); - final var expectedDto2 = 예상_레시피_검색_결과_변환(loginCookie, recipeId2); - final var expected = List.of(expectedDto1, expectedDto2); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(2L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 레시피_검색_결과_조회_요청("망고", 0); + final var 응답 = 레시피_검색_결과_조회_요청("망고", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 레시피_검색_결과를_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 레시피_검색_결과를_검증한다(응답, List.of(레시피2, 레시피3)); } @Test void 검색어에_해당하는_상품이_2개고_상품이_포함된_레시피가_1개면_레시피_1개를_반환한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - 복수_상품_저장(product1, product2, product3); - final var productIds1 = 상품_아이디_변환(product1, product2, product3); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_애플망고_가격3000원_평점5점_생성(카테고리)); - final var createRequest1 = 레시피추가요청_생성(productIds1); - final var images = 여러_사진_요청(3); - final var recipeId1 = 레시피_추가_요청하고_id_반환(createRequest1, images, loginCookie); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품1, 상품2)); - final var pageDto = new PageDto(1L, 1L, true, true, FIRST_PAGE, PAGE_SIZE); - - final var expectedDto1 = 예상_레시피_검색_결과_변환(loginCookie, recipeId1); - final var expected = List.of(expectedDto1); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(1L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 레시피_검색_결과_조회_요청("망고", 0); + final var 응답 = 레시피_검색_결과_조회_요청("망고", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 레시피_검색_결과를_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 레시피_검색_결과를_검증한다(응답, List.of(레시피)); } @Test void 검색_결과에_레시피가_없으면_빈_리스트를_반환한다() { // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점1점_생성(category); - final var product2 = 상품_망고빙수_가격5000원_평점4점_생성(category); - final var product3 = 상품_애플망고_가격3000원_평점5점_생성(category); - 복수_상품_저장(product1, product2, product3); - final var productIds1 = 상품_아이디_변환(product1, product2); - final var productIds2 = 상품_아이디_변환(product1, product3); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리)); - final var loginCookie = 로그인_쿠키를_얻는다(); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); - final var createRequest1 = 레시피추가요청_생성(productIds1); - final var createRequest2 = 레시피추가요청_생성(productIds2); - final var images = 여러_사진_요청(3); - - 레시피_생성_요청(createRequest1, images, loginCookie); - 레시피_생성_요청(createRequest2, images, loginCookie); - - final var pageDto = new PageDto(0L, 0L, true, true, FIRST_PAGE, PAGE_SIZE); - final var expected = Collections.emptyList(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(0L), 총_페이지(0L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 레시피_검색_결과_조회_요청("참치", 0); + final var 응답 = 레시피_검색_결과_조회_요청("참치", FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 페이지를_검증한다(response, pageDto); - 레시피_검색_결과를_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 레시피_검색_결과를_검증한다(응답, Collections.emptyList()); } } @@ -639,148 +439,69 @@ class getSortingRecipes_성공_테스트 { @Test void 꿀조합을_좋아요가_많은_순으로_정렬할_수_있다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1_1 = 레시피_생성(member1, 1L); - final var recipe1_2 = 레시피_생성(member1, 3L); - final var recipe1_3 = 레시피_생성(member1, 2L); - 복수_꿀조합_저장(recipe1_1, recipe1_2, recipe1_3); - - final var product_recipe_1_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_1); - final var product_recipe_1_1_2 = 레시피_안에_들어가는_상품_생성(product2, recipe1_1); - final var product_recipe_1_1_3 = 레시피_안에_들어가는_상품_생성(product3, recipe1_1); - final var product_recipe_1_2_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_2); - final var product_recipe_1_2_2 = 레시피_안에_들어가는_상품_생성(product3, recipe1_2); - 복수_꿀조합_상품_저장(product_recipe_1_1_1, product_recipe_1_1_2, product_recipe_1_1_3, product_recipe_1_2_1, - product_recipe_1_2_2); - - final var recipeImage1_1_1 = 레시피이미지_생성(recipe1_1); - final var recipeImage1_2_1 = 레시피이미지_생성(recipe1_2); - final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); - 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1, recipeImage1_2_2); - - final var pageDto = new PageDto(3L, 1L, true, true, 0L, 10L); - final var sortingRecipes = List.of( - RecipeDto.toDto(recipe1_2, List.of(recipeImage1_2_1, recipeImage1_2_2), - List.of(product1, product3)), - RecipeDto.toDto(recipe1_3, List.of(), List.of()), - RecipeDto.toDto(recipe1_1, List.of(recipeImage1_1_1), List.of(product1, product2, product3))); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + 여러명이_레시피_좋아요_요청(List.of(멤버1), 레시피1, 좋아요O); + 여러명이_레시피_좋아요_요청(List.of(멤버1, 멤버2), 레시피2, 좋아요O); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 레시피_목록_요청("favoriteCount", "desc", 0); + final var 응답 = 레시피_목록_요청(좋아요수_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 레시피_목록_조회_결과를_검증한다(response, sortingRecipes, pageDto); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 레시피_목록_조회_결과를_검증한다(응답, List.of(레시피2, 레시피1, 레시피3)); } @Test void 꿀조합을_최신순으로_정렬할_수_있다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1_1 = 레시피_생성(member1, 1L); - final var recipe1_2 = 레시피_생성(member1, 3L); - final var recipe1_3 = 레시피_생성(member1, 2L); - 복수_꿀조합_저장(recipe1_1, recipe1_2, recipe1_3); - - final var product_recipe_1_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_1); - final var product_recipe_1_1_2 = 레시피_안에_들어가는_상품_생성(product2, recipe1_1); - final var product_recipe_1_1_3 = 레시피_안에_들어가는_상품_생성(product3, recipe1_1); - final var product_recipe_1_2_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_2); - final var product_recipe_1_2_2 = 레시피_안에_들어가는_상품_생성(product3, recipe1_2); - 복수_꿀조합_상품_저장(product_recipe_1_1_1, product_recipe_1_1_2, product_recipe_1_1_3, product_recipe_1_2_1, - product_recipe_1_2_2); - - final var recipeImage1_1_1 = 레시피이미지_생성(recipe1_1); - final var recipeImage1_2_1 = 레시피이미지_생성(recipe1_2); - final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); - 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1, recipeImage1_2_2); - - final var pageDto = new PageDto(3L, 1L, true, true, 0L, 10L); - final var sortingRecipes = List.of( - RecipeDto.toDto(recipe1_3, List.of(), List.of()), - RecipeDto.toDto(recipe1_2, List.of(recipeImage1_2_1, recipeImage1_2_2), - List.of(product1, product3)), - RecipeDto.toDto(recipe1_1, List.of(recipeImage1_1_1), List.of(product1, product2, product3))); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 레시피_목록_요청("createdAt", "desc", 0); + final var 응답 = 레시피_목록_요청(최신순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 레시피_목록_조회_결과를_검증한다(response, sortingRecipes, pageDto); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 레시피_목록_조회_결과를_검증한다(응답, List.of(레시피3, 레시피2, 레시피1)); } @Test void 꿀조합을_오래된순으로_정렬할_수_있다() { // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점5점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - final var product3 = 상품_삼각김밥_가격2000원_평점1점_생성(category); - 복수_상품_저장(product1, product2, product3); - - final var recipe1_1 = 레시피_생성(member1, 1L); - final var recipe1_2 = 레시피_생성(member1, 3L); - final var recipe1_3 = 레시피_생성(member1, 2L); - 복수_꿀조합_저장(recipe1_1, recipe1_2, recipe1_3); - - final var product_recipe_1_1_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_1); - final var product_recipe_1_1_2 = 레시피_안에_들어가는_상품_생성(product2, recipe1_1); - final var product_recipe_1_1_3 = 레시피_안에_들어가는_상품_생성(product3, recipe1_1); - final var product_recipe_1_2_1 = 레시피_안에_들어가는_상품_생성(product1, recipe1_2); - final var product_recipe_1_2_2 = 레시피_안에_들어가는_상품_생성(product3, recipe1_2); - 복수_꿀조합_상품_저장(product_recipe_1_1_1, product_recipe_1_1_2, product_recipe_1_1_3, product_recipe_1_2_1, - product_recipe_1_2_2); - - final var recipeImage1_1_1 = 레시피이미지_생성(recipe1_1); - final var recipeImage1_2_1 = 레시피이미지_생성(recipe1_2); - final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); - 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1, recipeImage1_2_2); - - final var pageDto = new PageDto(3L, 1L, true, true, 0L, 10L); - final var sortingRecipes = List.of( - RecipeDto.toDto(recipe1_1, List.of(recipeImage1_1_1), List.of(product1, product2, product3)), - RecipeDto.toDto(recipe1_2, List.of(recipeImage1_2_1, recipeImage1_2_2), - List.of(product1, product3)), - RecipeDto.toDto(recipe1_3, List.of(), List.of())); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 레시피_목록_요청("createdAt", "asc", 0); + final var response = 레시피_목록_요청(과거순, FIRST_PAGE); // then STATUS_CODE를_검증한다(response, 정상_처리); - 레시피_목록_조회_결과를_검증한다(response, sortingRecipes, pageDto); + 페이지를_검증한다(response, 예상_응답_페이지); + 레시피_목록_조회_결과를_검증한다(response, List.of(레시피1, 레시피2, 레시피3)); } } @@ -790,113 +511,83 @@ class getRankingRecipes_성공_테스트 { @Test void 전체_꿀조합들_중에서_랭킹_TOP3를_조회할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var recipe1 = 레시피_생성(member, 1L); - final var recipe2 = 레시피_생성(member, 2L); - final var recipe3 = 레시피_생성(member, 3L); - final var recipe4 = 레시피_생성(member, 4L); - 복수_꿀조합_저장(recipe1, recipe2, recipe3, recipe4); - - final var expectedRecipes = List.of(recipe4, recipe3, recipe2); - final var expected = 예상_레시피_랭킹_변환(expectedRecipes, member); + final var 카테고리 = 카테고리_간편식사_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리)); + + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품)); + 레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지4), 레시피추가요청_생성(상품)); + 여러명이_레시피_좋아요_요청(List.of(멤버1, 멤버2), 레시피2, 좋아요O); + 여러명이_레시피_좋아요_요청(List.of(멤버1), 레시피3, 좋아요O); + 여러명이_레시피_좋아요_요청(List.of(멤버1, 멤버2, 멤버3), 레시피4, 좋아요O); // when - final var response = 레시피_랭킹_조회_요청(); + final var 응답 = 레시피_랭킹_조회_요청(); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 레시피_랭킹_조회_결과를_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 레시피_랭킹_조회_결과를_검증한다(응답, List.of(레시피4, 레시피2, 레시피3)); } } - private void 레시피_목록_조회_결과를_검증한다(final ExtractableResponse response, final List recipes, - final PageDto pageDto) { - 페이지를_검증한다(response, pageDto); - 레시피_목록을_검증한다(response, recipes); - } - - private void 페이지를_검증한다(final ExtractableResponse response, final PageDto expected) { - final var actual = response.jsonPath().getObject("page", PageDto.class); - - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - - private void 레시피_목록을_검증한다(final ExtractableResponse response, final List expected) { + private void 레시피_목록_조회_결과를_검증한다(final ExtractableResponse response, final List recipeIds) { final var actual = response.jsonPath().getList("recipes", RecipeDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(RecipeDto::getId) + .containsExactlyElementsOf(recipeIds); } - private void 레시피_좋아요_결과를_검증한다(final Member member, final Long recipeId, final Long expectedFavoriteCount, - final boolean expectedFavorite) { - final var actualRecipe = recipeRepository.findById(recipeId).get(); - final var actualRecipeFavorite = recipeFavoriteRepository.findByMemberAndRecipe(member, actualRecipe).get(); - - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualRecipe.getFavoriteCount()) - .isEqualTo(expectedFavoriteCount); - softAssertions.assertThat(actualRecipeFavorite.getFavorite()) - .isEqualTo(expectedFavorite); + private void 레시피_상세_정보_조회_결과를_검증한다(final ExtractableResponse response) { + final var actual = response.as(RecipeDetailResponse.class); + final var actualAuthor = response.jsonPath().getObject("author", RecipeAuthorDto.class); + final var actualProducts = response.jsonPath().getList("products", ProductRecipeDto.class); + + assertSoftly(soft -> { + soft.assertThat(actual.getId()).isEqualTo(1L); + soft.assertThat(actual.getImages()).hasSize(0); + soft.assertThat(actual.getTitle()).isEqualTo("The most delicious recipes"); + soft.assertThat(actual.getContent()).isEqualTo("More rice, more rice, more rice.. Done!!"); + soft.assertThat(actual.getTotalPrice()).isEqualTo(4000L); + soft.assertThat(actual.getFavoriteCount()).isEqualTo(0L); + soft.assertThat(actual.getFavorite()).isEqualTo(false); + soft.assertThat(actualAuthor.getNickname()).isEqualTo("member1"); + soft.assertThat(actualAuthor.getProfileImage()).isEqualTo("www.member1.com"); + soft.assertThat(actualProducts).extracting(ProductRecipeDto::getId) + .containsExactlyElementsOf(List.of(1L, 2L)); }); } - private void 레시피_상세_정보_조회_결과를_검증한다(final RecipeDetailResponse actual, final RecipeDetailResponse expected) { - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, final String expectedMessage) { - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) + assertSoftly(soft -> { + soft.assertThat(response.jsonPath().getString("code")) .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) + soft.assertThat(response.jsonPath().getString("message")) .isEqualTo(expectedMessage); }); } - private Long 상품_총가격_계산(final Product... products) { - return Stream.of(products) - .mapToLong(Product::getPrice) - .sum(); - } - - private List 상품_아이디_변환(final Product... products) { - return Stream.of(products) - .map(Product::getId) - .collect(Collectors.toList()); - } - private List 예상_레시피_랭킹_변환(final List recipes, final Member member) { return recipes.stream() .map(it -> RankingRecipeDto.toDto(it, Collections.emptyList(), RecipeAuthorDto.toDto(member))) .collect(Collectors.toList()); } - private void 레시피_랭킹_조회_결과를_검증한다(final ExtractableResponse response, - final List expected) { + private void 레시피_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List recipeIds) { final var actual = response.jsonPath() .getList("recipes", RankingRecipeDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - - private SearchRecipeResultDto 예상_레시피_검색_결과_변환(final String loginCookie, final Long recipeId1) { - final var response = 레시피_상세_정보_요청(loginCookie, recipeId1).as(RecipeDetailResponse.class); - return new SearchRecipeResultDto(response.getId(), response.getImages().get(0), response.getTitle(), - response.getAuthor(), response.getProducts(), response.getFavoriteCount(), response.getCreatedAt()); + assertThat(actual).extracting(RankingRecipeDto::getId) + .isEqualTo(recipeIds); } - private void 레시피_검색_결과를_검증한다(final ExtractableResponse response, final List expected) { + private void 레시피_검색_결과를_검증한다(final ExtractableResponse response, final List recipeIds) { final var actual = response.jsonPath() .getList("recipes", SearchRecipeResultDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(SearchRecipeResultDto::getId) + .containsExactlyElementsOf(recipeIds); } } 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 fd4c437ba..f82c84f93 100644 --- a/backend/src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java @@ -1,24 +1,23 @@ package com.funeat.acceptance.recipe; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; +import static com.funeat.fixture.RecipeFixture.레시피좋아요요청_생성; import static io.restassured.RestAssured.given; import com.funeat.recipe.dto.RecipeCreateRequest; import com.funeat.recipe.dto.RecipeFavoriteRequest; -import io.restassured.builder.MultiPartSpecBuilder; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.IntStream; @SuppressWarnings("NonAsciiCharacters") public class RecipeSteps { - public static ExtractableResponse 레시피_생성_요청(final RecipeCreateRequest recipeRequest, + public static ExtractableResponse 레시피_작성_요청(final String loginCookie, final List images, - final String loginCookie) { + final RecipeCreateRequest recipeRequest) { final var requestSpec = given() .cookie("FUNEAT", loginCookie); @@ -34,13 +33,6 @@ public class RecipeSteps { .extract(); } - public static Long 레시피_추가_요청하고_id_반환(final RecipeCreateRequest recipeRequest, - final List imageList, - final String loginCookie) { - final var response = 레시피_생성_요청(recipeRequest, imageList, loginCookie); - return Long.parseLong(response.header("Location").split("/")[3]); - } - public static ExtractableResponse 레시피_상세_정보_요청(final String loginCookie, final Long recipeId) { return given() .cookie("FUNEAT", loginCookie) @@ -50,10 +42,9 @@ public class RecipeSteps { .extract(); } - public static ExtractableResponse 레시피_목록_요청(final String sortType, final String sortOrderType, - final int page) { + public static ExtractableResponse 레시피_목록_요청(final String sort, final Long page) { return given() - .queryParam("sort", sortType + "," + sortOrderType) + .queryParam("sort", sort) .queryParam("page", page) .when() .get("/api/recipes") @@ -73,14 +64,13 @@ public class RecipeSteps { .extract(); } - public static List 여러_사진_요청(final int count) { - return IntStream.range(0, count) - .mapToObj(i -> new MultiPartSpecBuilder("image".getBytes()) - .fileName("testImage.png") - .controlName("images") - .mimeType("image/png") - .build()) - .collect(Collectors.toList()); + public static void 여러명이_레시피_좋아요_요청(final List memberIds, final Long recipeId, + final Boolean favorite) { + final var request = 레시피좋아요요청_생성(favorite); + + for (final var memberId : memberIds) { + 레시피_좋아요_요청(로그인_쿠키_획득(memberId), recipeId, request); + } } public static ExtractableResponse 레시피_랭킹_조회_요청() { @@ -91,7 +81,7 @@ public class RecipeSteps { .extract(); } - public static ExtractableResponse 레시피_검색_결과_조회_요청(final String query, final int page) { + public static ExtractableResponse 레시피_검색_결과_조회_요청(final String query, final Long page) { return given() .queryParam("query", query) .queryParam("page", page) diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index a6e12bf9d..07552c34c 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -1,6 +1,6 @@ package com.funeat.acceptance.review; -import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; import static com.funeat.acceptance.common.CommonSteps.사진_명세_요청; import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; @@ -9,51 +9,70 @@ import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.common.CommonSteps.정상_처리_NO_CONTENT; import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; -import static com.funeat.acceptance.review.ReviewSteps.단일_리뷰_요청; +import static com.funeat.acceptance.common.CommonSteps.페이지를_검증한다; +import static com.funeat.acceptance.product.ProductSteps.상품_상세_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_랭킹_조회_요청; +import static com.funeat.acceptance.review.ReviewSteps.리뷰_작성_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_좋아요_요청; +import static com.funeat.acceptance.review.ReviewSteps.여러명이_리뷰_좋아요_요청; import static com.funeat.acceptance.review.ReviewSteps.정렬된_리뷰_목록_조회_요청; import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND; import static com.funeat.exception.CommonErrorCode.REQUEST_VALID_ERROR_CODE; import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; -import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; +import static com.funeat.fixture.ImageFixture.이미지1; +import static com.funeat.fixture.ImageFixture.이미지2; +import static com.funeat.fixture.ImageFixture.이미지3; +import static com.funeat.fixture.ImageFixture.이미지4; +import static com.funeat.fixture.ImageFixture.이미지5; +import static com.funeat.fixture.MemberFixture.멤버1; +import static com.funeat.fixture.MemberFixture.멤버2; +import static com.funeat.fixture.MemberFixture.멤버3; +import static com.funeat.fixture.PageFixture.FIRST_PAGE; +import static com.funeat.fixture.PageFixture.PAGE_SIZE; +import static com.funeat.fixture.PageFixture.마지막페이지O; +import static com.funeat.fixture.PageFixture.응답_페이지_생성; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.첫페이지O; +import static com.funeat.fixture.PageFixture.총_데이터_개수; +import static com.funeat.fixture.PageFixture.총_페이지; +import static com.funeat.fixture.PageFixture.최신순; +import static com.funeat.fixture.PageFixture.평점_내림차순; +import static com.funeat.fixture.PageFixture.평점_오름차순; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test1_평점1점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test2_평점2점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test3_평점3점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test3_평점3점_재구매X_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test4_평점4점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰_이미지test5_평점5점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_false_생성; -import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_true_생성; +import static com.funeat.fixture.ProductFixture.존재하지_않는_상품; +import static com.funeat.fixture.ReviewFixture.리뷰; +import static com.funeat.fixture.ReviewFixture.리뷰1; +import static com.funeat.fixture.ReviewFixture.리뷰2; +import static com.funeat.fixture.ReviewFixture.리뷰3; +import static com.funeat.fixture.ReviewFixture.리뷰4; +import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_생성; +import static com.funeat.fixture.ReviewFixture.리뷰추가요청_생성; import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; +import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매X_생성; +import static com.funeat.fixture.ReviewFixture.재구매O; +import static com.funeat.fixture.ReviewFixture.존재하지_않는_리뷰; +import static com.funeat.fixture.ReviewFixture.좋아요O; +import static com.funeat.fixture.ReviewFixture.좋아요X; +import static com.funeat.fixture.ScoreFixture.점수_1점; +import static com.funeat.fixture.ScoreFixture.점수_2점; +import static com.funeat.fixture.ScoreFixture.점수_3점; +import static com.funeat.fixture.ScoreFixture.점수_4점; +import static com.funeat.fixture.ScoreFixture.점수_5점; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; -import static com.funeat.fixture.TagFixture.태그_푸짐해요_PRICE_생성; import static com.funeat.product.exception.ProductErrorCode.PRODUCT_NOT_FOUND; import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; import com.funeat.acceptance.common.AcceptanceTest; -import com.funeat.common.dto.PageDto; -import com.funeat.member.domain.Member; -import com.funeat.member.domain.favorite.ReviewFavorite; -import com.funeat.product.domain.Product; -import com.funeat.review.domain.Review; import com.funeat.review.dto.RankingReviewDto; import com.funeat.review.dto.ReviewCreateRequest; -import com.funeat.review.dto.ReviewFavoriteRequest; import com.funeat.review.dto.SortingReviewDto; -import com.funeat.tag.domain.Tag; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import java.util.Collections; 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; import org.junit.jupiter.params.ParameterizedTest; @@ -66,54 +85,35 @@ class ReviewAcceptanceTest extends AcceptanceTest { class writeReview_성공_테스트 { @Test - void 리뷰를_작성한다() { + void 이미지를_포함하여_리뷰를_작성한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var request = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); // when - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), + 리뷰추가요청_재구매O_생성(점수_1점, List.of(태그))); // then - STATUS_CODE를_검증한다(response, 정상_생성); + STATUS_CODE를_검증한다(응답, 정상_생성); } @Test void 이미지가_없어도_리뷰를_작성할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var request = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); // when - final var response = 단일_리뷰_요청(productId, null, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, null, + 리뷰추가요청_재구매O_생성(점수_1점, List.of(태그))); // then - STATUS_CODE를_검증한다(response, 정상_생성); + STATUS_CODE를_검증한다(응답, 정상_생성); } } @@ -124,200 +124,130 @@ class writeReview_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_리뷰_작성시_예외가_발생한다(final String cookie) { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var request = 리뷰추가요청_재구매O_생성(4L, tagIds); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); // when - final var response = 단일_리뷰_요청(productId, image, request, cookie); + final var 응답 = 리뷰_작성_요청(cookie, 상품, 사진_명세_요청(이미지1), + 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); // then - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - STATUS_CODE를_검증한다(response, 인증되지_않음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @Test void 사용자가_리뷰_작성할때_태그들이_NULL일시_예외가_발생한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var image = 사진_명세_요청(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); // when - final var request = 리뷰추가요청_재구매O_생성(4L, null); - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), + 리뷰추가요청_재구매O_생성(점수_4점, null)); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "태그 ID 목록을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "태그 ID 목록을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 사용자가_리뷰_작성할때_태그들이_비어있을시_예외가_발생한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var image = 사진_명세_요청(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); // when - final var request = 리뷰추가요청_재구매O_생성(4L, Collections.emptyList()); - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), + 리뷰추가요청_재구매O_생성(점수_4점, Collections.emptyList())); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "적어도 1개의 태그 ID가 필요합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "적어도 1개의 태그 ID가 필요합니다. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 사용자가_리뷰_작성할때_평점이_비어있을시_예외가_발생한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); // when - final var request = 리뷰추가요청_재구매O_생성(null, tagIds); - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), + 리뷰추가요청_재구매O_생성(null, List.of(태그))); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "평점을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "평점을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @ParameterizedTest @NullAndEmptySource void 사용자가_리뷰_작성할때_리뷰내용이_비어있을시_예외가_발생한다(final String content) { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 요청 = 리뷰추가요청_생성(점수_1점, List.of(태그), content, 재구매O); // when - final var request = new ReviewCreateRequest(1L, tagIds, content, true); - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "리뷰 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "리뷰 내용을 확인해 주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 사용자가_리뷰_작성할때_재구매여부가_비어있을시_예외가_발생한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 요청 = 리뷰추가요청_생성(점수_1점, List.of(태그), "content", null); // when - final var request = new ReviewCreateRequest(1L, tagIds, "content", null); - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "재구매 여부를 입력해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "재구매 여부를 입력해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 사용자가_리뷰_작성할때_리뷰내용이_200자_초과시_예외가_발생한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var image = 사진_명세_요청(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 리뷰내용_201자 = "test".repeat(50) + "a"; + final var 요청 = new ReviewCreateRequest(점수_1점, List.of(태그), 리뷰내용_201자, 재구매O); // when - final var maxContent = "test".repeat(50) + "a"; - final var request = new ReviewCreateRequest(1L, tagIds, maxContent, true); - final var response = 단일_리뷰_요청(productId, image, request, loginCookie); + final var 응답 = 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 요청); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "리뷰 내용은 최대 200자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "리뷰 내용은 최대 200자까지 입력 가능합니다. " + REQUEST_VALID_ERROR_CODE.getMessage()); } } @@ -327,122 +257,54 @@ class toggleLikeReview_성공_테스트 { @Test void 리뷰에_좋아요를_할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); - 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); - - final var reviewId = reviewRepository.findAll().get(0).getId(); - final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); // when - final var response = 리뷰_좋아요_요청(productId, reviewId, favoriteRequest, loginCookie); - final var actual = reviewFavoriteRepository.findAll().get(0); + final var 응답 = 리뷰_좋아요_요청(로그인_쿠키_획득(멤버1), 상품, 리뷰, 리뷰좋아요요청_생성(좋아요O)); // then - STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT); - 리뷰_좋아요_결과를_검증한다(actual, memberId, reviewId, true); + STATUS_CODE를_검증한다(응답, 정상_처리_NO_CONTENT); } @Test void 리뷰에_좋아요를_취소할_수_있다() { // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); - - 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); - - final var reviewId = reviewRepository.findAll().get(0).getId(); - - final var favoriteRequest = 리뷰좋아요요청_true_생성(); - 리뷰_좋아요_요청(productId, reviewId, favoriteRequest, loginCookie); - - final var favoriteCancelRequest = 리뷰좋아요요청_false_생성(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_좋아요_요청(로그인_쿠키_획득(멤버1), 상품, 리뷰, 리뷰좋아요요청_생성(좋아요O)); // when - final var response = 리뷰_좋아요_요청(productId, reviewId, favoriteCancelRequest, loginCookie); - final var actual = reviewFavoriteRepository.findAll().get(0); + final var 응답 = 리뷰_좋아요_요청(로그인_쿠키_획득(멤버1), 상품, 리뷰, 리뷰좋아요요청_생성(좋아요X)); // then - STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT); - 리뷰_좋아요_결과를_검증한다(actual, memberId, reviewId, false); + STATUS_CODE를_검증한다(응답, 정상_처리_NO_CONTENT); } @Test void 상품_이미지가_존재하는_좋아요를_가장_많이_받은_리뷰로_상품_이미지가_바뀐다() { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청("first"); - final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_1점, List.of(태그))); - 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); - 단일_리뷰_요청(productId, null, reviewRequest, loginCookie); - - final var firstReview = reviewRepository.findById(1L).get(); - final var firstReviewId = firstReview.getId(); - final var secondReview = reviewRepository.findById(2L).get(); - final var secondReviewId = secondReview.getId(); - - final var trueFavoriteRequest = 리뷰좋아요요청_true_생성(); - 리뷰_좋아요_요청(productId, secondReviewId, trueFavoriteRequest, loginCookie); - final var falseFavoriteRequest = 리뷰좋아요요청_false_생성(); - 리뷰_좋아요_요청(productId, secondReviewId, falseFavoriteRequest, loginCookie); - - final var expected = reviewRepository.findAll().get(0); + 리뷰_좋아요_요청(로그인_쿠키_획득(멤버1), 상품, 리뷰2, 리뷰좋아요요청_생성(좋아요O)); // when - final var response = 리뷰_좋아요_요청(productId, firstReviewId, trueFavoriteRequest, loginCookie); - final var actual = productRepository.findAll().get(0); + final var 응답 = 상품_상세_조회_요청(상품); // then - STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT); - 상품_사진을_검증한다(actual, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 상품_사진을_검증한다(응답, "2.png"); } } @@ -453,96 +315,52 @@ class toggleLikeReview_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_리뷰에_좋아요를_할때_예외가_발생한다(final String cookie) { // given - final var member = 멤버_멤버1_생성(); - 단일_멤버_저장(member); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); - 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); - - final var reviewId = reviewRepository.findAll().get(0).getId(); - final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); // when - final var response = 리뷰_좋아요_요청(productId, reviewId, favoriteRequest, cookie); + final var 응답 = 리뷰_좋아요_요청(cookie, 상품, 리뷰, 리뷰좋아요요청_생성(좋아요O)); // then - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - STATUS_CODE를_검증한다(response, 인증되지_않음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @Test void 사용자가_리뷰에_좋아요를_할때_좋아요_미기입시_예외가_발생한다() { // given - final var member = 멤버_멤버1_생성(); - final var memberId = 단일_멤버_저장(member); - - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_푸짐해요_PRICE_생성(); - 복수_태그_저장(tag1, tag2); - - final var tagIds = 태그_아이디_변환(tag1, tag2); - - final var image = 사진_명세_요청(); - final var reviewRequest = 리뷰추가요청_재구매O_생성(4L, tagIds); - final var loginCookie = 로그인_쿠키를_얻는다(); - 단일_리뷰_요청(productId, image, reviewRequest, loginCookie); - - final var reviewId = reviewRepository.findAll().get(0).getId(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); // when - final var request = new ReviewFavoriteRequest(null); - final var response = 리뷰_좋아요_요청(productId, reviewId, request, loginCookie); + final var 응답 = 리뷰_좋아요_요청(로그인_쿠키_획득(멤버1), 상품, 리뷰, 리뷰좋아요요청_생성(null)); // then - final var expectedCode = REQUEST_VALID_ERROR_CODE.getCode(); - final var expectedMessage = "좋아요를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage(); - - STATUS_CODE를_검증한다(response, 잘못된_요청); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 잘못된_요청); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(), + "좋아요를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage()); } @Test void 존재하지_않는_리뷰에_사용자가_좋아요를_할때_예외가_발생한다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var favoriteRequest = 리뷰좋아요요청_true_생성(); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); // when - final var notExistReviewId = 99999L; - final var response = 리뷰_좋아요_요청(productId, notExistReviewId, favoriteRequest, loginCookie); + final var 응답 = 리뷰_좋아요_요청(로그인_쿠키_획득(멤버1), 상품, 존재하지_않는_리뷰, 리뷰좋아요요청_생성(좋아요O)); // then - STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, REVIEW_NOT_FOUND.getCode(), REVIEW_NOT_FOUND.getMessage()); + STATUS_CODE를_검증한다(응답, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, REVIEW_NOT_FOUND.getCode(), REVIEW_NOT_FOUND.getMessage()); } } @@ -555,64 +373,49 @@ class 좋아요_기준_내림차순으로_리뷰_목록_조회 { @Test void 좋아요_수가_서로_다르면_좋아요_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); + 여러명이_리뷰_좋아요_요청(List.of(멤버1), 상품, 리뷰3, 좋아요O); + 여러명이_리뷰_좋아요_요청(List.of(멤버2, 멤버3), 상품, 리뷰2, 좋아요O); - final var sortingReviews = List.of(review2, review3, review1); - final var pageDto = new PageDto(3L, 1L, true, true, 0L, 10L); - - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "favoriteCount,desc", 0); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 좋아요수_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, pageDto, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3, 리뷰1)); } @Test void 좋아요_수가_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 130L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 130L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); - - final var sortingReviews = List.of(review3, review2, review1); - final var pageDto = new PageDto(3L, 1L, true, true, 0L, 10L); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "favoriteCount,desc", 0); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 좋아요수_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, pageDto, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -622,63 +425,47 @@ class 평점_기준_오름차순으로_리뷰_목록을_조회 { @Test void 평점이_서로_다르면_평점_기준_오름차순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_2점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var review1 = 리뷰_이미지test2_평점2점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); - - final var sortingReviews = List.of(review1, review3, review2); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "rating,asc", 0); - final var page = new PageDto(3L, 1L, true, true, 0L, 10L); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_오름차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, page, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰1, 리뷰3, 리뷰2)); } @Test void 평점이_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test3_평점3점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var sortingReviews = List.of(review3, review2, review1); - final var page = new PageDto(3L, 1L, true, true, 0L, 10L); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "rating,asc", 0); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_오름차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, page, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -688,63 +475,47 @@ class 평점_기준_내림차순으로_리뷰_목록_조회 { @Test void 평점이_서로_다르면_평점_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_2점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var review1 = 리뷰_이미지test2_평점2점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); - - final var sortingReviews = List.of(review2, review3, review1); - final var page = new PageDto(3L, 1L, true, true, 0L, 10L); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "rating,desc", 0); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, page, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3, 리뷰1)); } @Test void 평점이_서로_같으면_ID_기준_내림차순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); - - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test3_평점3점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var sortingReviews = List.of(review3, review2, review1); - final var page = new PageDto(3L, 1L, true, true, 0L, 10L); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "rating,desc", 0); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, page, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -754,32 +525,24 @@ class 최신순으로_리뷰_목록을_조회 { @Test void 등록_시간이_서로_다르면_최신순으로_정렬할_수_있다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_2점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var review1 = 리뷰_이미지test2_평점2점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); - - final var sortingReviews = List.of(review3, review2, review1); - final var loginCookie = 로그인_쿠키를_얻는다(); + final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, productId, "createdAt,desc", 0); - final var page = new PageDto(3L, 1L, true, true, 0L, 10L); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 최신순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 정렬된_리뷰_목록_조회_결과를_검증한다(response, sortingReviews, page, member1); + STATUS_CODE를_검증한다(응답, 정상_처리); + 페이지를_검증한다(응답, 예상_응답_페이지); + 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } } @@ -791,45 +554,30 @@ class getSortingReviews_실패_테스트 { @NullAndEmptySource void 로그인_하지않은_사용자가_리뷰_목록을_조회시_예외가_발생한다(final String cookie) { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var productId = 단일_상품_저장(product); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 5L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 351L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_2점, List.of(태그))); // when - final var response = 정렬된_리뷰_목록_조회_요청(cookie, productId, "favoriteCount,desc", 0); + final var 응답 = 정렬된_리뷰_목록_조회_요청(cookie, 상품, 좋아요수_내림차순, FIRST_PAGE); // then - final var expectedCode = LOGIN_MEMBER_NOT_FOUND.getCode(); - final var expectedMessage = LOGIN_MEMBER_NOT_FOUND.getMessage(); - - STATUS_CODE를_검증한다(response, 인증되지_않음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, expectedCode, expectedMessage); + STATUS_CODE를_검증한다(응답, 인증되지_않음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, LOGIN_MEMBER_NOT_FOUND.getCode(), + LOGIN_MEMBER_NOT_FOUND.getMessage()); } @Test void 존재하지_않는_상품의_리뷰_목록을_조회시_예외가_발생한다() { - // given - final var notExistProductId = 99999L; - final var loginCookie = 로그인_쿠키를_얻는다(); - - // when - final var response = 정렬된_리뷰_목록_조회_요청(loginCookie, notExistProductId, "favoriteCount,desc", 0); + // given && when + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_상품, 좋아요수_내림차순, FIRST_PAGE); // then - STATUS_CODE를_검증한다(response, 찾을수_없음); - RESPONSE_CODE와_MESSAGE를_검증한다(response, PRODUCT_NOT_FOUND.getCode(), PRODUCT_NOT_FOUND.getMessage()); + STATUS_CODE를_검증한다(응답, 찾을수_없음); + RESPONSE_CODE와_MESSAGE를_검증한다(응답, PRODUCT_NOT_FOUND.getCode(), PRODUCT_NOT_FOUND.getMessage()); } } @@ -839,109 +587,58 @@ class getRankingReviews_성공_테스트 { @Test void 리뷰_랭킹을_조회하다() { // given - final var category = 카테고리_즉석조리_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점3점_생성(category); - 복수_상품_저장(product1, product2); - - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var review1_1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product1, 5L); - final var review1_2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product1, 351L); - final var review1_3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product1, 130L); - final var review2_1 = 리뷰_이미지test5_평점5점_재구매O_생성(member1, product2, 247L); - final var review2_2 = 리뷰_이미지test1_평점1점_재구매X_생성(member2, product2, 83L); - 복수_리뷰_저장(review1_1, review1_2, review1_3, review2_1, review2_2); - - final var rankingReviews = List.of(review1_2, review2_1, review1_3); + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격2000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품1, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품1, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품1, 사진_명세_요청(이미지3), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품2, 사진_명세_요청(이미지4), 리뷰추가요청_재구매O_생성(점수_5점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품2, 사진_명세_요청(이미지5), 리뷰추가요청_재구매O_생성(점수_1점, List.of(태그))); + 여러명이_리뷰_좋아요_요청(List.of(멤버1, 멤버2, 멤버3), 상품1, 리뷰2, 좋아요O); + 여러명이_리뷰_좋아요_요청(List.of(멤버1, 멤버2), 상품1, 리뷰3, 좋아요O); + 여러명이_리뷰_좋아요_요청(List.of(멤버1), 상품1, 리뷰4, 좋아요O); // when - final var response = 리뷰_랭킹_조회_요청(); + final var 응답 = 리뷰_랭킹_조회_요청(); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 리뷰_랭킹_조회_결과를_검증한다(response, rankingReviews); + STATUS_CODE를_검증한다(응답, 정상_처리); + 리뷰_랭킹_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3, 리뷰4)); } } - private void 리뷰_좋아요_결과를_검증한다(final ReviewFavorite actual, final Long expectedMemberId, - final Long expectedReviewId, final Boolean expectedFavorite) { - final var actualId = actual.getId(); - final var actualMemberId = actual.getMember().getId(); - final var actualReviewId = actual.getReview().getId(); - final var actualFavorite = actual.getFavorite(); - - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualId) - .isNotNull(); - softAssertions.assertThat(actualReviewId) - .isEqualTo(expectedReviewId); - softAssertions.assertThat(actualMemberId) - .isEqualTo(expectedMemberId); - softAssertions.assertThat(actualFavorite) - .isEqualTo(expectedFavorite); - }); - } - private void RESPONSE_CODE와_MESSAGE를_검증한다(final ExtractableResponse response, final String expectedCode, final String expectedMessage) { - assertSoftly(softAssertions -> { - softAssertions.assertThat(response.jsonPath().getString("code")) + assertSoftly(soft -> { + soft.assertThat(response.jsonPath().getString("code")) .isEqualTo(expectedCode); - softAssertions.assertThat(response.jsonPath().getString("message")) + soft.assertThat(response.jsonPath().getString("message")) .isEqualTo(expectedMessage); }); } - private List 태그_아이디_변환(final Tag... tags) { - return Stream.of(tags) - .map(Tag::getId) - .collect(Collectors.toList()); - } - - private void 정렬된_리뷰_목록_조회_결과를_검증한다(final ExtractableResponse response, final List reviews, - final PageDto pageDto, final Member member) { - 페이지를_검증한다(response, pageDto); - 리뷰_목록을_검증한다(response, reviews, member); - } - - private void 페이지를_검증한다(final ExtractableResponse response, final PageDto expected) { - final var actual = response.jsonPath().getObject("page", PageDto.class); - - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - - private void 리뷰_목록을_검증한다(final ExtractableResponse response, final List reviews, - final Member member) { - final var expected = reviews.stream() - .map(review -> SortingReviewDto.toDto(review, member)) - .collect(Collectors.toList()); + private void 정렬된_리뷰_목록_조회_결과를_검증한다(final ExtractableResponse response, final List reviewIds) { final var actual = response.jsonPath().getList("reviews", SortingReviewDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(SortingReviewDto::getId) + .containsExactlyElementsOf(reviewIds); } - private void 리뷰_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List reviews) { - final var expected = reviews.stream() - .map(RankingReviewDto::toDto) - .collect(Collectors.toList()); + private void 리뷰_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List reviewIds) { final var actual = response.jsonPath() .getList("reviews", RankingReviewDto.class); - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); + assertThat(actual).extracting(RankingReviewDto::getReviewId) + .containsExactlyElementsOf(reviewIds); } - private void 상품_사진을_검증한다(final Product product, final Review review) { - final var actual = product.getImage(); - final var expected = review.getImage(); + private void 상품_사진을_검증한다(final ExtractableResponse response, final String expected) { + final var actual = response.jsonPath() + .getString("image"); assertThat(actual).isEqualTo(expected); } diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java index b003353a6..d59d9eded 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java @@ -1,5 +1,8 @@ package com.funeat.acceptance.review; +import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; +import static com.funeat.acceptance.common.CommonSteps.LOCATION_헤더에서_ID_추출; +import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_생성; import static io.restassured.RestAssured.given; import com.funeat.review.dto.ReviewCreateRequest; @@ -7,13 +10,15 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.MultiPartSpecification; +import java.util.List; import java.util.Objects; @SuppressWarnings("NonAsciiCharacters") public class ReviewSteps { - public static ExtractableResponse 단일_리뷰_요청(final Long productId, final MultiPartSpecification image, - final ReviewCreateRequest request, final String loginCookie) { + public static ExtractableResponse 리뷰_작성_요청(final String loginCookie, final Long productId, + final MultiPartSpecification image, + final ReviewCreateRequest request) { final var requestSpec = given() .cookie("FUNEAT", loginCookie); @@ -29,9 +34,8 @@ public class ReviewSteps { .extract(); } - public static ExtractableResponse 리뷰_좋아요_요청(final Long productId, final Long reviewId, - final ReviewFavoriteRequest request, - final String loginCookie) { + public static ExtractableResponse 리뷰_좋아요_요청(final String loginCookie, final Long productId, + final Long reviewId, final ReviewFavoriteRequest request) { return given() .cookie("FUNEAT", loginCookie) .contentType("application/json") @@ -42,8 +46,17 @@ public class ReviewSteps { .extract(); } + public static void 여러명이_리뷰_좋아요_요청(final List memberIds, final Long productId, final Long reviewId, + final Boolean favorite) { + final var request = 리뷰좋아요요청_생성(favorite); + + for (final var memberId : memberIds) { + 리뷰_좋아요_요청(로그인_쿠키_획득(memberId), productId, reviewId, request); + } + } + public static ExtractableResponse 정렬된_리뷰_목록_조회_요청(final String loginCookie, final Long productId, - final String sort, final Integer page) { + final String sort, final Long page) { return given() .cookie("FUNEAT", loginCookie) .queryParam("sort", sort) diff --git a/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java index a5be9ab71..426c7508b 100644 --- a/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java @@ -7,11 +7,9 @@ import static com.funeat.fixture.TagFixture.태그_갓성비_PRICE_생성; import static com.funeat.fixture.TagFixture.태그_단짠단짠_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; -import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.assertj.core.api.Assertions.assertThat; import com.funeat.acceptance.common.AcceptanceTest; -import com.funeat.tag.domain.Tag; -import com.funeat.tag.domain.TagType; import com.funeat.tag.dto.TagDto; import com.funeat.tag.dto.TagsResponse; import io.restassured.response.ExtractableResponse; @@ -30,45 +28,29 @@ class getAllTags_성공_테스트 { @Test void 전체_태그_목록을_조회할_수_있다() { // given - final var tag1 = 태그_맛있어요_TASTE_생성(); - final var tag2 = 태그_단짠단짠_TASTE_생성(); - final var tag3 = 태그_갓성비_PRICE_생성(); - final var tag4 = 태그_간식_ETC_생성(); - 복수_태그_저장(tag1, tag2, tag3, tag4); - - final var expected = List.of(tag1, tag2, tag3, tag4); + final var 맛있어요 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + final var 단짠단짠 = 단일_태그_저장(태그_단짠단짠_TASTE_생성()); + final var 갓성비 = 단일_태그_저장(태그_갓성비_PRICE_생성()); + final var 간식 = 단일_태그_저장(태그_간식_ETC_생성()); // when - final var response = 전체_태그_목록_조회_요청(); + final var 응답 = 전체_태그_목록_조회_요청(); // then - STATUS_CODE를_검증한다(response, 정상_처리); - 전체_태그_목록_조회_결과를_검증한다(response, expected); + STATUS_CODE를_검증한다(응답, 정상_처리); + 전체_태그_목록_조회_결과를_검증한다(응답, List.of(맛있어요, 단짠단짠, 갓성비, 간식)); } } - private void 전체_태그_목록_조회_결과를_검증한다(final ExtractableResponse response, final List expected) { - final var expectedByType = expected.stream() - .collect(Collectors.groupingBy(Tag::getTagType)); + private void 전체_태그_목록_조회_결과를_검증한다(final ExtractableResponse response, final List tagIds) { final var actual = response.jsonPath() .getList("", TagsResponse.class); - for (final var tagsResponse : actual) { - final var actualTagType = TagType.valueOf(tagsResponse.getTagType()); - final var actualTag = tagsResponse.getTags(); - - final var expectedTagTypes = expectedByType.keySet(); - final var expectedTag = expectedByType.get(actualTagType).stream() - .map(TagDto::toDto) - .collect(Collectors.toList()); + final var actualTagIds = actual.stream() + .flatMap(tagsResponse -> tagsResponse.getTags().stream()) + .map(TagDto::getId) + .collect(Collectors.toList()); - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualTagType) - .isIn(expectedTagTypes); - softAssertions.assertThat(actualTag) - .usingRecursiveComparison() - .isEqualTo(expectedTag); - }); - } + assertThat(actualTagIds).containsExactlyElementsOf(tagIds); } } diff --git a/backend/src/test/java/com/funeat/auth/application/AuthServiceTest.java b/backend/src/test/java/com/funeat/auth/application/AuthServiceTest.java index 206a825b0..7f82ccb6a 100644 --- a/backend/src/test/java/com/funeat/auth/application/AuthServiceTest.java +++ b/backend/src/test/java/com/funeat/auth/application/AuthServiceTest.java @@ -18,7 +18,7 @@ class loginWithKakao_성공_테스트 { @Test void 카카오_로그인을_하여_멤버_정보를_가져온다() { // given - final var code = "member1"; + final var code = "1"; final var member = 멤버_멤버1_생성(); final var expected = SignUserDto.of(true, member); diff --git a/backend/src/test/java/com/funeat/fixture/CategoryFixture.java b/backend/src/test/java/com/funeat/fixture/CategoryFixture.java index 9d6da56ab..95ee4b056 100644 --- a/backend/src/test/java/com/funeat/fixture/CategoryFixture.java +++ b/backend/src/test/java/com/funeat/fixture/CategoryFixture.java @@ -6,6 +6,10 @@ @SuppressWarnings("NonAsciiCharacters") public class CategoryFixture { + public static final String 음식 = "food"; + + public static final Long 존재하지_않는_카테고리 = 99999L; + public static Category 카테고리_간편식사_생성() { return new Category("간편식사", CategoryType.FOOD, "siksa.jpeg"); } diff --git a/backend/src/test/java/com/funeat/fixture/ImageFixture.java b/backend/src/test/java/com/funeat/fixture/ImageFixture.java index ae30f99fd..5e744727e 100644 --- a/backend/src/test/java/com/funeat/fixture/ImageFixture.java +++ b/backend/src/test/java/com/funeat/fixture/ImageFixture.java @@ -9,6 +9,14 @@ @SuppressWarnings("NonAsciiCharacters") public class ImageFixture { + public static final String 이미지1 = "1"; + public static final String 이미지2 = "2"; + public static final String 이미지3 = "3"; + public static final String 이미지4 = "4"; + public static final String 이미지5 = "5"; + public static final String 이미지6 = "6"; + public static final String 이미지7 = "7"; + public static MultipartFile 이미지_생성() { return new MockMultipartFile("image", "image.jpg", "image/jpeg", new byte[]{1, 2, 3}); } diff --git a/backend/src/test/java/com/funeat/fixture/MemberFixture.java b/backend/src/test/java/com/funeat/fixture/MemberFixture.java index 9337594b2..b6d67798f 100644 --- a/backend/src/test/java/com/funeat/fixture/MemberFixture.java +++ b/backend/src/test/java/com/funeat/fixture/MemberFixture.java @@ -1,10 +1,16 @@ package com.funeat.fixture; import com.funeat.member.domain.Member; +import com.funeat.member.dto.MemberRequest; @SuppressWarnings("NonAsciiCharacters") public class MemberFixture { + public static final Long 멤버1 = 1L; + public static final Long 멤버2 = 2L; + public static final Long 멤버3 = 3L; + + public static Member 멤버_멤버1_생성() { return new Member("member1", "www.member1.com", "1"); } @@ -16,4 +22,8 @@ public class MemberFixture { public static Member 멤버_멤버3_생성() { return new Member("member3", "www.member3.com", "3"); } + + public static MemberRequest 유저닉네임수정요청_생성(final String modifyNickname) { + return new MemberRequest(modifyNickname); + } } diff --git a/backend/src/test/java/com/funeat/fixture/PageFixture.java b/backend/src/test/java/com/funeat/fixture/PageFixture.java index 6aab74a64..afae2d14a 100644 --- a/backend/src/test/java/com/funeat/fixture/PageFixture.java +++ b/backend/src/test/java/com/funeat/fixture/PageFixture.java @@ -1,78 +1,55 @@ package com.funeat.fixture; +import com.funeat.common.dto.PageDto; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; @SuppressWarnings("NonAsciiCharacters") public class PageFixture { - private static final String 평균_평점 = "averageRating"; - private static final String 가격 = "price"; - private static final String 좋아요 = "favoriteCount"; - private static final String 평점 = "rating"; - private static final String 생성_시간 = "createdAt"; + public static final String 평균_평점_오름차순 = "averageRating,asc"; + public static final String 평균_평점_내림차순 = "averageRating,desc"; + public static final String 가격_오름차순 = "price,asc"; + public static final String 가격_내림차순 = "price,desc"; + public static final String 좋아요수_내림차순 = "favoriteCount,desc"; + public static final String 리뷰수_내림차순 = "reviewCount,desc"; + public static final String 평점_오름차순 = "rating,asc"; + public static final String 평점_내림차순 = "rating,desc"; + public static final String 과거순 = "createdAt,asc"; + public static final String 최신순 = "createdAt,desc"; + + public static final Long PAGE_SIZE = 10L; + public static final Long FIRST_PAGE = 0L; + public static final Long SECOND_PAGE = 1L; + + public static final boolean 첫페이지O = true; + public static final boolean 첫페이지X = false; + public static final boolean 마지막페이지O = true; + public static final boolean 마지막페이지X = false; public static PageRequest 페이지요청_기본_생성(final int page, final int size) { return PageRequest.of(page, size); } - public static PageRequest 페이지요청_평균_평점_오름차순_생성(final int page, final int size) { - final var sort = Sort.by(평균_평점).ascending(); + public static PageRequest 페이지요청_생성(final int page, final int size, final String sort) { + final String[] splitSort = sort.split(","); + final String order = splitSort[0]; + final Direction direction = Direction.fromString(splitSort[1]); - return PageRequest.of(page, size, sort); + return PageRequest.of(page, size, Sort.by(direction, order)); } - public static PageRequest 페이지요청_평균_평점_내림차순_생성(final int page, final int size) { - final var sort = Sort.by(평균_평점).descending(); - - return PageRequest.of(page, size, sort); - } - - public static PageRequest 페이지요청_가격_오름차순_생성(final int page, final int size) { - final var sort = Sort.by(가격).ascending(); - - return PageRequest.of(page, size, sort); + public static PageDto 응답_페이지_생성(final Long totalDataCount, final Long totalPages, final boolean firstPage, + final boolean lastPage, final Long requestPage, final Long requestSize) { + return new PageDto(totalDataCount, totalPages, firstPage, lastPage, requestPage, requestSize); } - public static PageRequest 페이지요청_가격_내림차순_생성(final int page, final int size) { - final var sort = Sort.by(가격).descending(); - - return PageRequest.of(page, size, sort); - } - - public static PageRequest 페이지요청_좋아요_오름차순_생성(final int page, final int size) { - final var sort = Sort.by(좋아요).ascending(); - - return PageRequest.of(page, size, sort); - } - - public static PageRequest 페이지요청_좋아요_내림차순_생성(final int page, final int size) { - final var sort = Sort.by(좋아요).descending(); - - return PageRequest.of(page, size, sort); + public static Long 총_데이터_개수(final Long count) { + return count; } - public static PageRequest 페이지요청_평점_오름차순_생성(final int page, final int size) { - final var sort = Sort.by(평점).ascending(); - - return PageRequest.of(page, size, sort); - } - - public static PageRequest 페이지요청_평점_내림차순_생성(final int page, final int size) { - final var sort = Sort.by(평점).descending(); - - return PageRequest.of(page, size, sort); - } - - public static PageRequest 페이지요청_생성_시간_오름차순_생성(final int page, final int size) { - final var sort = Sort.by(생성_시간).ascending(); - - return PageRequest.of(page, size, sort); - } - - public static PageRequest 페이지요청_생성_시간_내림차순_생성(final int page, final int size) { - final var sort = Sort.by(생성_시간).descending(); - - return PageRequest.of(page, size, sort); + public static Long 총_페이지(final Long page) { + return page; } } diff --git a/backend/src/test/java/com/funeat/fixture/ProductFixture.java b/backend/src/test/java/com/funeat/fixture/ProductFixture.java index c506834d6..15b2fa27e 100644 --- a/backend/src/test/java/com/funeat/fixture/ProductFixture.java +++ b/backend/src/test/java/com/funeat/fixture/ProductFixture.java @@ -8,6 +8,20 @@ @SuppressWarnings("NonAsciiCharacters") public class ProductFixture { + public static final Long 존재하지_않는_상품 = 99999L; + public static final Long 상품 = 1L; + public static final Long 상품1 = 1L; + public static final Long 상품2 = 2L; + public static final Long 상품3 = 3L; + public static final Long 상품4 = 4L; + public static final Long 상품5 = 5L; + public static final Long 상품6 = 6L; + public static final Long 상품7 = 7L; + public static final Long 상품8 = 8L; + public static final Long 상품9 = 9L; + public static final Long 상품10 = 10L; + public static final Long 상품11 = 11L; + public static Product 상품_삼각김밥_가격1000원_평점1점_생성(final Category category) { return new Product("삼각김밥", 1000L, "image.png", "맛있는 삼각김밥", 1.0, category); } diff --git a/backend/src/test/java/com/funeat/fixture/RecipeFixture.java b/backend/src/test/java/com/funeat/fixture/RecipeFixture.java index b63ea2ac1..2050727f3 100644 --- a/backend/src/test/java/com/funeat/fixture/RecipeFixture.java +++ b/backend/src/test/java/com/funeat/fixture/RecipeFixture.java @@ -11,20 +11,42 @@ @SuppressWarnings("NonAsciiCharacters") public class RecipeFixture { + public static final Long 레시피 = 1L; + public static final Long 존재하지_않는_레시피 = 99999L; + public static final Long 레시피1 = 1L; + public static final Long 레시피2 = 2L; + public static final Long 레시피3 = 3L; + public static final Long 레시피4 = 4L; + + public static final boolean 좋아요O = true; + public static final boolean 좋아요X = false; + + public static final String 레시피_제목 = "The most delicious recipes"; + public static final String 레시피_본문 = "More rice, more rice, more rice.. Done!!"; + + public static Recipe 레시피_생성(final Member member) { - return new Recipe("제일로 맛있는 레시피", "밥 추가, 밥 추가, 밥 추가.. 끝!!", member); + return new Recipe("The most delicious recipes", "More rice, more rice, more rice.. Done!!", member); } public static Recipe 레시피_생성(final Member member, final Long favoriteCount) { - return new Recipe("제일로 맛있는 레시피", "밥 추가, 밥 추가, 밥 추가.. 끝!!", member, favoriteCount); + return new Recipe("The most delicious recipes", "More rice, more rice, more rice.. Done!!", member, favoriteCount); } public static RecipeFavorite 레시피_좋아요_생성(final Member member, final Recipe recipe, final Boolean favorite) { return new RecipeFavorite(member, recipe, favorite); } + public static RecipeCreateRequest 레시피추가요청_생성(final String title, final List productIds, final String content) { + return new RecipeCreateRequest(title, productIds, content); + } + + public static RecipeCreateRequest 레시피추가요청_생성(final Long... productIds) { + return new RecipeCreateRequest("The most delicious recipes", List.of(productIds), "More rice, more rice, more rice.. Done!!"); + } + public static RecipeCreateRequest 레시피추가요청_생성(final List productIds) { - return new RecipeCreateRequest("제일로 맛있는 레시피", productIds, "밥 추가, 밥 추가, 밥 추가.. 끝!!"); + return new RecipeCreateRequest("The most delicious recipes", productIds, "More rice, more rice, more rice.. Done!!"); } public static RecipeFavoriteRequest 레시피좋아요요청_생성(final Boolean favorite) { diff --git a/backend/src/test/java/com/funeat/fixture/ReviewFixture.java b/backend/src/test/java/com/funeat/fixture/ReviewFixture.java index 7f4c82a25..3ae53a3c7 100644 --- a/backend/src/test/java/com/funeat/fixture/ReviewFixture.java +++ b/backend/src/test/java/com/funeat/fixture/ReviewFixture.java @@ -10,6 +10,17 @@ @SuppressWarnings("NonAsciiCharacters") public class ReviewFixture { + public static final Long 리뷰 = 1L; + public static final Long 존재하지_않는_리뷰 = 99999L; + public static final Long 리뷰1 = 1L; + public static final Long 리뷰2 = 2L; + public static final Long 리뷰3 = 3L; + public static final Long 리뷰4 = 4L; + public static final boolean 좋아요O = true; + public static final boolean 좋아요X = false; + public static final boolean 재구매O = true; + public static final boolean 재구매X = false; + public static Review 리뷰_이미지test1_평점1점_재구매O_생성(final Member member, final Product product, final Long count) { return new Review(member, product, "test1", 1L, "test", true, count); } @@ -54,6 +65,11 @@ public class ReviewFixture { return new Review(member, product, "test5", 5L, "test", false, count); } + public static ReviewCreateRequest 리뷰추가요청_생성(final Long rating, final List tagIds, final String content, + final Boolean rebuy) { + return new ReviewCreateRequest(rating, tagIds, content, rebuy); + } + public static ReviewCreateRequest 리뷰추가요청_재구매O_생성(final Long rating, final List tagIds) { return new ReviewCreateRequest(rating, tagIds, "test", true); } @@ -62,11 +78,7 @@ public class ReviewFixture { return new ReviewCreateRequest(rating, tagIds, "test", false); } - public static ReviewFavoriteRequest 리뷰좋아요요청_true_생성() { - return new ReviewFavoriteRequest(true); - } - - public static ReviewFavoriteRequest 리뷰좋아요요청_false_생성() { - return new ReviewFavoriteRequest(false); + public static ReviewFavoriteRequest 리뷰좋아요요청_생성(final Boolean favorite) { + return new ReviewFavoriteRequest(favorite); } } diff --git a/backend/src/test/java/com/funeat/fixture/ScoreFixture.java b/backend/src/test/java/com/funeat/fixture/ScoreFixture.java new file mode 100644 index 000000000..3f9ce8ece --- /dev/null +++ b/backend/src/test/java/com/funeat/fixture/ScoreFixture.java @@ -0,0 +1,11 @@ +package com.funeat.fixture; + +@SuppressWarnings("NonAsciiCharacters") +public class ScoreFixture { + + public static final Long 점수_1점 = 1L; + public static final Long 점수_2점 = 2L; + public static final Long 점수_3점 = 3L; + public static final Long 점수_4점 = 4L; + public static final Long 점수_5점 = 5L; +} diff --git a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java index 4d4a03e17..e67eb942d 100644 --- a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java +++ b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java @@ -36,10 +36,10 @@ class findOrCreateMember_성공_테스트 { final var actual = memberService.findOrCreateMember(userInfoDto); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actual.isSignUp()) + assertSoftly(soft -> { + soft.assertThat(actual.isSignUp()) .isFalse(); - softAssertions.assertThat(expected) + soft.assertThat(expected) .containsExactly(actual.getMember()); }); } @@ -58,10 +58,10 @@ class findOrCreateMember_성공_테스트 { final var actual = memberService.findOrCreateMember(userInfoDto); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actual.isSignUp()) + assertSoftly(soft -> { + soft.assertThat(actual.isSignUp()) .isTrue(); - softAssertions.assertThat(expected) + soft.assertThat(expected) .doesNotContain(actual.getMember()); }); } @@ -140,10 +140,10 @@ class modify_성공_테스트 { final var actualProfileImage = actual.getProfileImage(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualNickname) + assertSoftly(soft -> { + soft.assertThat(actualNickname) .isEqualTo(expectedNickname); - softAssertions.assertThat(actualProfileImage) + soft.assertThat(actualProfileImage) .isEqualTo(expectedProfileImage); }); } @@ -170,10 +170,10 @@ class modify_성공_테스트 { final var actualProfileImage = actual.getProfileImage(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualNickname) + assertSoftly(soft -> { + soft.assertThat(actualNickname) .isNotEqualTo(expectedNickname); - softAssertions.assertThat(actualProfileImage) + soft.assertThat(actualProfileImage) .isEqualTo(expectedProfileImage); }); } @@ -199,10 +199,10 @@ class modify_성공_테스트 { final var actualProfileImage = actual.getProfileImage(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualNickname) + assertSoftly(soft -> { + soft.assertThat(actualNickname) .isEqualTo(expectedNickname); - softAssertions.assertThat(actualProfileImage) + soft.assertThat(actualProfileImage) .isNotEqualTo(expectedProfileImage); }); } @@ -229,10 +229,10 @@ class modify_성공_테스트 { final var actualProfileImage = actual.getProfileImage(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualNickname) + assertSoftly(soft -> { + soft.assertThat(actualNickname) .isNotEqualTo(expectedNickname); - softAssertions.assertThat(actualProfileImage) + soft.assertThat(actualProfileImage) .isNotEqualTo(expectedProfileImage); }); } diff --git a/backend/src/test/java/com/funeat/member/domain/MemberTest.java b/backend/src/test/java/com/funeat/member/domain/MemberTest.java index 39bc4c1fa..25bbda6dc 100644 --- a/backend/src/test/java/com/funeat/member/domain/MemberTest.java +++ b/backend/src/test/java/com/funeat/member/domain/MemberTest.java @@ -30,10 +30,10 @@ class modifyProfile_성공_테스트 { final var actualProfileImage = member.getProfileImage(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualNickname) + assertSoftly(soft -> { + soft.assertThat(actualNickname) .isEqualTo(expectedNickname); - softAssertions.assertThat(actualProfileImage) + soft.assertThat(actualProfileImage) .isEqualTo(expectedProfileImage); }); } diff --git a/backend/src/test/java/com/funeat/member/domain/favorite/RecipeFavoriteTest.java b/backend/src/test/java/com/funeat/member/domain/favorite/RecipeFavoriteTest.java index 8da60b358..99f69ae56 100644 --- a/backend/src/test/java/com/funeat/member/domain/favorite/RecipeFavoriteTest.java +++ b/backend/src/test/java/com/funeat/member/domain/favorite/RecipeFavoriteTest.java @@ -41,10 +41,10 @@ class updateFavorite_성공_테스트 { recipeFavorite.updateFavorite(true); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) .isOne(); - softAssertions.assertThat(recipeFavorite.getFavorite()) + soft.assertThat(recipeFavorite.getFavorite()) .isTrue(); }); } @@ -62,10 +62,10 @@ class updateFavorite_성공_테스트 { recipeFavorite.updateFavorite(false); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) .isZero(); - softAssertions.assertThat(recipeFavorite.getFavorite()) + soft.assertThat(recipeFavorite.getFavorite()) .isFalse(); }); } @@ -83,10 +83,10 @@ class updateFavorite_성공_테스트 { recipeFavorite.updateFavorite(true); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) .isOne(); - softAssertions.assertThat(recipeFavorite.getFavorite()) + soft.assertThat(recipeFavorite.getFavorite()) .isTrue(); }); } @@ -103,10 +103,10 @@ class updateFavorite_성공_테스트 { recipeFavorite.updateFavorite(false); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(recipeFavorite.getRecipe().getFavoriteCount()) .isZero(); - softAssertions.assertThat(recipeFavorite.getFavorite()) + soft.assertThat(recipeFavorite.getFavorite()) .isFalse(); }); } diff --git a/backend/src/test/java/com/funeat/member/persistence/RecipeFavoriteRepositoryTest.java b/backend/src/test/java/com/funeat/member/persistence/RecipeFavoriteRepositoryTest.java index 0a1d9bdf7..1d87dd531 100644 --- a/backend/src/test/java/com/funeat/member/persistence/RecipeFavoriteRepositoryTest.java +++ b/backend/src/test/java/com/funeat/member/persistence/RecipeFavoriteRepositoryTest.java @@ -67,10 +67,10 @@ class findByMemberAndRecipe_성공_테스트 { final var fakeMemberActual = recipeFavoriteRepository.findByMemberAndRecipe(fakeMember, recipe); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(realMemberActual) + assertSoftly(soft -> { + soft.assertThat(realMemberActual) .isNotEmpty(); - softAssertions.assertThat(fakeMemberActual) + soft.assertThat(fakeMemberActual) .isEmpty(); }); } @@ -115,10 +115,10 @@ class existsByMemberAndRecipeAndFavoriteTrue_성공_테스트 { recipe); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(realMemberActual) + assertSoftly(soft -> { + soft.assertThat(realMemberActual) .isTrue(); - softAssertions.assertThat(fakeMemberActual) + soft.assertThat(fakeMemberActual) .isFalse(); }); } diff --git a/backend/src/test/java/com/funeat/product/domain/ProductTest.java b/backend/src/test/java/com/funeat/product/domain/ProductTest.java index bee40ecc0..ddfeaa2c7 100644 --- a/backend/src/test/java/com/funeat/product/domain/ProductTest.java +++ b/backend/src/test/java/com/funeat/product/domain/ProductTest.java @@ -48,10 +48,10 @@ class updateAverageRating_성공_테스트 { final var actual2 = product.getAverageRating(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actual1) + assertSoftly(soft -> { + soft.assertThat(actual1) .isEqualTo(4.0); - softAssertions.assertThat(actual2) + soft.assertThat(actual2) .isEqualTo(3.0); }); } diff --git a/backend/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java b/backend/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java index 81983a65b..887958516 100644 --- a/backend/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java +++ b/backend/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java @@ -4,11 +4,12 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; -import static com.funeat.fixture.PageFixture.페이지요청_가격_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_가격_오름차순_생성; +import static com.funeat.fixture.PageFixture.가격_내림차순; +import static com.funeat.fixture.PageFixture.가격_오름차순; import static com.funeat.fixture.PageFixture.페이지요청_기본_생성; -import static com.funeat.fixture.PageFixture.페이지요청_평균_평점_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_평균_평점_오름차순_생성; +import static com.funeat.fixture.PageFixture.페이지요청_생성; +import static com.funeat.fixture.PageFixture.평균_평점_내림차순; +import static com.funeat.fixture.PageFixture.평균_평점_오름차순; import static com.funeat.fixture.ProductFixture.상품_망고빙수_가격5000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; @@ -57,7 +58,7 @@ class findByAllCategory_성공_테스트 { final var product5 = 상품_삼각김밥_가격1000원_평점5점_생성(category); 복수_상품_저장(product1, product2, product3, product4, product5); - final var page = 페이지요청_평균_평점_내림차순_생성(0, 3); + final var page = 페이지요청_생성(0, 3, 평균_평점_내림차순); final var productInCategoryDto1 = ProductInCategoryDto.toDto(product5, 0L); final var productInCategoryDto2 = ProductInCategoryDto.toDto(product4, 0L); @@ -85,7 +86,7 @@ class findByAllCategory_성공_테스트 { final var product5 = 상품_삼각김밥_가격1000원_평점5점_생성(category); 복수_상품_저장(product1, product2, product3, product4, product5); - final var page = 페이지요청_평균_평점_오름차순_생성(0, 3); + final var page = 페이지요청_생성(0, 3, 평균_평점_오름차순); final var productInCategoryDto1 = ProductInCategoryDto.toDto(product1, 0L); final var productInCategoryDto2 = ProductInCategoryDto.toDto(product2, 0L); @@ -113,7 +114,7 @@ class findByAllCategory_성공_테스트 { final var product5 = 상품_삼각김밥_가격5000원_평점1점_생성(category); 복수_상품_저장(product1, product2, product3, product4, product5); - final var page = 페이지요청_가격_내림차순_생성(0, 3); + final var page = 페이지요청_생성(0, 3, 가격_내림차순); final var productInCategoryDto1 = ProductInCategoryDto.toDto(product5, 0L); final var productInCategoryDto2 = ProductInCategoryDto.toDto(product4, 0L); @@ -141,7 +142,7 @@ class findByAllCategory_성공_테스트 { final var product5 = 상품_삼각김밥_가격5000원_평점1점_생성(category); 복수_상품_저장(product1, product2, product3, product4, product5); - final var page = 페이지요청_가격_오름차순_생성(0, 3); + final var page = 페이지요청_생성(0, 3, 가격_오름차순); final var productInCategoryDto1 = ProductInCategoryDto.toDto(product1, 0L); final var productInCategoryDto2 = ProductInCategoryDto.toDto(product2, 0L); diff --git a/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java b/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java index 1b9b09aba..fcd4e2f40 100644 --- a/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java +++ b/backend/src/test/java/com/funeat/recipe/application/RecipeServiceTest.java @@ -1,5 +1,29 @@ package com.funeat.recipe.application; +import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; +import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; +import static com.funeat.fixture.ImageFixture.여러_이미지_생성; +import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; +import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; +import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; +import static com.funeat.fixture.PageFixture.과거순; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.최신순; +import static com.funeat.fixture.PageFixture.페이지요청_생성; +import static com.funeat.fixture.ProductFixture.레시피_안에_들어가는_상품_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점5점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; +import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격3000원_평점4점_생성; +import static com.funeat.fixture.RecipeFixture.레시피_생성; +import static com.funeat.fixture.RecipeFixture.레시피이미지_생성; +import static com.funeat.fixture.RecipeFixture.레시피좋아요요청_생성; +import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; + import com.funeat.common.ServiceTest; import com.funeat.common.dto.PageDto; import com.funeat.member.domain.Member; @@ -23,17 +47,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static com.funeat.fixture.CategoryFixture.카테고리_간편식사_생성; -import static com.funeat.fixture.CategoryFixture.카테고리_즉석조리_생성; -import static com.funeat.fixture.ImageFixture.여러_이미지_생성; -import static com.funeat.fixture.MemberFixture.*; -import static com.funeat.fixture.PageFixture.*; -import static com.funeat.fixture.ProductFixture.*; -import static com.funeat.fixture.RecipeFixture.*; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.SoftAssertions.assertSoftly; - @SuppressWarnings("NonAsciiCharacters") class RecipeServiceTest extends ServiceTest { @@ -194,7 +207,7 @@ class findRecipeByMember_성공_테스트 { final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage1_2); - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); // when final var actual = recipeService.findRecipeByMember(member1.getId(), page); @@ -220,9 +233,9 @@ class findRecipeByMember_성공_테스트 { void 사용자가_작성한_꿀조합이_없을때_꿀조합은_빈상태로_조회된다() { // given final var member1 = 멤버_멤버1_생성(); - 복수_멤버_저장(member1); + 단일_멤버_저장(member1); - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); // when final var actual = recipeService.findRecipeByMember(member1.getId(), page); @@ -242,7 +255,7 @@ class findRecipeByMember_실패_테스트 { void 존재하지_않는_멤버가_해당_멤버의_레시피를_조회하면_예외가_발생한다() { // given final var notExistMemberId = 99999L; - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); // when & then assertThatThrownBy(() -> recipeService.findRecipeByMember(notExistMemberId, page)) @@ -287,7 +300,7 @@ class getSortingRecipes_성공_테스트 { final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1); - final var page = 페이지요청_좋아요_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 좋아요수_내림차순); // when final var actual = recipeService.getSortingRecipes(page).getRecipes(); @@ -337,7 +350,7 @@ class getSortingRecipes_성공_테스트 { final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1); - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); // when final var actual = recipeService.getSortingRecipes(page).getRecipes(); @@ -387,7 +400,7 @@ class getSortingRecipes_성공_테스트 { final var recipeImage1_2_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1_1, recipeImage1_2_1); - final var page = 페이지요청_생성_시간_오름차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 과거순); // when final var actual = recipeService.getSortingRecipes(page).getRecipes(); @@ -437,10 +450,10 @@ class likeRecipe_성공_테스트 { final var actualRecipeFavorite = recipeFavoriteRepository.findByMemberAndRecipe(member, actualRecipe).get(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualRecipe.getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(actualRecipe.getFavoriteCount()) .isOne(); - softAssertions.assertThat(actualRecipeFavorite.getFavorite()) + soft.assertThat(actualRecipeFavorite.getFavorite()) .isTrue(); }); } @@ -478,10 +491,10 @@ class likeRecipe_성공_테스트 { final var actualRecipeFavorite = recipeFavoriteRepository.findByMemberAndRecipe(member, actualRecipe).get(); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualRecipe.getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(actualRecipe.getFavoriteCount()) .isZero(); - softAssertions.assertThat(actualRecipeFavorite.getFavorite()) + soft.assertThat(actualRecipeFavorite.getFavorite()) .isFalse(); }); } @@ -534,7 +547,7 @@ class likeRecipe_실패_테스트 { private void 해당멤버의_꿀조합과_페이징_결과를_검증한다(final MemberRecipesResponse actual, final List expectedRecipesDtos, final PageDto expectedPage) { - assertSoftly(softAssertions -> { + assertSoftly(soft -> { assertThat(actual.getRecipes()).usingRecursiveComparison() .isEqualTo(expectedRecipesDtos); assertThat(actual.getPage()).usingRecursiveComparison() diff --git a/backend/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java b/backend/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java index f701969bd..c7130d2ce 100644 --- a/backend/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java +++ b/backend/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java @@ -4,10 +4,11 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; +import static com.funeat.fixture.PageFixture.과거순; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.PageFixture.페이지요청_기본_생성; -import static com.funeat.fixture.PageFixture.페이지요청_생성_시간_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_생성_시간_오름차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_좋아요_내림차순_생성; +import static com.funeat.fixture.PageFixture.페이지요청_생성; import static com.funeat.fixture.ProductFixture.레시피_안에_들어가는_상품_생성; import static com.funeat.fixture.ProductFixture.상품_망고빙수_가격5000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점1점_생성; @@ -105,7 +106,7 @@ class findAllRecipes_성공_테스트 { final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage1_2); - final var page = 페이지요청_좋아요_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 좋아요수_내림차순); final var expected = List.of(recipe1_2, recipe1_3, recipe1_1); // when @@ -150,7 +151,7 @@ class findAllRecipes_성공_테스트 { final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage1_2); - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); final var expected = List.of(recipe1_3, recipe1_2, recipe1_1); // when @@ -195,7 +196,7 @@ class findAllRecipes_성공_테스트 { final var recipeImage1_2 = 레시피이미지_생성(recipe1_2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage1_2); - final var page = 페이지요청_생성_시간_오름차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 과거순); final var expected = List.of(recipe1_1, recipe1_2, recipe1_3); // when @@ -242,7 +243,8 @@ class findRecipesByProduct_성공_테스트 { final var recipeImage2_1 = 레시피이미지_생성(recipe2); final var recipeImage2_2 = 레시피이미지_생성(recipe2); 복수_꿀조합_이미지_저장(recipeImage1_1, recipeImage2_1, recipeImage2_2); - final var page = 페이지요청_좋아요_내림차순_생성(0, 10); + + final var page = 페이지요청_생성(0, 10, 좋아요수_내림차순); final var expected = List.of(recipe2, recipe1); // when diff --git a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java index 819a46797..aa2a0b33e 100644 --- a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -5,11 +5,12 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.PageFixture.페이지요청_기본_생성; -import static com.funeat.fixture.PageFixture.페이지요청_생성_시간_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_좋아요_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_평점_내림차순_생성; -import static com.funeat.fixture.PageFixture.페이지요청_평점_오름차순_생성; +import static com.funeat.fixture.PageFixture.페이지요청_생성; +import static com.funeat.fixture.PageFixture.평점_내림차순; +import static com.funeat.fixture.PageFixture.평점_오름차순; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점5점_생성; @@ -23,8 +24,7 @@ import static com.funeat.fixture.ReviewFixture.리뷰_이미지test3_평점3점_재구매X_생성; import static com.funeat.fixture.ReviewFixture.리뷰_이미지test4_평점4점_재구매O_생성; import static com.funeat.fixture.ReviewFixture.리뷰_이미지없음_평점1점_재구매O_생성; -import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_false_생성; -import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_true_생성; +import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_생성; import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_아침식사_ETC_생성; @@ -203,7 +203,7 @@ class likeReview_성공_테스트 { final var review = reviewRepository.findAll().get(0); final var reviewId = review.getId(); - final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var favoriteRequest = 리뷰좋아요요청_생성(true); // when reviewService.likeReview(reviewId, memberId, favoriteRequest); @@ -212,10 +212,10 @@ class likeReview_성공_테스트 { final var actualReviewFavorite = reviewFavoriteRepository.findAll().get(0); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualReview.getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(actualReview.getFavoriteCount()) .isOne(); - softAssertions.assertThat(actualReviewFavorite.getFavorite()) + soft.assertThat(actualReviewFavorite.getFavorite()) .isTrue(); }); } @@ -244,21 +244,21 @@ class likeReview_성공_테스트 { final var review = reviewRepository.findAll().get(0); final var reviewId = review.getId(); - final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var favoriteRequest = 리뷰좋아요요청_생성(true); reviewService.likeReview(reviewId, memberId, favoriteRequest); // when - final var cancelFavoriteRequest = 리뷰좋아요요청_false_생성(); + final var cancelFavoriteRequest = 리뷰좋아요요청_생성(false); reviewService.likeReview(reviewId, memberId, cancelFavoriteRequest); final var actualReview = reviewRepository.findAll().get(0); final var actualReviewFavorite = reviewFavoriteRepository.findAll().get(0); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actualReview.getFavoriteCount()) + assertSoftly(soft -> { + soft.assertThat(actualReview.getFavoriteCount()) .isZero(); - softAssertions.assertThat(actualReviewFavorite.getFavorite()) + soft.assertThat(actualReviewFavorite.getFavorite()) .isFalse(); }); } @@ -292,7 +292,7 @@ class likeReview_실패_테스트 { final var review = reviewRepository.findAll().get(0); final var reviewId = review.getId(); - final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var favoriteRequest = 리뷰좋아요요청_생성(true); // when assertThatThrownBy(() -> reviewService.likeReview(reviewId, wrongMemberId, favoriteRequest)) @@ -324,7 +324,7 @@ class likeReview_실패_테스트 { final var reviewId = review.getId(); final var wrongReviewId = reviewId + 1L; - final var favoriteRequest = 리뷰좋아요요청_true_생성(); + final var favoriteRequest = 리뷰좋아요요청_생성(true); // when assertThatThrownBy(() -> reviewService.likeReview(wrongReviewId, memberId, favoriteRequest)) @@ -354,7 +354,7 @@ class sortingReviews_성공_테스트 { final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); 복수_리뷰_저장(review1, review2, review3); - final var page = 페이지요청_좋아요_내림차순_생성(0, 2); + final var page = 페이지요청_생성(0, 2, 좋아요수_내림차순); final var member1Id = member1.getId(); final var expected = Stream.of(review1, review3) @@ -388,7 +388,7 @@ class sortingReviews_성공_테스트 { final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); 복수_리뷰_저장(review1, review2, review3); - final var page = 페이지요청_평점_오름차순_생성(0, 2); + final var page = 페이지요청_생성(0, 2, 평점_오름차순); final var member1Id = member1.getId(); final var expected = Stream.of(review1, review3) @@ -422,7 +422,7 @@ class sortingReviews_성공_테스트 { final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); 복수_리뷰_저장(review1, review2, review3); - final var page = 페이지요청_평점_내림차순_생성(0, 2); + final var page = 페이지요청_생성(0, 2, 평점_내림차순); final var member1Id = member1.getId(); final var expected = Stream.of(review2, review3) @@ -456,7 +456,7 @@ class sortingReviews_성공_테스트 { final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); 복수_리뷰_저장(review1, review2, review3); - final var page = 페이지요청_생성_시간_내림차순_생성(0, 2); + final var page = 페이지요청_생성(0, 2, 최신순); final var member1Id = member1.getId(); final var expected = Stream.of(review3, review2) @@ -558,7 +558,7 @@ class findReviewByMember_성공_테스트 { 복수_리뷰_저장(review1_1, review2_1, review2_2, review3_1, review3_2); // when - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); final var member1Id = member1.getId(); final var result = reviewService.findReviewByMember(member1Id, page); @@ -583,7 +583,7 @@ class findReviewByMember_실패_테스트 { void 존재하지_않은_사용자가_작성한_리뷰를_조회할때_예외가_발생한다() { // given final var notExistMemberId = 999999L; - final var page = 페이지요청_생성_시간_내림차순_생성(0, 10); + final var page = 페이지요청_생성(0, 10, 최신순); // when & then assertThatThrownBy(() -> reviewService.findReviewByMember(notExistMemberId, page)) diff --git a/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java b/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java index 8cc78ede7..c076fe6b6 100644 --- a/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java +++ b/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java @@ -5,7 +5,8 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; -import static com.funeat.fixture.PageFixture.페이지요청_좋아요_내림차순_생성; +import static com.funeat.fixture.PageFixture.좋아요수_내림차순; +import static com.funeat.fixture.PageFixture.페이지요청_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점2점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; @@ -56,10 +57,10 @@ class countByProduct_성공_테스트 { final var actual2 = reviewRepository.countByProduct(product2); // then - assertSoftly(softAssertions -> { - softAssertions.assertThat(actual1) + assertSoftly(soft -> { + soft.assertThat(actual1) .isEqualTo(3); - softAssertions.assertThat(actual2) + soft.assertThat(actual2) .isEqualTo(1); }); } @@ -87,7 +88,7 @@ class findReviewsByProduct_성공_테스트 { final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); 복수_리뷰_저장(review1, review2, review3); - final var page = 페이지요청_좋아요_내림차순_생성(0, 2); + final var page = 페이지요청_생성(0, 2, 좋아요수_내림차순); final var expected = List.of(review1, review3);