|
12 | 12 | import com.backend.domain.review.entity.Review; |
13 | 13 | import com.backend.domain.review.repository.ReviewRepository; |
14 | 14 | import com.backend.global.elasticsearch.TestElasticsearchConfiguration; |
15 | | -import com.backend.global.redis.TestRedisConfiguration; |
16 | 15 | import com.backend.global.security.JwtUtil; |
17 | 16 | import com.fasterxml.jackson.databind.ObjectMapper; |
18 | 17 | import org.junit.jupiter.api.BeforeEach; |
|
39 | 38 | @SpringBootTest |
40 | 39 | @AutoConfigureMockMvc |
41 | 40 | @ActiveProfiles("test") |
42 | | -@Import({TestElasticsearchConfiguration.class, TestRedisConfiguration.class}) |
| 41 | +@Import({TestElasticsearchConfiguration.class, com.backend.global.redis.TestRedisConfig.class, com.backend.global.config.TestRedissonConfig.class}) |
43 | 42 | @Transactional |
44 | 43 | class ApiV1ReviewControllerTest { |
45 | 44 |
|
@@ -107,7 +106,7 @@ void createReview_Success() throws Exception { |
107 | 106 | .andExpect(jsonPath("$.data.isSatisfied").value(true)); |
108 | 107 |
|
109 | 108 | // DB 검증 |
110 | | - Review review = reviewRepository.findByProductId(testProduct.getId()).orElseThrow(); |
| 109 | + Review review = reviewRepository.findAllByProductId(testProduct.getId()).get(0); |
111 | 110 | assertThat(review.getComment()).isEqualTo("Great product!"); |
112 | 111 | assertThat(review.getReviewer().getId()).isEqualTo(testUser.getId()); |
113 | 112 | } |
@@ -137,6 +136,36 @@ void getReview_Success() throws Exception { |
137 | 136 | .andExpect(jsonPath("$.data.reviewerNickname").value(testUser.getNickname())); |
138 | 137 | } |
139 | 138 |
|
| 139 | + @Test |
| 140 | + @DisplayName("상품 ID로 리뷰 목록 조회 성공") |
| 141 | + void getReviewsByProductId_Success() throws Exception { |
| 142 | + // Given |
| 143 | + reviewRepository.save(Review.builder() |
| 144 | + .reviewer(testUser) |
| 145 | + .product(testProduct) |
| 146 | + .comment("First review") |
| 147 | + .isSatisfied(true) |
| 148 | + .build()); |
| 149 | + |
| 150 | + reviewRepository.save(Review.builder() |
| 151 | + .reviewer(anotherUser) |
| 152 | + .product(testProduct) |
| 153 | + .comment("Second review") |
| 154 | + .isSatisfied(false) |
| 155 | + .build()); |
| 156 | + |
| 157 | + // When & Then |
| 158 | + mockMvc.perform(get("/api/v1/reviews/products/{productId}", testProduct.getId()) |
| 159 | + .header("Authorization", "Bearer " + testUserToken)) |
| 160 | + .andDo(print()) |
| 161 | + .andExpect(status().isOk()) |
| 162 | + .andExpect(jsonPath("$.resultCode").value("200")) |
| 163 | + .andExpect(jsonPath("$.data").isArray()) |
| 164 | + .andExpect(jsonPath("$.data.length()").value(2)) |
| 165 | + .andExpect(jsonPath("$.data[0].comment").value("First review")) |
| 166 | + .andExpect(jsonPath("$.data[1].comment").value("Second review")); |
| 167 | + } |
| 168 | + |
140 | 169 | @Test |
141 | 170 | @DisplayName("리뷰 수정 성공") |
142 | 171 | void updateReview_Success() throws Exception { |
|
0 commit comments