Skip to content

Commit

Permalink
[BE] fix: 이미지가 없는 리뷰는 상품 이미지 변경 대상에 제외 (#667)
Browse files Browse the repository at this point in the history
* fix: 상품 이미지가 변경되어야 하는 상황일 때, image 경로가 ''인 데이터는 제외하기

* test: 이미지가 존재하지 않는 리뷰가 상품 이미지가 변경되지 않는 테스트 추가
  • Loading branch information
70825 authored Sep 19, 2023
1 parent 28e4555 commit bf79379
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
@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<Review> findPopularReviewWithImage(@Param("id") final Long productId, final Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf79379

Please sign in to comment.