-
Notifications
You must be signed in to change notification settings - Fork 2
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
[BE] feat: 받은 리뷰 요약 조회 API 구현 #796
Changes from 1 commit
95be71e
73f587d
530cebb
3231afa
cc6e147
8b0742c
6533eb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,95 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package reviewme.review.service; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import static org.assertj.core.api.Assertions.assertThat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import static org.junit.jupiter.api.Assertions.assertAll; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import static reviewme.fixture.QuestionFixture.서술형_필수_질문; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import static reviewme.fixture.SectionFixture.항상_보이는_섹션; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import static reviewme.fixture.TemplateFixture.템플릿; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.junit.jupiter.api.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.beans.factory.annotation.Autowired; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.question.domain.Question; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.question.repository.QuestionRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.review.domain.Review; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.review.repository.ReviewRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.review.service.dto.response.list.ReceivedReviewsSummaryResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.review.service.exception.ReviewGroupNotFoundByReviewRequestCodeException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.reviewgroup.domain.ReviewGroup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.reviewgroup.repository.ReviewGroupRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.support.ServiceTest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.template.domain.Section; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.template.domain.Template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.template.repository.SectionRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import reviewme.template.repository.TemplateRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@ServiceTest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class ReviewSummaryServiceTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private ReviewSummaryService reviewSummaryService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private ReviewGroupRepository reviewGroupRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private ReviewRepository reviewRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private TemplateRepository templateRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private SectionRepository sectionRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private QuestionRepository questionRepository; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void 리뷰_그룹에_등록된_리뷰_요약_정보를_반환한다() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Question question = questionRepository.save(서술형_필수_질문()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Section section = sectionRepository.save(항상_보이는_섹션(List.of(question.getId()))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Template template = templateRepository.save(템플릿(List.of(section.getId()))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ReviewGroup reviewGroup = reviewGroupRepository.save(new ReviewGroup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"ted", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"review-me", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"reviewRequestCode", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"groupAccessCode" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗차차 수정할게요~ |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Review review1 = new Review(template.getId(), reviewGroup.getId(), List.of()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Review review2 = new Review(template.getId(), reviewGroup.getId(), List.of()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Review review3 = new Review(template.getId(), reviewGroup.getId(), List.of()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reviewRepository.saveAll(List.of(review1, review2, review3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
long numberOfReviews = reviewRepository.count(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ReceivedReviewsSummaryResponse actual = reviewSummaryService.getReviewSummary( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reviewGroup.getReviewRequestCode()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertAll( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
() -> assertThat(actual.projectName()).isEqualTo(reviewGroup.getProjectName()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
() -> assertThat(actual.revieweeName()).isEqualTo(reviewGroup.getReviewee()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
() -> assertThat(actual.totalReviewCount()).isEqualTo(numberOfReviews) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reivewRepositoy.count 하면 다른 리뷰그룹의 리뷰까지 함께 가져오는 결과를 의미하니 이렇게 list의 크기로 검증하는 건 어떨까요?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굿 깔끔 반영했어요~ |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void 리뷰_요약_정보_조회시_리뷰_요청_코드가_존재하지_않는_경우_예외가_발생한다() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ReviewGroup reviewGroup = reviewGroupRepository.save(new ReviewGroup( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"ted", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"review-me", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"reviewRequestCode", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"groupAccessCode" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// when, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assertThatThrownBy(() -> reviewSummaryService.getReviewSummary( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reviewGroup.getReviewRequestCode() + "wrong")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.isInstanceOf(ReviewGroupNotFoundByReviewRequestCodeException.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 reviewGroup의 review가 아닌 내 reviewGroup의 review 갯수만 반환하는지 확인하는 로직이 필요할 것 같아요~ 쓰고보니 repository의 countByReviewGroupId에 대한 테스트 메서드를 만드는 게 더 맞겠다는 생각도 드네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 다른 레포지토리에서 JPA가 만들어준 메서드는 따로 테스트 하고 있지 않아서.. 우선 기존 테스트에 그룹 하나 추가하는 걸로도 알 수 있을 것 같아 추가했어요~