diff --git a/README.md b/README.md index ba167386..f0e5501c 100644 --- a/README.md +++ b/README.md @@ -762,4 +762,4 @@ ## ๐Ÿ“ฑ ์‚ฌ์šฉ ์˜ˆ์‹œ -> ์‹ค์ œ ์œ ์ € ์‚ฌ์šฉ ํŽ˜์ด์ง€ ํ๋ฆ„ ๋ณด์—ฌ์ฃผ๊ธฐ ( ์˜์ƒ x ) +> ์‹ค์ œ ์œ ์ € ์‚ฌ์šฉ ํŽ˜์ด์ง€ ํ๋ฆ„ ๋ณด์—ฌ์ฃผ๊ธฐ ( ์˜์ƒ x ) \ No newline at end of file diff --git a/src/test/java/team7/inplace/favoriteInfluencer/FavoriteInfluencerServiceTest.java b/src/test/java/team7/inplace/favoriteInfluencer/FavoriteInfluencerServiceTest.java new file mode 100644 index 00000000..094ab7a6 --- /dev/null +++ b/src/test/java/team7/inplace/favoriteInfluencer/FavoriteInfluencerServiceTest.java @@ -0,0 +1,58 @@ +package team7.inplace.favoriteInfluencer; + + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import team7.inplace.favoriteInfluencer.application.FavoriteInfluencerService; +import team7.inplace.favoriteInfluencer.domain.FavoriteInfluencer; +import team7.inplace.favoriteInfluencer.persistent.FavoriteInfluencerRepository; +import team7.inplace.influencer.application.dto.InfluencerInfo; +import team7.inplace.influencer.domain.Influencer; +import team7.inplace.user.domain.Role; +import team7.inplace.user.domain.User; +import team7.inplace.user.domain.UserType; + +@ExtendWith(MockitoExtension.class) +public class FavoriteInfluencerServiceTest { + + @Mock + private FavoriteInfluencerRepository favoriteRepository; + + @InjectMocks + private FavoriteInfluencerService favoriteInfluencerService; + + @Test + void getFavoriteInfluencers() { + Pageable pageable = PageRequest.of(0, 10); + Long userId = 1L; + User user = new User("name", "password", "nickname", UserType.KAKAO, Role.USER); + Influencer influencer1 = new Influencer("influencer1", "imgUrl1", "job1"); + FavoriteInfluencer favoriteInfluencer1 = new FavoriteInfluencer(user, influencer1); + favoriteInfluencer1.updateLike(true); + Page favoriteInfluencersPage = new PageImpl<>( + List.of(favoriteInfluencer1)); + + given(favoriteRepository.findByUserIdAndIsLikedTrue(userId, pageable)) + .willReturn(favoriteInfluencersPage); + + Page result = favoriteInfluencerService.getFavoriteInfluencers(userId, + pageable); + + verify(favoriteRepository).findByUserIdAndIsLikedTrue(userId, pageable); + assertThat(result.getContent().get(0)).isInstanceOf(InfluencerInfo.class); + assertThat(result.getContent().get(0).influencerName()).isEqualTo(influencer1.getName()); + assertThat(result.getContent().get(0).likes()).isEqualTo(true); + } +} diff --git a/src/test/java/team7/inplace/place/application/PlaceServiceTest.java b/src/test/java/team7/inplace/place/application/PlaceServiceTest.java index ae628dd8..95db60e9 100644 --- a/src/test/java/team7/inplace/place/application/PlaceServiceTest.java +++ b/src/test/java/team7/inplace/place/application/PlaceServiceTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mockStatic; @@ -13,6 +14,7 @@ import java.lang.reflect.Field; import java.time.LocalDateTime; import java.util.Arrays; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -33,6 +35,7 @@ import team7.inplace.place.application.command.PlaceLikeCommand; import team7.inplace.place.application.command.PlacesCommand.PlacesCoordinateCommand; import team7.inplace.place.application.command.PlacesCommand.PlacesFilterParamsCommand; +import team7.inplace.place.application.dto.LikedPlaceInfo; import team7.inplace.place.application.dto.PlaceDetailInfo; import team7.inplace.place.application.dto.PlaceInfo; import team7.inplace.place.domain.Category; @@ -664,4 +667,24 @@ public void likedTest2() { .isLiked()) .isFalse(); } + + @Test + void getLikedPlaceInfoTest() { + Pageable pageable = PageRequest.of(0, 10); + Long userId = 1L; + LikedPlace likedPlace = new LikedPlace(user1, place1); + + Page likedPlacePage = new PageImpl<>(List.of(likedPlace)); + + given(likedPlaceRepository.findByUserIdAndIsLikedTrueWithPlace(userId, pageable)) + .willReturn(likedPlacePage); + given(videoRepository.findByPlaceIdInWithInfluencer(anyList())) + .willReturn(List.of(video1)); + + Page result = placeService.getLikedPlaceInfo(userId, pageable); + + verify(likedPlaceRepository).findByUserIdAndIsLikedTrueWithPlace(userId, pageable); + assertThat(result.getContent().get(0)).isInstanceOf(LikedPlaceInfo.class); + assertThat(result.getContent().get(0).influencerName()).isEqualTo(influencer1.getName()); + } } diff --git a/src/test/java/team7/inplace/review/ReviewServiceTest.java b/src/test/java/team7/inplace/review/ReviewServiceTest.java index b662624b..93c97d72 100644 --- a/src/test/java/team7/inplace/review/ReviewServiceTest.java +++ b/src/test/java/team7/inplace/review/ReviewServiceTest.java @@ -1,5 +1,18 @@ package team7.inplace.review; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.verify; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -17,6 +30,7 @@ import team7.inplace.place.domain.Place; import team7.inplace.place.persistence.PlaceRepository; import team7.inplace.review.application.ReviewService; +import team7.inplace.review.application.dto.MyReviewInfo; import team7.inplace.review.application.dto.ReviewCommand; import team7.inplace.review.application.dto.ReviewInfo; import team7.inplace.review.domain.Review; @@ -28,18 +42,6 @@ import team7.inplace.user.domain.UserType; import team7.inplace.user.persistence.UserRepository; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) public class ReviewServiceTest { @@ -75,13 +77,13 @@ void setUp() { user = new User("name", "password", "nickname", UserType.KAKAO, Role.USER); place = new Place("name", "facility", "menuImgUrl", "category", - "Address 1|Address 2|Address 3", "x", "y", - Arrays.asList("ํ•œ๊ธ€๋‚ |์ˆ˜|N", "ํฌ๋ฆฌ์Šค๋งˆ์Šค|์ˆ˜|Y"), - Arrays.asList("์˜คํ”ˆ ์‹œ๊ฐ„|9:00 AM|์›”", "๋‹ซ๋Š” ์‹œ๊ฐ„|6:00 PM|์›”"), - Arrays.asList("์‚ผ๊ฒน์‚ด|5000|false|menu.url|description", - "๋ผ์ง€์ฐŒ๊ฐœ|7000|true|menu.url|description"), - LocalDateTime.of(2024, 3, 28, 5, 30), - Arrays.asList("menuBoard1.url", "menuBoard2.url") + "Address 1|Address 2|Address 3", "x", "y", + Arrays.asList("ํ•œ๊ธ€๋‚ |์ˆ˜|N", "ํฌ๋ฆฌ์Šค๋งˆ์Šค|์ˆ˜|Y"), + Arrays.asList("์˜คํ”ˆ ์‹œ๊ฐ„|9:00 AM|์›”", "๋‹ซ๋Š” ์‹œ๊ฐ„|6:00 PM|์›”"), + Arrays.asList("์‚ผ๊ฒน์‚ด|5000|false|menu.url|description", + "๋ผ์ง€์ฐŒ๊ฐœ|7000|true|menu.url|description"), + LocalDateTime.of(2024, 3, 28, 5, 30), + Arrays.asList("menuBoard1.url", "menuBoard2.url") ); command = new ReviewCommand(isLiked, comment); @@ -118,8 +120,8 @@ void createReviewTest_ReviewAlreadyExists() { given(reviewRepository.existsByUserIdAndPlaceId(userId, placeId)).willReturn(true); assertThatThrownBy(() -> reviewService.createReview(placeId, command)) - .isInstanceOf(InplaceException.class) - .hasMessage(ReviewErrorCode.REVIEW_ALREADY_EXISTS.getMessage()); + .isInstanceOf(InplaceException.class) + .hasMessage(ReviewErrorCode.REVIEW_ALREADY_EXISTS.getMessage()); authorizationUtil.close(); } @@ -140,8 +142,8 @@ void getReviews_LoggedIn() { Page result = reviewService.getReviews(placeId, pageable); assertThat(result.getContent().get(0)) - .extracting("comment", "mine") - .containsExactly(comment, true); + .extracting("comment", "mine") + .containsExactly(comment, true); authorizationUtil.close(); } @@ -160,8 +162,8 @@ void getReviews_NotLoggedIn() { Page result = reviewService.getReviews(placeId, pageable); assertThat(result.getContent().get(0)) - .extracting("comment", "mine") - .containsExactly(comment, false); + .extracting("comment", "mine") + .containsExactly(comment, false); authorizationUtil.close(); } @@ -181,9 +183,26 @@ void deleteReview_NotOwner() { given(userMock.getId()).willReturn(1L); // ๋ฆฌ๋ทฐ์˜ userId๊ฐ€ 1L assertThatThrownBy(() -> reviewService.deleteReview(reviewId)) - .isInstanceOf(InplaceException.class) - .hasMessage(ReviewErrorCode.NOT_OWNER.getMessage()); + .isInstanceOf(InplaceException.class) + .hasMessage(ReviewErrorCode.NOT_OWNER.getMessage()); authorizationUtil.close(); } + + @Test + void getMyReviewsTest() { + Pageable pageable = PageRequest.of(0, 10); + Review myReview = new Review(user, place, isLiked, comment); + Page reviewPage = new PageImpl<>(List.of(myReview)); + + given(reviewRepository.findByUserIdWithPlace(userId, pageable)).willReturn( + reviewPage); + + Page result = reviewService.getMyReviews(userId, pageable); + + verify(reviewRepository).findByUserIdWithPlace(userId, pageable); + assertThat(result.getContent().get(0)).isInstanceOf(MyReviewInfo.class); + assertThat(result.getContent().get(0).comment()).isEqualTo(myReview.getComment()); + assertThat(result.getContent().get(0).placeInfo().placeName()).isEqualTo(place.getName()); + } }