-
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.
- Loading branch information
1 parent
3db47b7
commit 1b17d04
Showing
9 changed files
with
477 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ public record ReviewUpdateRequest( | |
String contents, | ||
@NotNull | ||
Score score, | ||
|
||
List<MultipartFile> files | ||
) { | ||
} |
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
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
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
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
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
89 changes: 89 additions & 0 deletions
89
...t/java/com/inq/wishhair/wesharewishhair/review/presentation/LikeReviewControllerTest.java
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.inq.wishhair.wesharewishhair.review.presentation; | ||
|
||
import static com.inq.wishhair.wesharewishhair.common.fixture.AuthFixture.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import com.inq.wishhair.wesharewishhair.common.config.EmbeddedRedisConfig; | ||
import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport; | ||
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReview; | ||
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReviewRepository; | ||
import com.inq.wishhair.wesharewishhair.user.domain.entity.User; | ||
|
||
@DisplayName("[LikeReview API 테스트]") | ||
@Import(EmbeddedRedisConfig.class) | ||
class LikeReviewControllerTest extends ApiTestSupport { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@Autowired | ||
private LikeReviewRepository likeReviewRepository; | ||
|
||
@Test | ||
@DisplayName("[좋아요 실행 API 를 호출한다]") | ||
void executeLike() throws Exception { | ||
//given | ||
User user = saveUser(); | ||
|
||
//when | ||
ResultActions actual = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.post("/api/reviews/like/1") | ||
.header(AUTHORIZATION, BEARER + getAccessToken(user.getId())) | ||
); | ||
|
||
//then | ||
actual.andExpect(status().isOk()); | ||
boolean userExist = likeReviewRepository.existsByUserIdAndReviewId(user.getId(), 1L); | ||
assertThat(userExist).isTrue(); | ||
} | ||
|
||
@Test | ||
@DisplayName("[좋아요 취소 API 를 호출한다]") | ||
void cancelLike() throws Exception { | ||
//given | ||
User user = saveUser(); | ||
likeReviewRepository.save(LikeReview.addLike(user.getId(), 2L)); | ||
|
||
//when | ||
ResultActions actual = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.delete("/api/reviews/like/2") | ||
.header(AUTHORIZATION, BEARER + getAccessToken(user.getId())) | ||
); | ||
|
||
//then | ||
actual.andExpect(status().isOk()); | ||
boolean userExist = likeReviewRepository.existsByUserIdAndReviewId(user.getId(), 2L); | ||
assertThat(userExist).isFalse(); | ||
} | ||
|
||
@Test | ||
@DisplayName("[좋아요 상태 확인 API 를 호출한다]") | ||
void checkIsLiking() throws Exception { | ||
//given | ||
User user = saveUser(); | ||
likeReviewRepository.save(LikeReview.addLike(user.getId(), 3L)); | ||
|
||
//when | ||
ResultActions actual = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.get("/api/reviews/like/3") | ||
.header(AUTHORIZATION, BEARER + getAccessToken(user.getId())) | ||
); | ||
|
||
//then | ||
actual.andExpectAll( | ||
status().isOk(), | ||
jsonPath("$.isLiking").value(true) | ||
); | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
src/test/java/com/inq/wishhair/wesharewishhair/review/presentation/ReviewApiTest.java
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 |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package com.inq.wishhair.wesharewishhair.review.presentation; | ||
|
||
import static com.inq.wishhair.wesharewishhair.common.fixture.AuthFixture.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.mock.web.MockMultipartFile; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
|
||
import com.inq.wishhair.wesharewishhair.common.support.ApiTestSupport; | ||
import com.inq.wishhair.wesharewishhair.hairstyle.domain.HairStyle; | ||
import com.inq.wishhair.wesharewishhair.hairstyle.domain.HairStyleRepository; | ||
import com.inq.wishhair.wesharewishhair.hairstyle.fixture.HairStyleFixture; | ||
import com.inq.wishhair.wesharewishhair.photo.domain.PhotoStore; | ||
import com.inq.wishhair.wesharewishhair.review.application.dto.request.ReviewCreateRequest; | ||
import com.inq.wishhair.wesharewishhair.review.application.dto.request.ReviewUpdateRequest; | ||
import com.inq.wishhair.wesharewishhair.review.domain.ReviewRepository; | ||
import com.inq.wishhair.wesharewishhair.review.domain.entity.Review; | ||
import com.inq.wishhair.wesharewishhair.review.fixture.ReviewFixture; | ||
import com.inq.wishhair.wesharewishhair.review.infrastructure.ReviewJpaRepository; | ||
import com.inq.wishhair.wesharewishhair.user.domain.entity.User; | ||
|
||
@DisplayName("[Review API 테스트]") | ||
class ReviewApiTest extends ApiTestSupport { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@Autowired | ||
private ReviewRepository reviewRepository; | ||
@Autowired | ||
private ReviewJpaRepository reviewJpaRepository; | ||
@Autowired | ||
private HairStyleRepository hairStyleRepository; | ||
|
||
@MockBean | ||
private PhotoStore photoStore; | ||
|
||
private Review saveReview(User user) { | ||
HairStyle hairStyle = HairStyleFixture.getWomanHairStyle(); | ||
hairStyleRepository.save(hairStyle); | ||
|
||
Review review = ReviewFixture.getReview(hairStyle, user); | ||
reviewRepository.save(review); | ||
return review; | ||
} | ||
|
||
@Test | ||
@DisplayName("[리뷰 생성 API 를 호출한다]") | ||
void createReview() throws Exception { | ||
//given | ||
User user = saveUser(); | ||
|
||
HairStyle hairStyle = HairStyleFixture.getWomanHairStyle(); | ||
hairStyleRepository.save(hairStyle); | ||
|
||
given(photoStore.uploadFiles(anyList())) | ||
.willReturn(List.of("url1")); | ||
|
||
ReviewCreateRequest request = ReviewFixture.getReviewCreateRequest(hairStyle.getId()); | ||
|
||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("contents", request.contents()); | ||
params.add("score", String.valueOf(request.score())); | ||
params.add("hairStyleId", String.valueOf(request.hairStyleId())); | ||
|
||
//when | ||
ResultActions actual = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.multipart(HttpMethod.POST, "/api/reviews") | ||
.file((MockMultipartFile)request.files().get(0)) | ||
.header(AUTHORIZATION, BEARER + getAccessToken(user.getId())) | ||
.params(params) | ||
); | ||
|
||
//then | ||
actual.andExpect(status().isCreated()); | ||
assertThat(reviewJpaRepository.findAll()).hasSize(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("[리뷰 삭제 API 를 호출한다]") | ||
void deleteReview() throws Exception { | ||
//given | ||
given(photoStore.deleteFiles(anyList())).willReturn(true); | ||
given(photoStore.uploadFiles(anyList())).willReturn(List.of("url1")); | ||
|
||
User user = saveUser(); | ||
Review review = saveReview(user); | ||
|
||
//when | ||
ResultActions actual = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.delete("/api/reviews/" + review.getId()) | ||
.header(AUTHORIZATION, BEARER + getAccessToken(user.getId())) | ||
); | ||
|
||
//then | ||
actual.andExpect(status().isOk()); | ||
assertThat(reviewRepository.findById(review.getId())).isNotPresent(); | ||
} | ||
|
||
@Test | ||
@DisplayName("[리뷰 수정 API 를 호출한다]") | ||
void updateReview() throws Exception { | ||
//given | ||
given(photoStore.uploadFiles(anyList())).willReturn(List.of("url1")); | ||
|
||
User user = saveUser(); | ||
Review review = saveReview(user); | ||
|
||
ReviewUpdateRequest request = ReviewFixture.getReviewUpdateRequest(review.getId()); | ||
|
||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("contents", request.contents()); | ||
params.add("score", String.valueOf(request.score())); | ||
params.add("reviewId", String.valueOf(request.reviewId())); | ||
|
||
//when | ||
ResultActions actual = mockMvc.perform( | ||
MockMvcRequestBuilders | ||
.multipart(HttpMethod.PATCH, "/api/reviews") | ||
.file((MockMultipartFile)request.files().get(0)) | ||
.header(AUTHORIZATION, BEARER + getAccessToken(user.getId())) | ||
.params(params) | ||
); | ||
|
||
//then | ||
actual.andExpect(status().isOk()); | ||
Review findReview = reviewRepository.findById(review.getId()).orElseThrow(); | ||
assertAll( | ||
() -> assertThat(findReview.getScore()).isEqualTo(request.score()), | ||
() -> assertThat(findReview.getContentsValue()).isEqualTo(request.contents()), | ||
() -> assertThat(findReview.getPhotos().get(0).getStoreUrl()).isEqualTo("url1") | ||
); | ||
} | ||
} |
Oops, something went wrong.