Skip to content

Commit

Permalink
Feat: private 한줄요약 상세조회 API 테스트 구현 (#173)
Browse files Browse the repository at this point in the history
* #165 - refactor: private 게시글도 찾을 수 있는 메소드에 public 이 들어간 메소드명 변경

* #165 - test: private 한줄요약 상세조회 API 테스트 구현
  • Loading branch information
morenow98 authored Feb 20, 2024
1 parent e4c3ab4 commit f505706
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface ReviewRepositoryCustom {
Page<ReviewDto> findPublicReviewWithLikedByIsbn13(String isbn13, Long memberId, Long loginMemberId, Pageable pageable);

Optional<ReviewDetailDto> findPublicReviewDetailByReviewId(Long reviewId, Long memberId);
Optional<ReviewDetailDto> findReviewDetailByReviewId(Long reviewId, Long memberId);

Page<ReviewDto> findLikeReviewByMemberId(Long memberId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Page<ReviewDto> findPublicReviewWithLikedByIsbn13(String isbn13, Long mem
}

@Override
public Optional<ReviewDetailDto> findPublicReviewDetailByReviewId(Long reviewId, Long memberId) {
public Optional<ReviewDetailDto> findReviewDetailByReviewId(Long reviewId, Long memberId) {
return Optional.ofNullable(queryFactory
.select(
Projections.constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void updateReview(Long reviewId, ReviewUpdateRequest reviewUpdateRequest,

@Transactional(readOnly = true)
public ReviewDetailDto getReview(Long reviewId, Long memberId) {
return reviewRepository.findPublicReviewDetailByReviewId(reviewId, memberId)
return reviewRepository.findReviewDetailByReviewId(reviewId, memberId)
.orElseThrow(() -> new EntityNotFoundException("한줄요약을 찾을 수 없습니다."));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void givenPostIdWithLogin_whenGettingPrivatePost_thenReturnErrorResponse() throw
}

@Test
@DisplayName("로그인 안된 유저가 다른사람 private 게시글을 조회하면 에러를 반환한다.")
@DisplayName("로그인 안된 유저가 private 게시글을 조회하면 에러를 반환한다.")
void givenPostId_whenGettingPrivatePost_thenReturnErrorResponse() throws Exception {
//given

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,47 @@ void givenReviewIdWithLogin_whenGettingAnotherPersonReview_thenReviewResponse()
.andExpect(jsonPath("$.isMine").value(false));
}

@Test
@WithCustomMockUser
@DisplayName("로그인 된 유저가 본인의 private 게시글을 조회한다.")
void givenReviewIdWithLogin_whenGettingMyPrivateReview_thenReturnReviewResponse() throws Exception {
//given

//when & then
mockMvc.perform(get("/reviews/8")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.reviewStatus").value("PRIVATE"))
;
}

@Test
@WithCustomMockUser
@DisplayName("로그인 된 유저가 다른 사람 private 한줄요약을 조회하면 에러를 반환한다.")
void givenReviewIdWithLogin_whenGettingPrivateReview_thenReturnErrorResponse() throws Exception {
//given

//when & then
mockMvc.perform(get("/reviews/6")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound())
.andExpect(jsonPath("$.message").value("한줄요약을 찾을 수 없습니다."))
;
}

@Test
@DisplayName("로그인 안된 유저가 private 한줄요약을 조회하면 에러를 반환한다.")
void givenReviewId_whenGettingPrivateReview_thenReturnErrorResponse() throws Exception {
//given

//when & then
mockMvc.perform(get("/reviews/8")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound())
.andExpect(jsonPath("$.message").value("한줄요약을 찾을 수 없습니다."))
;
}

@Test
@DisplayName("없는 한줄요약 id로 조회하면 에러를 반환한다.")
void givenNonExistedReviewId_whenGettingReview_thenErrorResponse() throws Exception {
Expand Down Expand Up @@ -286,7 +327,7 @@ void givenNothing_whenSearchingReview_thenReturnReviewListResponse() throws Exce
mockMvc.perform(get("/reviews/all")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.totalResults").value(7))
.andExpect(jsonPath("$.totalResults").value(6))
;
}

Expand Down Expand Up @@ -356,7 +397,7 @@ void givenMemberIdWithLogin_whenSearchingReview_thenReturnReviewListResponse() t
.param("member-id", String.valueOf(memberId))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.totalResults").value(5))
.andExpect(jsonPath("$.totalResults").value(4))
.andExpect(jsonPath("$.reviewList[0].liked").value(true))
;
}
Expand All @@ -371,7 +412,7 @@ void givenMemberId_whenSearchingReview_thenReturnReviewListResponse() throws Exc
mockMvc.perform(get("/reviews")
.param("member-id", String.valueOf(memberId))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.totalResults").value(5))
.andExpect(jsonPath("$.totalResults").value(4))
.andExpect(jsonPath("$.reviewList[0].liked").value(false))
;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ VALUES (1, 1, 'reviewContent', 'PUBLIC', 2, 0, false, TIMESTAMP '2024-02-15 00:0
(2, 1, 'rContent', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-13 00:00:00', CURRENT_TIMESTAMP),
(2, 1, 'rContent2', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP),
(2, 2, 'rContent3', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP),
(2, 2, 'reContent2', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP),
(2, 2, 'reContent2', 'PRIVATE', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP),
(1, 2, 'rContent', 'PUBLIC', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP),
(1, 2, 'rContent', 'PRIVATE', 0, 0, false, TIMESTAMP '2024-02-12 00:00:00', CURRENT_TIMESTAMP);

Expand Down

0 comments on commit f505706

Please sign in to comment.