Skip to content

Commit

Permalink
Test: Controller - 유저 구독 중인 OTT 조회 테스트 코드 작성 (TAVE-balak#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyjyjy25 committed Feb 14, 2024
1 parent ce6fcea commit 45ec3ee
Showing 1 changed file with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.ArrayList;
Expand All @@ -12,9 +13,9 @@
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import tavebalak.OTTify.common.constant.GradeType;
import tavebalak.OTTify.genre.dto.GenreDTO;
import tavebalak.OTTify.oauth.jwt.JwtService;
Expand Down Expand Up @@ -78,17 +79,39 @@ public void findUserProfile() throws Exception {
UninterestedProgramDTO uninterestedProgramDto1 = new UninterestedProgramDTO(5L, "/1uHRkB2Q00Y4i7I7KNd0jGi4OmY.jpg");
UninterestedProgramListDTO uninterestedProgram = new UninterestedProgramListDTO(1, new ArrayList<>(Arrays.asList(uninterestedProgramDto1)));

UserProfileDTO responseDto = new UserProfileDTO("https://ottify-s3-bucket.s3.ap-northeast-2.amazonaws.com/profile-images/813f55bc-8900-49e3-8e6b-98cc85f2fa0d.jpg",
UserProfileDTO response = new UserProfileDTO("https://ottify-s3-bucket.s3.ap-northeast-2.amazonaws.com/profile-images/813f55bc-8900-49e3-8e6b-98cc85f2fa0d.jpg",
"닉네임1", GradeType.GENERAL, "[email protected]", 3.99, reviewRatingListDto, genreDto1, new ArrayList<>(Arrays.asList(genreDto2, genreDto3)), ottListDto, likedProgram, uninterestedProgram);

// when
when(userService.getUserProfile()).thenReturn(responseDto);
when(userService.getUserProfile()).thenReturn(response);

ResultActions result = mockMvc.perform(get(BASE_URL));

// then
mockMvc.perform(get(BASE_URL)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
result.andExpect(status().isOk())
.andExpect(jsonPath("$.data").isNotEmpty())
.andExpect(jsonPath("$.data", response).exists());

}

@Test
@DisplayName("유저는 자신이 구독 중인 OTT를 조회할 수 있다.")
public void findUserOTT() throws Exception {
// given
UserOttDTO ottDto1 = new UserOttDTO(3L, "쿠팡플레이", "https://ottify-s3-bucket.s3.ap-northeast-2.amazonaws.com/ott/provider/coupang_play.png");
UserOttDTO ottDto2 = new UserOttDTO(11L, "U+ TV", "https://ottify-s3-bucket.s3.ap-northeast-2.amazonaws.com/ott/provider/ue%2B_tv.png");

UserOttListDTO response = new UserOttListDTO(2, new ArrayList<>(Arrays.asList(ottDto1, ottDto2)));

// when
when(userService.getUserOTT()).thenReturn(response);

ResultActions result = mockMvc.perform(get(BASE_URL + "/otts"));

// then
result.andExpect(status().isOk())
.andExpect(jsonPath("$.data").isNotEmpty())
.andExpect(jsonPath("$.data", response).exists());

}
}

0 comments on commit 45ec3ee

Please sign in to comment.