Skip to content

Commit

Permalink
[DVK-125] fix: 리뷰 목록 조회 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeSM0518 committed Nov 28, 2024
1 parent fec3cd2 commit 35bc25a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ data class ReviewView(
val writtenDate: Instant,
@Schema(description = "수정 날짜")
val modifiedDate: Instant,
@Schema(description = "리뷰 댓글 개수")
val commentCount: Int
) {
companion object {
fun ReviewRow.toReviewView(): ReviewView =
Expand All @@ -33,6 +35,7 @@ data class ReviewView(
writer = this.toWriterView(),
writtenDate = this.writtenDate,
modifiedDate = this.modifiedDate,
commentCount = this.commentCount
)

fun Review.toReviewView(writer: Member): ReviewView =
Expand All @@ -44,6 +47,7 @@ data class ReviewView(
writer = writer.toWriterView(),
writtenDate = this.writtenDate,
modifiedDate = this.modifiedDate,
commentCount = 0
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,52 @@ internal class ReviewCommentControllerTest @Autowired constructor(
assertThat(notification.note["commenterName"]).isEqualTo(expectedMember2.nickname)
}

@Test
fun `리뷰 댓글을 작성후 리뷰 조회시 증가된 개수를 조회할 수 있다`(): Unit = runBlocking {
val review = postCreateReview()
val accessToken = tokenService.createTokenGroup(expectedMember2).accessToken
val request = CreateReviewCommentRequest(review.id, review.content)

val reviewComment = webTestClient
.post()
.uri("/api/v1/review-comments")
.accept(APPLICATION_JSON)
.contentType(APPLICATION_JSON)
.header(AUTHORIZATION, "Bearer $accessToken")
.bodyValue(request)
.exchange()
.expectStatus().isOk
.expectBody<CreateReviewCommentResponse>()
.returnResult()
.responseBody!!
.reviewComment

assertThat(reviewComment.reviewId).isEqualTo(request.reviewId)
assertThat(reviewComment.content).isEqualTo(request.content)

delay(100)
val notification = notificationRepository.findAll().toList()
.find { it.receiverId == review.writer.memberId }!!
assertThat(notification.type).isEqualTo(NotificationType.REVIEW_COMMENT)
assertThat(notification.receiverId).isEqualTo(review.writer.memberId)
assertThat(notification.note["ebookId"]).isEqualTo(review.ebookId.toString())
assertThat(notification.note["reviewId"]).isEqualTo(review.id.toString())
assertThat(notification.note["receiverId"]).isEqualTo(review.writer.memberId.toString())
assertThat(notification.note["commenterName"]).isEqualTo(expectedMember2.nickname)

val getReviewsResponse = webTestClient
.get()
.uri("/api/v1/reviews?page=1&count=10&ebookId=${review.ebookId}")
.accept(APPLICATION_JSON)
.exchange()
.expectStatus().isOk
.expectBody<PageResponse<ReviewView>>()
.returnResult()
.responseBody!!

assertThat(getReviewsResponse.data[0].commentCount).isOne()
}

@Test
fun `리뷰 댓글 작성시 리뷰가 존재하지 않을 경우 예외가 발생한다`(): Unit = runBlocking {
val review = postCreateReview()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ internal class ReviewControllerTest @Autowired constructor(
assertThat(review.writer).isEqualTo(createReviewResponse.writer)
assertThat(review.writtenDate.toEpochMilli()).isEqualTo(createReviewResponse.writtenDate.toEpochMilli())
assertThat(review.modifiedDate.toEpochMilli()).isEqualTo(createReviewResponse.modifiedDate.toEpochMilli())
assertThat(review.commentCount).isZero()
}

@Test
Expand Down

0 comments on commit 35bc25a

Please sign in to comment.