Skip to content

Commit

Permalink
Merge pull request #235 from kakao-tech-campus-2nd-step3/fix/#129-vid…
Browse files Browse the repository at this point in the history
…eoTestFix

[Fix] 비디오 테스트 문제 해결해요
  • Loading branch information
suhyeon7497 authored Nov 15, 2024
2 parents eb6da8a + 4703192 commit 3879e36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team7.inplace.video.application;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -12,9 +13,14 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import team7.inplace.influencer.domain.Influencer;
import team7.inplace.place.domain.Place;
import team7.inplace.place.persistence.PlaceRepository;
import team7.inplace.security.application.dto.CustomOAuth2User;
import team7.inplace.user.domain.Role;
import team7.inplace.util.TestUtil;
import team7.inplace.video.application.dto.VideoInfo;
import team7.inplace.video.domain.Video;
Expand All @@ -38,10 +44,16 @@ public class VideoServiceTest {
@InjectMocks
private VideoService videoService;

@AfterEach
void tearDown() {
SecurityContextHolder.clearContext();
}

@Test
@DisplayName("getVideosBySurround Test")
void test1() {
// given
setUser();
// 매개변수
VideoSearchParams videoSearchParams = new VideoSearchParams(
"10.0",
Expand Down Expand Up @@ -296,4 +308,11 @@ void test5() {
Assertions.assertThat(videoInfos.get(0).videoId()).isEqualTo(2L);
Assertions.assertThat(videoInfos.get(1).videoId()).isEqualTo(1L);
}

private void setUser() {
CustomOAuth2User customOAuth2User = new CustomOAuth2User("test", 1L, Role.USER.getRoles());
Authentication authentication = new UsernamePasswordAuthenticationToken(customOAuth2User,
null);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ void test1() {
);
// then
Assertions.assertThat(savedVideos.size()).isEqualTo(5);
Long count = 1L;
Long count = 5L;
for (Video savedVideo : savedVideos) {
Assertions.assertThat(savedVideo.getId()).isEqualTo(count);
count = count + 1L;
count = count - 1L;
}
}

Expand All @@ -148,10 +148,10 @@ void test1_1() {
);
// then
Assertions.assertThat(savedVideos.size()).isEqualTo(10);
Long count = 1L;
Long count = 11L;
for (Video savedVideo : savedVideos) {
Assertions.assertThat(savedVideo.getId()).isEqualTo(count);
count = count + 1L;
count = count - 1L;
}
}

Expand Down Expand Up @@ -283,6 +283,12 @@ void test7() {
// given

// when
for (int i = 1; i <= 11; i++) {
Video video = videoRepository.findById((long) i)
.orElseThrow(() -> InplaceException.of(VideoErrorCode.NOT_FOUND));
video.updateViewCount(1L);
}

for (int i = 1; i <= 11; i++) {
Video video = videoRepository.findById((long) i)
.orElseThrow(() -> InplaceException.of(VideoErrorCode.NOT_FOUND));
Expand Down

0 comments on commit 3879e36

Please sign in to comment.