Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #231 mypage 반환 테스트해요 #236

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -762,4 +762,4 @@

## 📱 사용 예시

> 실제 유저 사용 페이지 흐름 보여주기 ( 영상 x )
> 실제 유저 사용 페이지 흐름 보여주기 ( 영상 x )
Original file line number Diff line number Diff line change
@@ -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<FavoriteInfluencer> favoriteInfluencersPage = new PageImpl<>(
List.of(favoriteInfluencer1));

given(favoriteRepository.findByUserIdAndIsLikedTrue(userId, pageable))
.willReturn(favoriteInfluencersPage);

Page<InfluencerInfo> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<LikedPlace> likedPlacePage = new PageImpl<>(List.of(likedPlace));

given(likedPlaceRepository.findByUserIdAndIsLikedTrueWithPlace(userId, pageable))
.willReturn(likedPlacePage);
given(videoRepository.findByPlaceIdInWithInfluencer(anyList()))
.willReturn(List.of(video1));

Page<LikedPlaceInfo> 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());
}
}
73 changes: 46 additions & 27 deletions src/test/java/team7/inplace/review/ReviewServiceTest.java
Original file line number Diff line number Diff line change
@@ -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<ReviewInfo> 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<ReviewInfo> 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<Review> reviewPage = new PageImpl<>(List.of(myReview));

given(reviewRepository.findByUserIdWithPlace(userId, pageable)).willReturn(
reviewPage);

Page<MyReviewInfo> 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());
}
}