From dcecc17a621ed4c744290e090307e0d95b54ce72 Mon Sep 17 00:00:00 2001 From: jyjyjy25 Date: Sun, 18 Feb 2024 03:11:58 +0900 Subject: [PATCH] =?UTF-8?q?Test:=20Controller=20-=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EB=A6=AC=EB=B7=B0=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20(#153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserControllerTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/java/tavebalak/OTTify/user/controller/UserControllerTest.java b/src/test/java/tavebalak/OTTify/user/controller/UserControllerTest.java index a19fa56..a83236a 100644 --- a/src/test/java/tavebalak/OTTify/user/controller/UserControllerTest.java +++ b/src/test/java/tavebalak/OTTify/user/controller/UserControllerTest.java @@ -1,5 +1,6 @@ package tavebalak.OTTify.user.controller; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -9,6 +10,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.google.gson.Gson; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -19,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; @@ -32,6 +35,7 @@ import tavebalak.OTTify.oauth.redis.RefreshTokenRepository; import tavebalak.OTTify.oauth.redis.RefreshTokenService; import tavebalak.OTTify.review.dto.UserReviewRatingListDTO; +import tavebalak.OTTify.review.dto.response.MyReviewDto; import tavebalak.OTTify.user.dto.Response.LikedProgramDTO; import tavebalak.OTTify.user.dto.Response.LikedProgramListDTO; import tavebalak.OTTify.user.dto.Response.UninterestedProgramDTO; @@ -213,4 +217,29 @@ public void update2stLikedGenre() throws Exception { .andExpect(jsonPath("$.data").isNotEmpty()) .andExpect(jsonPath("$.data", "성공적으로 2순위 장르가 업데이트 되었습니다.").exists()); } + + @Test + @DisplayName("유저는 작성한 리뷰 목록을 조회할 수 있다.") + public void findUserReviews() throws Exception { + // given + List reviewTagNames1 = new ArrayList<>(Arrays.asList("극장에서 또 보고 싶어요")); + MyReviewDto reviewDto1 = new MyReviewDto(6L, LocalDateTime.now(), "https://ottify-s3-bucket.s3.ap-northeast-2.amazonaws.com/profile-images/813f55bc-8900-49e3-8e6b-98cc85f2fa0d.jpg", + "닉네임1", "어벤져스: 인피니티 워", 3.5, reviewTagNames1, "액션 그 자체 난 아직도 이때가 그립다", 3); + + List reviewTagNames2 = new ArrayList<>(Arrays.asList("극장에서 또 보고 싶어요")); + MyReviewDto reviewDto2 = new MyReviewDto(7L, LocalDateTime.now(), "https://ottify-s3-bucket.s3.ap-northeast-2.amazonaws.com/profile-images/813f55bc-8900-49e3-8e6b-98cc85f2fa0d.jpg", + "닉네임2", "어벤져스", 4.5, reviewTagNames1, "그 시절 나는 슈퍼 hero 였다 ...", 3); + + List response = new ArrayList<>(Arrays.asList(reviewDto1, reviewDto2)); + + // when + when(userService.getMyReview(any(Pageable.class))).thenReturn(response); + + ResultActions result = mockMvc.perform(get(BASE_URL + "/reviews")); + + // then + result.andExpect(status().isOk()) + .andExpect(jsonPath("$.data").isNotEmpty()) + .andExpect(jsonPath("$.data", response).exists()); + } } \ No newline at end of file