Skip to content

Commit

Permalink
test: 북마크한 레시피 목록 조회 리포지토리 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed May 31, 2024
1 parent 4c1ed48 commit 3ba575c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/java/com/funeat/common/RepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +47,9 @@ public abstract class RepositoryTest {
@Autowired
protected RecipeFavoriteRepository recipeFavoriteRepository;

@Autowired
protected RecipeBookmarkRepository recipeBookmarkRepository;

@Autowired
protected ReviewFavoriteRepository reviewFavoriteRepository;

Expand Down Expand Up @@ -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<Banner> banners = List.of(bannerToSave);

Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/funeat/fixture/RecipeFixture.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Long> productIds, final String content) {
return new RecipeCreateRequest(title, productIds, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 3ba575c

Please sign in to comment.