|
3 | 3 | import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition; |
4 | 4 | import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition; |
5 | 5 | import com.somemore.domains.recruitboard.dto.response.RecruitBoardDetailResponseDto; |
| 6 | +import com.somemore.domains.recruitboard.dto.response.RecruitBoardResponseDto; |
6 | 7 | import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithCenterResponseDto; |
7 | 8 | import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; |
8 | 9 | import com.somemore.domains.search.config.ElasticsearchHealthChecker; |
9 | 10 | import com.somemore.domains.search.usecase.RecruitBoardDocumentUseCase; |
10 | 11 | import com.somemore.support.ControllerTestSupport; |
| 12 | +import com.somemore.support.annotation.MockUser; |
11 | 13 | import org.junit.jupiter.api.DisplayName; |
12 | 14 | import org.junit.jupiter.api.Test; |
13 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
14 | 16 | import org.springframework.boot.test.mock.mockito.MockBean; |
15 | 17 | import org.springframework.data.domain.Page; |
16 | 18 | import org.springframework.data.domain.PageImpl; |
17 | 19 | import org.springframework.http.MediaType; |
18 | | -import org.springframework.test.context.junit.jupiter.EnabledIf; |
19 | 20 | import org.springframework.test.web.servlet.MockMvc; |
20 | 21 |
|
21 | 22 | import java.util.Collections; |
| 23 | +import java.util.UUID; |
22 | 24 |
|
23 | 25 | import static com.somemore.domains.recruitboard.domain.VolunteerCategory.ADMINISTRATIVE_SUPPORT; |
24 | 26 | import static org.mockito.ArgumentMatchers.any; |
| 27 | +import static org.mockito.ArgumentMatchers.eq; |
25 | 28 | import static org.mockito.BDDMockito.given; |
26 | 29 | import static org.mockito.Mockito.times; |
27 | 30 | import static org.mockito.Mockito.verify; |
@@ -111,4 +114,79 @@ void getNearby() throws Exception { |
111 | 114 | any(RecruitBoardNearByCondition.class)); |
112 | 115 | } |
113 | 116 | } |
| 117 | + |
| 118 | + @Test |
| 119 | + @DisplayName("특정 기관이 작성한 모집글을 검색 조건으로 페이징 조회 성공") |
| 120 | + void getRecruitBoardsByCenterId() throws Exception { |
| 121 | + // given |
| 122 | + UUID centerId = UUID.randomUUID(); |
| 123 | + Page<RecruitBoardResponseDto> page = new PageImpl<>(Collections.emptyList()); |
| 124 | + |
| 125 | + if (elasticsearchHealthChecker.isElasticsearchRunning()) { |
| 126 | + given(recruitBoardDocumentUseCase |
| 127 | + .getRecruitBoardsByCenterIdWithKeyword(eq(centerId), |
| 128 | + any(RecruitBoardSearchCondition.class))) |
| 129 | + .willReturn(page); |
| 130 | + } else { |
| 131 | + given(recruitBoardQueryUseCase.getRecruitBoardsByCenterId(eq(centerId), |
| 132 | + any(RecruitBoardSearchCondition.class))) |
| 133 | + .willReturn(page); |
| 134 | + } |
| 135 | + |
| 136 | + // when |
| 137 | + // then |
| 138 | + mockMvc.perform(get("/api/recruit-boards/center/{centerId}", centerId.toString()) |
| 139 | + .param("keyword", "volunteer") |
| 140 | + .param("category", ADMINISTRATIVE_SUPPORT.name()) |
| 141 | + .accept(MediaType.APPLICATION_JSON)) |
| 142 | + .andExpect(status().isOk()) |
| 143 | + .andExpect(jsonPath("$.code").value(200)) |
| 144 | + .andExpect(jsonPath("$.data").exists()) |
| 145 | + .andExpect(jsonPath("$.message").value("특정 기관 봉사 활동 모집글 조회 성공")); |
| 146 | + |
| 147 | + if (elasticsearchHealthChecker.isElasticsearchRunning()) { |
| 148 | + verify(recruitBoardDocumentUseCase, times(1)) |
| 149 | + .getRecruitBoardsByCenterIdWithKeyword(eq(centerId), any(RecruitBoardSearchCondition.class)); |
| 150 | + } else { |
| 151 | + verify(recruitBoardQueryUseCase, times(1)) |
| 152 | + .getRecruitBoardsByCenterId(eq(centerId), any(RecruitBoardSearchCondition.class)); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + @MockUser(role = "ROLE_CENTER") |
| 158 | + @DisplayName("기관이 작성한 모집글을 검색 조건으로 페이징 조회 성공") |
| 159 | + void getMyRecruitBoards() throws Exception { |
| 160 | + // given |
| 161 | + Page<RecruitBoardResponseDto> page = new PageImpl<>(Collections.emptyList()); |
| 162 | + |
| 163 | + if (elasticsearchHealthChecker.isElasticsearchRunning()) { |
| 164 | + given(recruitBoardDocumentUseCase |
| 165 | + .getRecruitBoardsByCenterIdWithKeyword(any(), |
| 166 | + any(RecruitBoardSearchCondition.class))) |
| 167 | + .willReturn(page); |
| 168 | + } else { |
| 169 | + given(recruitBoardQueryUseCase.getRecruitBoardsByCenterId(any(), |
| 170 | + any(RecruitBoardSearchCondition.class))) |
| 171 | + .willReturn(page); |
| 172 | + } |
| 173 | + |
| 174 | + // when |
| 175 | + // then |
| 176 | + mockMvc.perform(get("/api/recruit-boards/me") |
| 177 | + .param("keyword", "volunteer") |
| 178 | + .param("category", ADMINISTRATIVE_SUPPORT.name()) |
| 179 | + .accept(MediaType.APPLICATION_JSON)) |
| 180 | + .andExpect(status().isOk()) |
| 181 | + .andExpect(jsonPath("$.data").exists()) |
| 182 | + .andExpect(jsonPath("$.message").value("기관 봉사 활동 모집글 조회 성공")); |
| 183 | + |
| 184 | + if (elasticsearchHealthChecker.isElasticsearchRunning()) { |
| 185 | + verify(recruitBoardDocumentUseCase, times(1)) |
| 186 | + .getRecruitBoardsByCenterIdWithKeyword(any(), any(RecruitBoardSearchCondition.class)); |
| 187 | + } else { |
| 188 | + verify(recruitBoardQueryUseCase, times(1)) |
| 189 | + .getRecruitBoardsByCenterId(any(), any(RecruitBoardSearchCondition.class)); |
| 190 | + } |
| 191 | + } |
114 | 192 | } |
0 commit comments