diff --git a/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/src/test/java/com/funeat/review/application/ReviewServiceTest.java index f16ea97f..f6dfdc76 100644 --- a/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -30,6 +30,7 @@ import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성; import static com.funeat.fixture.TagFixture.태그_맛있어요_TASTE_생성; import static com.funeat.fixture.TagFixture.태그_아침식사_ETC_생성; +import static com.funeat.review.exception.ReviewErrorCode.REVIEW_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -56,12 +57,17 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import jakarta.persistence.EntityManager; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; @SuppressWarnings("NonAsciiCharacters") class ReviewServiceTest extends ServiceTest { + @Autowired + private EntityManager entityManager; + @Nested class create_성공_테스트 { @@ -393,13 +399,21 @@ class sortingReviews_성공_테스트 { Thread.sleep(100); final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member, product, 130L); 복수_리뷰_저장(review1, review2, review3); - + entityManager.clear(); final var request = 리뷰정렬요청_최신순_생성(3L); final var expected = List.of(review2.getId(), review1.getId()); + Review review3_1 = reviewRepository.findById(3L) + .orElseThrow(() -> new ReviewNotFoundException(REVIEW_NOT_FOUND, 3L)); // when final var actual = reviewService.sortingReviews(productId, memberId, request).getReviews(); + if (actual.size() == 3) { + assertThat(review3_1.getCreatedAt()).isEqualTo(actual.get(0).getCreatedAt()); + } else { + assertThat(actual.size()).isEqualTo(3L); + assertThat(review3_1.getCreatedAt()).isEqualTo(actual.get(0).getCreatedAt()); + } // then assertThat(actual).extracting(SortingReviewDto::getId)