forked from TAVE-balak/OTTify-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Controller - 유저 구독 중인 OTT 조회 테스트 코드 작성 (TAVE-balak#153)
- Loading branch information
Showing
1 changed file
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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()); | ||
|
||
} | ||
} |