diff --git a/src/test/java/com/funeat/common/RepositoryTest.java b/src/test/java/com/funeat/common/RepositoryTest.java index 1ae1fff6..f73a758b 100644 --- a/src/test/java/com/funeat/common/RepositoryTest.java +++ b/src/test/java/com/funeat/common/RepositoryTest.java @@ -3,9 +3,11 @@ import com.funeat.banner.domain.Banner; import com.funeat.banner.persistence.BannerRepository; import com.funeat.member.domain.Member; +import com.funeat.member.domain.bookmark.RecipeBookmark; import com.funeat.member.domain.favorite.RecipeFavorite; import com.funeat.member.domain.favorite.ReviewFavorite; import com.funeat.member.persistence.MemberRepository; +import com.funeat.member.persistence.RecipeBookmarkRepository; import com.funeat.member.persistence.RecipeFavoriteRepository; import com.funeat.member.persistence.ReviewFavoriteRepository; import com.funeat.product.domain.Category; @@ -45,6 +47,9 @@ public abstract class RepositoryTest { @Autowired protected RecipeFavoriteRepository recipeFavoriteRepository; + @Autowired + protected RecipeBookmarkRepository recipeBookmarkRepository; + @Autowired protected ReviewFavoriteRepository reviewFavoriteRepository; @@ -193,6 +198,12 @@ public abstract class RepositoryTest { recipeFavoriteRepository.save(recipeFavorite); } + protected void 복수_레시피_북마크_저장(final RecipeBookmark... recipeBookmarksToSave) { + final var recipeBookmarks = List.of(recipeBookmarksToSave); + + recipeBookmarkRepository.saveAll(recipeBookmarks); + } + protected void 복수_배너_저장(final Banner... bannerToSave) { final List banners = List.of(bannerToSave); diff --git a/src/test/java/com/funeat/fixture/RecipeFixture.java b/src/test/java/com/funeat/fixture/RecipeFixture.java index c05637e5..c6d25371 100644 --- a/src/test/java/com/funeat/fixture/RecipeFixture.java +++ b/src/test/java/com/funeat/fixture/RecipeFixture.java @@ -1,6 +1,7 @@ package com.funeat.fixture; import com.funeat.member.domain.Member; +import com.funeat.member.domain.bookmark.RecipeBookmark; import com.funeat.member.domain.favorite.RecipeFavorite; import com.funeat.recipe.domain.Recipe; import com.funeat.recipe.domain.RecipeImage; @@ -53,6 +54,10 @@ public class RecipeFixture { return new RecipeFavorite(member, recipe, favorite); } + public static RecipeBookmark 레시피_북마크_생성(final Member member, final Recipe recipe, final Boolean bookmark) { + return new RecipeBookmark(member, recipe, bookmark); + } + public static RecipeCreateRequest 레시피추가요청_생성(final String title, final List productIds, final String content) { return new RecipeCreateRequest(title, productIds, content); } diff --git a/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java b/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java index adb5a7a5..70aabf27 100644 --- a/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java +++ b/src/test/java/com/funeat/recipe/persistence/RecipeRepositoryTest.java @@ -15,8 +15,11 @@ import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점1점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; 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.북마크O; +import static com.funeat.fixture.RecipeFixture.북마크X; import static org.assertj.core.api.Assertions.assertThat; import com.funeat.common.RepositoryTest; @@ -347,4 +350,56 @@ class findRecipesByFavoriteCountGreaterThanEqual_성공_테스트 { .isEqualTo(expected); } } + + @Nested + class findBookmarkedRecipesByMember_성공_테스트 { + + @Test + void 특정_멤버가_저장한_모든_꿀조합을_조회한다() { + // given + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var recipe1 = 레시피_생성(member, 1L); + final var recipe2 = 레시피_생성(member, 10L); + final var recipe3 = 레시피_생성(member, 100L); + 복수_꿀조합_저장(recipe1, recipe2, recipe3); + + final var bookmarkRecipe1 = 레시피_북마크_생성(member, recipe1, 북마크X); + final var bookmarkRecipe2 = 레시피_북마크_생성(member, recipe2, 북마크O); + final var bookmarkRecipe3 = 레시피_북마크_생성(member, recipe3, 북마크O); + 복수_레시피_북마크_저장(bookmarkRecipe1, bookmarkRecipe2, bookmarkRecipe3); + + final var expected = List.of(recipe3, recipe2); + final var page = 페이지요청_생성(0, 10, 최신순); + + // when + final var actual = recipeRepository.findBookmarkedRecipesByMember(member, page).getContent(); + + // then + assertThat(actual).usingRecursiveComparison() + .isEqualTo(expected); + } + + @Test + void 특정_멤버가_저장한_꿀조합이_없으면_빈_리스트를_반환한다() { + // given + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var recipe1 = 레시피_생성(member, 0L); + final var recipe2 = 레시피_생성(member, 0L); + 복수_꿀조합_저장(recipe1, recipe2); + + final var expected = Collections.emptyList(); + final var page = 페이지요청_생성(0, 10, 최신순); + + // when + final var actual = recipeRepository.findBookmarkedRecipesByMember(member, page).getContent(); + + // then + assertThat(actual).usingRecursiveComparison() + .isEqualTo(expected); + } + } }