Skip to content

Commit 7c0429e

Browse files
committed
test(review): 봉사 지원 생성 리팩토링에 따른 테스트
- ReviewQueryUseCase 의존하도록 변경
1 parent 3d43e09 commit 7c0429e

File tree

3 files changed

+80
-45
lines changed

3 files changed

+80
-45
lines changed

src/test/java/com/somemore/domains/review/controller/ReviewCommandApiControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ReviewCommandApiControllerTest extends ControllerTestSupport {
4848
void createReview() throws Exception {
4949
// given
5050
ReviewCreateRequestDto requestDto = ReviewCreateRequestDto.builder()
51-
.recruitBoardId(1L)
51+
.volunteerApplyId(1L)
5252
.title("리뷰 제목")
5353
.content("리뷰 내용")
5454
.build();
@@ -105,7 +105,7 @@ void createReviewValidateTestRecruitBoardId() throws Exception {
105105
.andExpect(status().isBadRequest())
106106
.andExpect(jsonPath("$.status").value(400))
107107
.andExpect(jsonPath("$.title").value("유효성 예외"))
108-
.andExpect(jsonPath("$.detail").value("봉사 모집글 아이디는 필수 값입니다."));
108+
.andExpect(jsonPath("$.detail").value("봉사 지원 아이디는 필수 값입니다."));
109109
}
110110

111111
@DisplayName("리뷰 생성 유효성 테스트 - 제목")
@@ -114,7 +114,7 @@ void createReviewValidateTestRecruitBoardId() throws Exception {
114114
void createReviewValidateTestTitle() throws Exception {
115115
// given
116116
ReviewCreateRequestDto requestDto = ReviewCreateRequestDto.builder()
117-
.recruitBoardId(1L)
117+
.volunteerApplyId(1L)
118118
.content("리뷰 내용")
119119
.build();
120120

@@ -140,7 +140,7 @@ void createReviewValidateTestTitle() throws Exception {
140140
void createReviewValidateTestContent() throws Exception {
141141
// given
142142
ReviewCreateRequestDto requestDto = ReviewCreateRequestDto.builder()
143-
.recruitBoardId(1L)
143+
.volunteerApplyId(1L)
144144
.title("리뷰 제목")
145145
.build();
146146

src/test/java/com/somemore/domains/review/service/CreateReviewServiceTest.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ class CreateReviewServiceTest extends IntegrationTestSupport {
3939
void createReview() {
4040
// given
4141
UUID volunteerId = UUID.randomUUID();
42-
Long recruitId = 200L;
42+
Long recruitBoardId = 200L;
4343
VolunteerApply apply = VolunteerApply.builder()
4444
.volunteerId(volunteerId)
45-
.recruitBoardId(200L)
45+
.recruitBoardId(recruitBoardId)
4646
.status(APPROVED)
4747
.attended(true)
4848
.build();
4949
volunteerApplyRepository.save(apply);
5050

5151
ReviewCreateRequestDto requestDto = ReviewCreateRequestDto.builder()
52-
.recruitBoardId(recruitId)
52+
.volunteerApplyId(apply.getId())
5353
.title("리뷰 제목")
5454
.content("리뷰 내용")
5555
.build();
@@ -63,70 +63,69 @@ void createReview() {
6363
assertThat(findReview.get().getId()).isEqualTo(reviewId);
6464
}
6565

66-
@DisplayName("참석하지 않은 봉사 활동에 대해 리뷰를 생성하면 에러가 발생한다")
66+
@DisplayName("이미 작성한 봉사 활동에 대해 리뷰를 생성하면 에러가 발생한다")
6767
@Test
68-
void createReviewWhenNotCompleted() {
68+
void createReviewWhenExistsReview() {
6969
// given
7070
UUID volunteerId = UUID.randomUUID();
71-
Long recruitId = 200L;
71+
Long recruitBoardId = 200L;
7272
VolunteerApply apply = VolunteerApply.builder()
7373
.volunteerId(volunteerId)
74-
.recruitBoardId(200L)
74+
.recruitBoardId(recruitBoardId)
7575
.status(APPROVED)
7676
.attended(false)
7777
.build();
7878
volunteerApplyRepository.save(apply);
7979

80+
Review review = Review.builder()
81+
.volunteerApplyId(apply.getId())
82+
.volunteerId(volunteerId)
83+
.title("리뷰 제목")
84+
.content("리뷰 내용")
85+
.imgUrl("")
86+
.build();
87+
reviewRepository.save(review);
88+
8089
ReviewCreateRequestDto requestDto = ReviewCreateRequestDto.builder()
81-
.recruitBoardId(recruitId)
90+
.volunteerApplyId(apply.getId())
8291
.title("리뷰 제목")
8392
.content("리뷰 내용")
8493
.build();
8594

8695
// when
8796
// then
8897
assertThatThrownBy(
89-
() -> createReviewService.createReview(requestDto, volunteerId, "")
90-
).isInstanceOf(BadRequestException.class)
91-
.hasMessage(REVIEW_RESTRICTED_TO_ATTENDED.getMessage());
98+
() -> createReviewService.createReview(requestDto, volunteerId, ""))
99+
.isInstanceOf(DuplicateException.class)
100+
.hasMessage(REVIEW_ALREADY_EXISTS.getMessage());
92101
}
93102

94-
@DisplayName("이미 작성한 봉사 활동에 대해 리뷰를 생성하면 에러가 발생한다")
103+
104+
@DisplayName("참석하지 않은 봉사 활동에 대해 리뷰를 생성하면 에러가 발생한다")
95105
@Test
96-
void createReviewWhenExistsReview() {
106+
void createReviewWhenNotCompleted() {
97107
// given
98108
UUID volunteerId = UUID.randomUUID();
99-
Long recruitId = 200L;
109+
Long recruitBoardId = 200L;
100110
VolunteerApply apply = VolunteerApply.builder()
101111
.volunteerId(volunteerId)
102-
.recruitBoardId(200L)
112+
.recruitBoardId(recruitBoardId)
103113
.status(APPROVED)
104114
.attended(false)
105115
.build();
106116
volunteerApplyRepository.save(apply);
107117

108-
Review review = Review.builder()
109-
.volunteerApplyId(apply.getId())
110-
.volunteerId(volunteerId)
111-
.title("리뷰 제목")
112-
.content("리뷰 내용")
113-
.imgUrl("")
114-
.build();
115-
116-
reviewRepository.save(review);
117-
118118
ReviewCreateRequestDto requestDto = ReviewCreateRequestDto.builder()
119-
.recruitBoardId(recruitId)
119+
.volunteerApplyId(apply.getId())
120120
.title("리뷰 제목")
121121
.content("리뷰 내용")
122122
.build();
123123

124124
// when
125125
// then
126126
assertThatThrownBy(
127-
() -> createReviewService.createReview(requestDto, volunteerId, "")
128-
).isInstanceOf(DuplicateException.class)
129-
.hasMessage(REVIEW_ALREADY_EXISTS.getMessage());
127+
() -> createReviewService.createReview(requestDto, volunteerId, ""))
128+
.isInstanceOf(BadRequestException.class)
129+
.hasMessage(REVIEW_RESTRICTED_TO_ATTENDED.getMessage());
130130
}
131-
132131
}

src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository;
1717
import com.somemore.global.exception.NoSuchElementException;
1818
import com.somemore.support.IntegrationTestSupport;
19+
import org.junit.jupiter.api.BeforeEach;
1920
import org.junit.jupiter.api.DisplayName;
2021
import org.junit.jupiter.api.Test;
2122
import org.springframework.beans.factory.annotation.Autowired;
@@ -57,38 +58,73 @@ class ReviewQueryServiceTest extends IntegrationTestSupport {
5758
@Autowired
5859
private CenterRepository centerRepository;
5960

61+
private Long volunteerApplyId;
62+
private Review review;
63+
64+
@BeforeEach
65+
void setUp() {
66+
volunteerApplyId = 100L;
67+
review = createReview(volunteerApplyId, UUID.randomUUID());
68+
reviewRepository.save(review);
69+
}
70+
71+
@DisplayName("봉사 지원 아이디로 리뷰 존재 유무를 조회할 수 있다.")
72+
@Test
73+
void existsByVolunteerApplyId() {
74+
// given
75+
// when
76+
boolean result = reviewQueryService.existsByVolunteerApplyId(volunteerApplyId);
77+
78+
// then
79+
assertThat(result).isTrue();
80+
}
81+
6082
@DisplayName("아이디로 리뷰를 조회할 수 있다.")
6183
@Test
62-
void getReviewById() {
84+
void getById() {
6385
// given
64-
Review review = createReview(1L, UUID.randomUUID());
65-
reviewRepository.save(review);
86+
Long id = review.getId();
6687

6788
// when
68-
ReviewDetailResponseDto findOne = reviewQueryService.getDetailById(review.getId());
89+
Review findOne = reviewQueryService.getById(id);
6990

7091
// then
71-
assertThat(findOne).extracting("id").isEqualTo(review.getId());
72-
assertThat(findOne).extracting("volunteerId").isEqualTo(review.getVolunteerId());
73-
assertThat(findOne).extracting("title").isEqualTo(review.getTitle());
74-
assertThat(findOne).extracting("content").isEqualTo(review.getContent());
75-
assertThat(findOne).extracting("imgUrl").isEqualTo(review.getImgUrl());
92+
assertThat(findOne.getId()).isEqualTo(id);
7693
}
7794

7895
@DisplayName("존재하지 않는 아이디로 리뷰를 조회하면 에러가 발생한다.")
7996
@Test
80-
void getReviewByIdWhenWrongId() {
97+
void getByIdWhenDoesNotExist() {
8198
// given
8299
Long wrongId = 10000000L;
83100

84101
// when
85102
// then
86103
assertThatThrownBy(
87-
() -> reviewQueryService.getDetailById(wrongId))
104+
() -> reviewQueryService.getById(wrongId))
88105
.isInstanceOf(NoSuchElementException.class)
89106
.hasMessage(NOT_EXISTS_REVIEW.getMessage());
90107
}
91108

109+
110+
@DisplayName("아이디로 리뷰를 상세 조회할 수 있다.")
111+
@Test
112+
void getDetailById() {
113+
// given
114+
Long id = review.getId();
115+
116+
// when
117+
ReviewDetailResponseDto findOne = reviewQueryService.getDetailById(id);
118+
119+
// then
120+
assertThat(findOne).extracting("id").isEqualTo(review.getId());
121+
assertThat(findOne).extracting("volunteerId").isEqualTo(review.getVolunteerId());
122+
assertThat(findOne).extracting("title").isEqualTo(review.getTitle());
123+
assertThat(findOne).extracting("content").isEqualTo(review.getContent());
124+
assertThat(findOne).extracting("imgUrl").isEqualTo(review.getImgUrl());
125+
}
126+
127+
92128
@DisplayName("봉사자 ID로 리뷰 리스트를 조회할 수 있다.")
93129
@Test
94130
void getReviewsByVolunteerId() {

0 commit comments

Comments
 (0)