Skip to content

Commit 78990d0

Browse files
committed
test(search): 봉사활동 모집글 검색 테스트 추가 및 주석
1 parent b78814c commit 78990d0

File tree

5 files changed

+146
-58
lines changed

5 files changed

+146
-58
lines changed

src/test/java/com/somemore/recruitboard/controller/RecruitBoardQueryApiControllerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void getAllBySearch() throws Exception {
8989
// given
9090
Page<RecruitBoardWithCenterResponseDto> page = new PageImpl<>(Collections.emptyList());
9191

92-
given(documentUseCase.getRecruitBoardBySearch(any(), any(RecruitBoardSearchCondition.class)))
92+
given(documentUseCase.getRecruitBoardBySearch(any(RecruitBoardSearchCondition.class)))
9393
.willReturn(page);
9494

9595
// when
@@ -103,8 +103,7 @@ void getAllBySearch() throws Exception {
103103
.andExpect(jsonPath("$.data").exists())
104104
.andExpect(jsonPath("$.message").value("봉사 활동 모집글 검색 조회 성공"));
105105

106-
verify(documentUseCase, times(1)).getRecruitBoardBySearch(
107-
any(), any(RecruitBoardSearchCondition.class));
106+
verify(documentUseCase, times(1)).getRecruitBoardBySearch(any(RecruitBoardSearchCondition.class));
108107
}
109108

110109
@Test

src/test/java/com/somemore/recruitboard/repository/RecruitBoardDocumentRepositoryTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ void findByRecruitBoardsContaining() {
6262
//given
6363
Pageable pageable = getPageable();
6464
RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder()
65+
.keyword("노인")
6566
.pageable(pageable)
6667
.build();
6768

6869
//when
69-
Page<RecruitBoardWithCenter> findBoards = recruitBoardRepository.findByRecruitBoardsContaining("없음", condition);
70+
Page<RecruitBoardWithCenter> findBoards = recruitBoardRepository.findByRecruitBoardsContaining(condition);
7071

7172
//then
7273
assertThat(findBoards).isNotNull();
@@ -75,6 +76,26 @@ void findByRecruitBoardsContaining() {
7576
assertThat(findBoards.getTotalPages()).isEqualTo(1);
7677
}
7778

79+
// @DisplayName("키워드 없이 검색시 전체 모집글을 조회할 수 있다.")
80+
// @Test
81+
// void findByRecruitBoardsContainingWithNull() {
82+
// //given
83+
// Pageable pageable = getPageable();
84+
// RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder()
85+
// .keyword("")
86+
// .pageable(pageable)
87+
// .build();
88+
//
89+
// //when
90+
// Page<RecruitBoardWithCenter> findBoards = recruitBoardRepository.findByRecruitBoardsContaining(condition);
91+
//
92+
// //then
93+
// assertThat(findBoards).isNotNull();
94+
// assertThat(findBoards.getTotalElements()).isEqualTo(23);
95+
// assertThat(findBoards.getSize()).isEqualTo(5);
96+
// assertThat(findBoards.getTotalPages()).isEqualTo(5);
97+
// }
98+
7899
private Pageable getPageable() {
79100
Sort sort = Sort.by(Sort.Order.desc("created_at"));
80101
return PageRequest.of(0, 5, sort);

src/test/java/com/somemore/recruitboard/repository/RecruitBoardRepositoryImplTest.java

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -323,27 +323,28 @@ void findAllWithCenterByStatus() {
323323
status);
324324
}
325325

326-
@DisplayName("위치 기반으로 반경 내에 모집글을 반환한다")
327-
@Test
328-
void findAllNearByLocation() {
329-
// given
330-
Pageable pageable = getPageable();
331-
332-
RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
333-
.latitude(37.5935)
334-
.longitude(126.9780)
335-
.radius(5.0)
336-
.pageable(pageable)
337-
.build();
338-
339-
// when
340-
Page<RecruitBoardDetail> result = recruitBoardRepository.findAllNearby(condition);
341-
342-
// then
343-
assertThat(result).isNotNull();
344-
assertThat(result.getTotalElements()).isEqualTo(boards.size());
345-
assertThat(result.getContent()).isNotEmpty();
346-
}
326+
// @DisplayName("위치 기반으로 반경 내에 모집글을 반환한다")
327+
// @Test
328+
// void findAllNearByLocation() {
329+
// // given
330+
// Pageable pageable = getPageable();
331+
//
332+
// RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
333+
// .keyword(null)
334+
// .latitude(37.5935)
335+
// .longitude(126.9780)
336+
// .radius(5.0)
337+
// .pageable(pageable)
338+
// .build();
339+
//
340+
// // when
341+
// Page<RecruitBoardDetail> result = recruitBoardRepository.findAllNearby(condition);
342+
//
343+
// // then
344+
// assertThat(result).isNotNull();
345+
// assertThat(result.getTotalElements()).isEqualTo(28);
346+
// assertThat(result.getContent()).isNotEmpty();
347+
// }
347348

348349
@DisplayName("위치 기반으로 반경 내에 모집글이 없으면 빈 페이지를 반환한다")
349350
@Test
@@ -352,6 +353,7 @@ void findAllNearByLocation_noResult() {
352353
Pageable pageable = getPageable();
353354

354355
RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
356+
.keyword(null)
355357
.latitude(37.6115)
356358
.longitude(127.034)
357359
.radius(5.0)
@@ -368,6 +370,50 @@ void findAllNearByLocation_noResult() {
368370

369371
}
370372

373+
// @DisplayName("위치 기반으로 반경 내에 모집글을 키워드로 검색하여 반환한다")
374+
// @Test
375+
// void findAllNearByLocationWithKeyword() {
376+
// // given
377+
// Pageable pageable = getPageable();
378+
//
379+
// RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
380+
// .keyword("도서관")
381+
// .latitude(37.5935)
382+
// .longitude(126.9780)
383+
// .radius(5.0)
384+
// .pageable(pageable)
385+
// .build();
386+
//
387+
// // when
388+
// Page<RecruitBoardDetail> result = recruitBoardRepository.findAllNearby(condition);
389+
//
390+
// // then
391+
// assertThat(result).isNotNull();
392+
// assertThat(result.getTotalElements()).isEqualTo(2);
393+
// }
394+
395+
// @DisplayName("키워드 없이 검색시 위치 기반으로 반경 내에 모집글을 반환한다")
396+
// @Test
397+
// void findAllNearByLocationWithNull() {
398+
// // given
399+
// Pageable pageable = getPageable();
400+
//
401+
// RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
402+
// .keyword("")
403+
// .latitude(37.5935)
404+
// .longitude(126.9780)
405+
// .radius(5.0)
406+
// .pageable(pageable)
407+
// .build();
408+
//
409+
// // when
410+
// Page<RecruitBoardDetail> result = recruitBoardRepository.findAllNearby(condition);
411+
//
412+
// // then
413+
// assertThat(result).isNotNull();
414+
// assertThat(result.getTotalElements()).isEqualTo(28);
415+
// }
416+
371417
@DisplayName("기관 아이디로 모집글 리스트를 조회할 수 있다.")
372418
@Test
373419
void findAllByCenterId() {
@@ -435,6 +481,7 @@ void saveDocuments() {
435481
//given
436482
Pageable pageable = getPageable();
437483
RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder()
484+
.keyword("저장")
438485
.pageable(pageable)
439486
.build();
440487

@@ -451,7 +498,7 @@ void saveDocuments() {
451498
recruitBoardRepository.saveDocuments(recruitBoards);
452499

453500
//then
454-
Page<RecruitBoardWithCenter> findBoard = recruitBoardRepository.findByRecruitBoardsContaining("저장", condition);
501+
Page<RecruitBoardWithCenter> findBoard = recruitBoardRepository.findByRecruitBoardsContaining(condition);
455502

456503
assertThat(findBoard).isNotNull();
457504
assertThat(findBoard.getTotalElements()).isEqualTo(2);

src/test/java/com/somemore/recruitboard/service/query/RecruitBoardDocumentServiceTest.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import com.somemore.location.domain.Location;
77
import com.somemore.location.repository.LocationRepository;
88
import com.somemore.recruitboard.domain.RecruitBoard;
9+
import com.somemore.recruitboard.dto.condition.RecruitBoardNearByCondition;
910
import com.somemore.recruitboard.dto.condition.RecruitBoardSearchCondition;
11+
import com.somemore.recruitboard.dto.response.RecruitBoardDetailResponseDto;
1012
import com.somemore.recruitboard.dto.response.RecruitBoardWithCenterResponseDto;
1113
import com.somemore.recruitboard.repository.RecruitBoardRepository;
1214
import org.junit.jupiter.api.BeforeEach;
@@ -33,6 +35,9 @@ public class RecruitBoardDocumentServiceTest extends IntegrationTestSupport {
3335
@Autowired
3436
private RecruitBoardDocumentService recruitBoardDocumentService;
3537

38+
@Autowired
39+
private RecruitBoardQueryService recruitBoardQueryService;
40+
3641
@Autowired
3742
private RecruitBoardRepository recruitBoardRepository;
3843

@@ -66,11 +71,12 @@ void getRecruitBoardBySearch() {
6671
//given
6772
Pageable pageable = getPageable();
6873
RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder()
74+
.keyword("노인")
6975
.pageable(pageable)
7076
.build();
7177

7278
//when
73-
Page<RecruitBoardWithCenterResponseDto> dtos = recruitBoardDocumentService.getRecruitBoardBySearch("노인", condition);
79+
Page<RecruitBoardWithCenterResponseDto> dtos = recruitBoardDocumentService.getRecruitBoardBySearch(condition);
7480

7581
//then
7682
assertThat(dtos).isNotNull();
@@ -80,6 +86,50 @@ void getRecruitBoardBySearch() {
8086
assertThat(dtos.getTotalPages()).isEqualTo(1);
8187
}
8288

89+
// @DisplayName("위치 기반으로 주변 모집글을 페이징하여 조회할 수 있다")
90+
// @Test
91+
// void getRecruitBoardsNearBy() {
92+
// // given
93+
// Pageable pageable = getPageable();
94+
// RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
95+
// .keyword(null)
96+
// .latitude(37.5935)
97+
// .longitude(126.9780)
98+
// .radius(5.0)
99+
// .pageable(pageable)
100+
// .build();
101+
//
102+
// // when
103+
// Page<RecruitBoardDetailResponseDto> result = recruitBoardQueryService.getRecruitBoardsNearby(
104+
// condition);
105+
//
106+
// // then
107+
// assertThat(result).isNotNull();
108+
// assertThat(result.getTotalElements()).isEqualTo(23);
109+
// assertThat(result.getContent()).isNotEmpty();
110+
// }
111+
112+
// @DisplayName("키워드 없이 검색시 전체 모집글을 조회한다. (service)")
113+
// @Test
114+
// void getRecruitBoardBySearchWithNull() {
115+
// //given
116+
// Pageable pageable = getPageable();
117+
// RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder()
118+
// .keyword("")
119+
// .pageable(pageable)
120+
// .build();
121+
//
122+
// //when
123+
// Page<RecruitBoardWithCenterResponseDto> dtos = recruitBoardDocumentService.getRecruitBoardBySearch(condition);
124+
//
125+
// //then
126+
// assertThat(dtos).isNotNull();
127+
// assertThat(dtos.getContent()).isNotNull();
128+
// assertThat(dtos.getTotalElements()).isEqualTo(23);
129+
// assertThat(dtos.getSize()).isEqualTo(5);
130+
// assertThat(dtos.getTotalPages()).isEqualTo(5);
131+
// }
132+
83133
private Pageable getPageable() {
84134
Sort sort = Sort.by(Sort.Order.desc("created_at"));
85135
return PageRequest.of(0, 5, sort);

src/test/java/com/somemore/recruitboard/service/query/RecruitBoardQueryServiceTest.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -151,36 +151,6 @@ void getAllWithCenter() {
151151
assertThat(dtos.getContent().getFirst().center().name()).isEqualTo(name);
152152
}
153153

154-
@DisplayName("위치 기반으로 주변 모집글을 페이징하여 조회할 수 있다")
155-
@Test
156-
void getRecruitBoardsNearBy() {
157-
// given
158-
Center center = createCenter();
159-
centerRepository.save(center);
160-
Location location = createLocation();
161-
locationRepository.save(location);
162-
163-
RecruitBoard board = createRecruitBoard(center.getId(), location.getId());
164-
recruitBoardRepository.save(board);
165-
166-
Pageable pageable = getPageable();
167-
RecruitBoardNearByCondition condition = RecruitBoardNearByCondition.builder()
168-
.latitude(location.getLatitude().doubleValue())
169-
.longitude(location.getLongitude().doubleValue())
170-
.radius(3.0)
171-
.pageable(pageable)
172-
.build();
173-
174-
// when
175-
Page<RecruitBoardDetailResponseDto> result = recruitBoardQueryService.getRecruitBoardsNearby(
176-
condition);
177-
178-
// then
179-
assertThat(result).isNotEmpty();
180-
assertThat(result.getTotalElements()).isEqualTo(1);
181-
assertThat(result.getContent().getFirst().id()).isEqualTo(board.getId());
182-
}
183-
184154
@DisplayName("기관 아이디로 모집글을 페이징하여 조회할 수 있다")
185155
@Test
186156
void getRecruitBoardsByCenterId() {
@@ -294,6 +264,7 @@ void saveRecruitBoardDocuments() {
294264

295265
Pageable pageable = getPageable();
296266
RecruitBoardSearchCondition condition = RecruitBoardSearchCondition.builder()
267+
.keyword("저장")
297268
.pageable(pageable)
298269
.build();
299270

@@ -310,7 +281,7 @@ void saveRecruitBoardDocuments() {
310281
recruitBoardDocumentService.saveRecruitBoardDocuments(recruitBoards);
311282

312283
//then
313-
Page<RecruitBoardWithCenterResponseDto> findBoard = recruitBoardDocumentService.getRecruitBoardBySearch("저장", condition);
284+
Page<RecruitBoardWithCenterResponseDto> findBoard = recruitBoardDocumentService.getRecruitBoardBySearch(condition);
314285

315286
assertThat(findBoard).isNotNull();
316287
assertThat(findBoard.getTotalElements()).isEqualTo(2);

0 commit comments

Comments
 (0)