Skip to content

Commit

Permalink
Test: Controller - 유저 작성 리뷰 조회 테스트 코드 작성 (TAVE-balak#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyjyjy25 committed Feb 17, 2024
1 parent 440a333 commit dcecc17
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> 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<MyReviewDto> 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());
}
}

0 comments on commit dcecc17

Please sign in to comment.