|
| 1 | +package com.somemore.review.repository; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import com.somemore.IntegrationTestSupport; |
| 6 | +import com.somemore.review.domain.Review; |
| 7 | +import java.util.Optional; |
| 8 | +import java.util.UUID; |
| 9 | +import org.junit.jupiter.api.DisplayName; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.transaction.annotation.Transactional; |
| 13 | + |
| 14 | +@Transactional |
| 15 | +class ReviewRepositoryImplTest extends IntegrationTestSupport { |
| 16 | + |
| 17 | + @Autowired |
| 18 | + private ReviewRepositoryImpl reviewRepository; |
| 19 | + |
| 20 | + @DisplayName("리뷰 생성 및 조회") |
| 21 | + @Test |
| 22 | + void saveAndFind() { |
| 23 | + // given |
| 24 | + Review review = Review.builder() |
| 25 | + .volunteerApplyId(1L) |
| 26 | + .volunteerId(UUID.randomUUID()) |
| 27 | + .title("리뷰 제목") |
| 28 | + .content("리뷰 내용") |
| 29 | + .imgUrl("") |
| 30 | + .build(); |
| 31 | + reviewRepository.save(review); |
| 32 | + |
| 33 | + // when |
| 34 | + Optional<Review> findReview = reviewRepository.findById(review.getId()); |
| 35 | + |
| 36 | + // then |
| 37 | + assertThat(findReview).isPresent(); |
| 38 | + assertThat(findReview.get().getId()).isEqualTo(review.getId()); |
| 39 | + } |
| 40 | + |
| 41 | + @DisplayName("봉사 지원 아이디로 리뷰 존재 유무를 확인할 수 있다") |
| 42 | + @Test |
| 43 | + void existsByVolunteerApplyId() { |
| 44 | + // given |
| 45 | + Long volunteerApplyId = 1L; |
| 46 | + Review review = Review.builder() |
| 47 | + .volunteerApplyId(volunteerApplyId) |
| 48 | + .volunteerId(UUID.randomUUID()) |
| 49 | + .title("리뷰 제목") |
| 50 | + .content("리뷰 내용") |
| 51 | + .imgUrl("") |
| 52 | + .build(); |
| 53 | + reviewRepository.save(review); |
| 54 | + |
| 55 | + // when |
| 56 | + boolean result = reviewRepository.existsByVolunteerApplyId(volunteerApplyId); |
| 57 | + |
| 58 | + // then |
| 59 | + assertThat(result).isTrue(); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments