diff --git a/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java b/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java index 96c1b0e2e..0fa4e050a 100644 --- a/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java +++ b/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java @@ -31,7 +31,7 @@ public interface ReviewRepository extends JpaRepository { @Query("SELECT r " + "FROM Review r " + "LEFT JOIN r.product p " - + "WHERE p.id = :id AND r.image IS NOT NULL " + + "WHERE p.id = :id AND r.image != '' " + "ORDER BY r.favoriteCount DESC, r.id DESC") List findPopularReviewWithImage(@Param("id") final Long productId, final Pageable pageable); } diff --git a/backend/src/test/java/com/funeat/fixture/ReviewFixture.java b/backend/src/test/java/com/funeat/fixture/ReviewFixture.java index 2fdc23969..7f4c82a25 100644 --- a/backend/src/test/java/com/funeat/fixture/ReviewFixture.java +++ b/backend/src/test/java/com/funeat/fixture/ReviewFixture.java @@ -15,7 +15,7 @@ public class ReviewFixture { } public static Review 리뷰_이미지없음_평점1점_재구매O_생성(final Member member, final Product product, final Long count) { - return new Review(member, product, null, 1L, "test", true, count); + return new Review(member, product, "", 1L, "test", true, count); } public static Review 리뷰_이미지test1_평점1점_재구매X_생성(final Member member, final Product product, final Long count) { 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 7ae5fc6fb..819a46797 100644 --- a/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -738,6 +738,35 @@ class updateProductImage_성공_테스트 { // then assertThat(actual).isEqualTo(expected); } + + @Test + void 이미지가_존재하지_않는_리뷰들만_있으면_상품_이미지는_바뀌지_않는다() { + // given + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); + + final var firstReview = 리뷰_이미지없음_평점1점_재구매O_생성(member, product, 3L); + final var firstReviewId = 단일_리뷰_저장(firstReview); + reviewService.updateProductImage(firstReviewId); + + final var secondReview = 리뷰_이미지없음_평점1점_재구매O_생성(member, product, 2L); + final var secondReviewId = 단일_리뷰_저장(secondReview); + + final var expected = secondReview.getImage(); + + // when + reviewService.updateProductImage(secondReviewId); + final var actual = product.getImage(); + + // then + assertThat(actual).isNotEqualTo(expected); + } } @Nested