@@ -51,17 +51,11 @@ class ReviewRepositoryImplTest extends IntegrationTestSupport {
5151 @ Autowired
5252 private VolunteerRepository volunteerRepository ;
5353
54- @ DisplayName ("리뷰 생성 및 조회 " )
54+ @ DisplayName ("리뷰를 저장하고 조회할 수 있다 " )
5555 @ Test
5656 void saveAndFind () {
5757 // given
58- Review review = Review .builder ()
59- .volunteerApplyId (1L )
60- .volunteerId (UUID .randomUUID ())
61- .title ("리뷰 제목" )
62- .content ("리뷰 내용" )
63- .imgUrl ("" )
64- .build ();
58+ Review review = createReview (1L , UUID .randomUUID (), "리뷰 내용" );
6559 reviewRepository .save (review );
6660
6761 // when
@@ -77,13 +71,7 @@ void saveAndFind() {
7771 void existsByVolunteerApplyId () {
7872 // given
7973 Long volunteerApplyId = 1L ;
80- Review review = Review .builder ()
81- .volunteerApplyId (volunteerApplyId )
82- .volunteerId (UUID .randomUUID ())
83- .title ("리뷰 제목" )
84- .content ("리뷰 내용" )
85- .imgUrl ("" )
86- .build ();
74+ Review review = createReview (volunteerApplyId , UUID .randomUUID (), "리뷰 내용" );
8775 reviewRepository .save (review );
8876
8977 // when
@@ -93,9 +81,9 @@ void existsByVolunteerApplyId() {
9381 assertThat (result ).isTrue ();
9482 }
9583
96- @ DisplayName ("봉사자 ID로 검색 조건으로 리뷰를 조회할 수 있다. " )
84+ @ DisplayName ("봉사자 ID로 조건 없이 리뷰를 조회할 수 있다" )
9785 @ Test
98- void findAllByVolunteerIdAndSearchWithCondition () {
86+ void findAllByVolunteerIdAndSearchWithoutCondition () {
9987 // given
10088 UUID volunteerId = UUID .randomUUID ();
10189
@@ -109,35 +97,30 @@ void findAllByVolunteerIdAndSearchWithCondition() {
10997
11098 volunteerApplyRepository .saveAll (List .of (apply1 , apply2 ));
11199
112- Review review1 = createReview (apply1 .getId (), volunteerId , "제 인생 최고의 봉사활동" ,
113- "정말 유익했습니다. 더보기.." ,
114- "https://image.domain.com/links1" );
115- Review review2 = createReview (apply2 .getId (), volunteerId , "보람있는 봉사활동" ,
116- "많은 사람들에게 도움을 주었어요." ,
117- "https://image.domain.com/links2" );
100+ Review review1 = createReview (apply1 .getId (), volunteerId , "제 인생 최고의 봉사활동" );
101+ Review review2 = createReview (apply2 .getId (), volunteerId , "보람있는 봉사활동" );
118102 reviewRepository .saveAll (List .of (review1 , review2 ));
119103
120- ReviewSearchCondition conditionWithType = ReviewSearchCondition .builder ()
121- .volunteerType (type )
104+ ReviewSearchCondition conditionWithoutType = ReviewSearchCondition .builder ()
122105 .pageable (getPageable ())
123106 .build ();
124107
125108 // when
126109 Page <Review > result = reviewRepository .findAllByVolunteerIdAndSearch (volunteerId ,
127- conditionWithType );
110+ conditionWithoutType );
128111
129112 // then
130- assertThat (result .getTotalElements ()).isEqualTo (1 );
113+ assertThat (result .getTotalElements ()).isEqualTo (2 );
131114 assertThat (result .getContent ()).extracting ("title" )
132- .containsExactlyInAnyOrder ("제 인생 최고의 봉사활동" );
115+ .containsExactlyInAnyOrder ("제 인생 최고의 봉사활동" , "보람있는 봉사활동" );
133116
134117 assertThat (result .getPageable ().getPageSize ()).isEqualTo (5 );
135118 assertThat (result .getPageable ().getPageNumber ()).isZero ();
136119 }
137120
138- @ DisplayName ("봉사자 ID로 리뷰를 조회할 수 있다" )
121+ @ DisplayName ("기관 ID와 봉사 유형으로 리뷰 목록을 조회할 수 있다" )
139122 @ Test
140- void findAllByVolunteerIdAndSearchWithoutCondition () {
123+ void findAllByVolunteerIdAndSearchWithCondition () {
141124 // given
142125 UUID volunteerId = UUID .randomUUID ();
143126
@@ -151,34 +134,31 @@ void findAllByVolunteerIdAndSearchWithoutCondition() {
151134
152135 volunteerApplyRepository .saveAll (List .of (apply1 , apply2 ));
153136
154- Review review1 = createReview (apply1 .getId (), volunteerId , "제 인생 최고의 봉사활동" ,
155- "정말 유익했습니다. 더보기.." ,
156- "https://image.domain.com/links1" );
157- Review review2 = createReview (apply2 .getId (), volunteerId , "보람있는 봉사활동" ,
158- "많은 사람들에게 도움을 주었어요." ,
159- "https://image.domain.com/links2" );
137+ Review review1 = createReview (apply1 .getId (), volunteerId , "제 인생 최고의 봉사활동" );
138+ Review review2 = createReview (apply2 .getId (), volunteerId , "보람있는 봉사활동" );
160139 reviewRepository .saveAll (List .of (review1 , review2 ));
161140
162- ReviewSearchCondition conditionWithoutType = ReviewSearchCondition .builder ()
141+ ReviewSearchCondition conditionWithType = ReviewSearchCondition .builder ()
142+ .volunteerType (type )
163143 .pageable (getPageable ())
164144 .build ();
165145
166146 // when
167147 Page <Review > result = reviewRepository .findAllByVolunteerIdAndSearch (volunteerId ,
168- conditionWithoutType );
148+ conditionWithType );
169149
170150 // then
171- assertThat (result .getTotalElements ()).isEqualTo (2 );
151+ assertThat (result .getTotalElements ()).isEqualTo (1 );
172152 assertThat (result .getContent ()).extracting ("title" )
173- .containsExactlyInAnyOrder ("제 인생 최고의 봉사활동" , "보람있는 봉사활동" );
153+ .containsExactlyInAnyOrder ("제 인생 최고의 봉사활동" );
174154
175155 assertThat (result .getPageable ().getPageSize ()).isEqualTo (5 );
176156 assertThat (result .getPageable ().getPageNumber ()).isZero ();
177157 }
178158
179- @ DisplayName ("기관 ID와 검색 조건으로 리뷰 목록을 조회할 수 있다. " )
159+ @ DisplayName ("기관 ID로 봉사 유형 없이 리뷰 목록을 조회할 수 있다" )
180160 @ Test
181- void findAllByCenterIdAndSearchWithType () {
161+ void findAllByCenterIdAndSearchWithoutType () {
182162 // given
183163 Center center = createCenter ("Test Center" );
184164 centerRepository .save (center );
@@ -187,40 +167,38 @@ void findAllByCenterIdAndSearchWithType() {
187167 RecruitBoard board2 = createCompletedRecruitBoard (center .getId (), CULTURAL_EVENT );
188168 recruitBoardRepository .saveAll (List .of (board1 , board2 ));
189169
190- Volunteer volunteer = Volunteer . createDefault ( NAVER , "naver" );
170+ Volunteer volunteer = createVolunteer ( );
191171 volunteerRepository .save (volunteer );
192172
193173 VolunteerApply apply1 = createApply (volunteer .getId (), board1 .getId ());
194174 VolunteerApply apply2 = createApply (volunteer .getId (), board2 .getId ());
195175 volunteerApplyRepository .saveAll (List .of (apply1 , apply2 ));
196176
197- Review review1 = createReview (apply1 .getId (), volunteer .getId (), "제목제목" , "내용내용" , "이미지링크" );
198- Review review2 = createReview (apply2 .getId (), volunteer .getId (), "제목제목제목" , "내용내용내용" ,
199- "이미지링크링크" );
177+ Review review1 = createReview (apply1 .getId (), volunteer .getId (), "제목제목" );
178+ Review review2 = createReview (apply2 .getId (), volunteer .getId (), "제목제목제목" );
200179 reviewRepository .saveAll (List .of (review1 , review2 ));
201180
202181 ReviewSearchCondition condition = ReviewSearchCondition .builder ()
203- .volunteerType (CULTURAL_EVENT )
204182 .pageable (getPageable ())
205183 .build ();
206184
207185 // when
208186 Page <Review > result = reviewRepository .findAllByCenterIdAndSearch (center .getId (),
209187 condition );
210188
211- assertThat (result .getContent ()).hasSize (1 );
189+ assertThat (result .getContent ()).hasSize (2 );
212190
213191 assertThat (result .getContent ())
214192 .extracting ("title" )
215- .containsExactly ( "제목제목제목" );
193+ .containsExactlyInAnyOrder ( "제목제목" , "제목제목제목" );
216194
217- assertThat (result .getTotalElements ()).isEqualTo (1 );
195+ assertThat (result .getTotalElements ()).isEqualTo (2 );
218196 assertThat (result .getTotalPages ()).isEqualTo (1 );
219197 }
220198
221- @ DisplayName ("기관 ID으로 리뷰 목록을 조회할 수 있다." )
199+ @ DisplayName ("기관 ID와 검색 조건으로 리뷰 목록을 조회할 수 있다." )
222200 @ Test
223- void findAllByCenterIdAndSearchWithoutType () {
201+ void findAllByCenterIdAndSearchWithType () {
224202 // given
225203 Center center = createCenter ("Test Center" );
226204 centerRepository .save (center );
@@ -229,44 +207,47 @@ void findAllByCenterIdAndSearchWithoutType() {
229207 RecruitBoard board2 = createCompletedRecruitBoard (center .getId (), CULTURAL_EVENT );
230208 recruitBoardRepository .saveAll (List .of (board1 , board2 ));
231209
232- Volunteer volunteer = Volunteer . createDefault ( NAVER , "naver" );
210+ Volunteer volunteer = createVolunteer ( );
233211 volunteerRepository .save (volunteer );
234212
235213 VolunteerApply apply1 = createApply (volunteer .getId (), board1 .getId ());
236214 VolunteerApply apply2 = createApply (volunteer .getId (), board2 .getId ());
237215 volunteerApplyRepository .saveAll (List .of (apply1 , apply2 ));
238216
239- Review review1 = createReview (apply1 .getId (), volunteer .getId (), "제목제목" , "내용내용" , "이미지링크" );
240- Review review2 = createReview (apply2 .getId (), volunteer .getId (), "제목제목제목" , "내용내용내용" ,
241- "이미지링크링크" );
217+ Review review1 = createReview (apply1 .getId (), volunteer .getId (), "제목제목" );
218+ Review review2 = createReview (apply2 .getId (), volunteer .getId (), "제목제목제목" );
242219 reviewRepository .saveAll (List .of (review1 , review2 ));
243220
244221 ReviewSearchCondition condition = ReviewSearchCondition .builder ()
222+ .volunteerType (CULTURAL_EVENT )
245223 .pageable (getPageable ())
246224 .build ();
247225
248226 // when
249227 Page <Review > result = reviewRepository .findAllByCenterIdAndSearch (center .getId (),
250228 condition );
251229
252- assertThat (result .getContent ()).hasSize (2 );
230+ assertThat (result .getContent ()).hasSize (1 );
253231
254232 assertThat (result .getContent ())
255233 .extracting ("title" )
256- .containsExactlyInAnyOrder ( "제목제목" , "제목제목제목" );
234+ .containsExactly ( "제목제목제목" );
257235
258- assertThat (result .getTotalElements ()).isEqualTo (2 );
236+ assertThat (result .getTotalElements ()).isEqualTo (1 );
259237 assertThat (result .getTotalPages ()).isEqualTo (1 );
260238 }
261239
262- private Review createReview (Long applyId , UUID volunteerId , String title , String content ,
263- String imgUrl ) {
240+ private static Volunteer createVolunteer () {
241+ return Volunteer .createDefault (NAVER , "naver" );
242+ }
243+
244+ private Review createReview (Long applyId , UUID volunteerId , String title ) {
264245 return Review .builder ()
265246 .volunteerApplyId (applyId )
266247 .volunteerId (volunteerId )
267248 .title (title )
268- .content (content )
269- .imgUrl (imgUrl )
249+ .content ("내용내용" )
250+ .imgUrl ("이미지링크" )
270251 .build ();
271252 }
272253
0 commit comments