Skip to content

Commit

Permalink
test14
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed Apr 2, 2024
1 parent 8686231 commit 3b5122c
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_성공_테스트 {

Expand Down Expand Up @@ -393,13 +399,22 @@ 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());
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)
Expand Down

0 comments on commit 3b5122c

Please sign in to comment.