|
| 1 | +package com.somemore.interestcenter.controller; |
| 2 | + |
| 3 | +import com.somemore.ControllerTestSupport; |
| 4 | +import com.somemore.WithMockCustomUser; |
| 5 | +import com.somemore.interestcenter.dto.response.GetInterestCentersResponseDto; |
| 6 | +import com.somemore.interestcenter.usecase.InterestCenterQueryUseCase; |
| 7 | +import org.junit.jupiter.api.DisplayName; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.springframework.boot.test.mock.mockito.MockBean; |
| 10 | +import org.springframework.http.MediaType; |
| 11 | + |
| 12 | +import java.util.List; |
| 13 | +import java.util.UUID; |
| 14 | + |
| 15 | +import static org.mockito.BDDMockito.given; |
| 16 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 17 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
| 18 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 19 | + |
| 20 | +class InterestCenterQueryApiControllerTest extends ControllerTestSupport { |
| 21 | + |
| 22 | + @MockBean |
| 23 | + private InterestCenterQueryUseCase interestCenterQueryUseCase; |
| 24 | + |
| 25 | + @DisplayName("봉사자 ID로 관심기관 목록을 조회할 수 있다.") |
| 26 | + @Test |
| 27 | + @WithMockCustomUser |
| 28 | + void getInterestCenters_ShouldReturnInterestCentersList() throws Exception { |
| 29 | + // given |
| 30 | + UUID volunteerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); |
| 31 | + UUID centerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174001"); |
| 32 | + List<GetInterestCentersResponseDto> responseDtos = List.of( |
| 33 | + new GetInterestCentersResponseDto(centerId, "센터1", "http://image1.jpg"), |
| 34 | + new GetInterestCentersResponseDto(centerId, "센터2", "http://image2.jpg") |
| 35 | + ); |
| 36 | + |
| 37 | + given(interestCenterQueryUseCase.getInterestCenters(volunteerId)).willReturn(responseDtos); |
| 38 | + |
| 39 | + // when & then |
| 40 | + mockMvc.perform(get("/api/interest-centers") |
| 41 | + .accept(MediaType.APPLICATION_JSON)) |
| 42 | + .andExpect(status().isOk()) |
| 43 | + .andExpect(jsonPath("$.message").value("관심기관 조회 성공")) |
| 44 | + .andExpect(jsonPath("$.data").isArray()) |
| 45 | + .andExpect(jsonPath("$.data[0].center_name").value("센터1")) |
| 46 | + .andExpect(jsonPath("$.data[0].img_url").value("http://image1.jpg")) |
| 47 | + .andExpect(jsonPath("$.data[1].center_name").value("센터2")) |
| 48 | + .andExpect(jsonPath("$.data[1].img_url").value("http://image2.jpg")); |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + @DisplayName("봉사자 ID로 관심기관이 없을 경우 빈 리스트를 반환한다.") |
| 53 | + @Test |
| 54 | + @WithMockCustomUser |
| 55 | + void getInterestCenters_ShouldReturnEmptyList_WhenNoInterestCenters() throws Exception { |
| 56 | + // given |
| 57 | + UUID volunteerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000"); |
| 58 | + |
| 59 | + given(interestCenterQueryUseCase.getInterestCenters(volunteerId)).willReturn(List.of()); |
| 60 | + |
| 61 | + // when & then |
| 62 | + mockMvc.perform(get("/api/interest-centers") |
| 63 | + .param("volunteerId", volunteerId.toString())) |
| 64 | + .andExpect(status().isOk()) |
| 65 | + .andExpect(jsonPath("$.message").value("관심기관 조회 성공")) |
| 66 | + .andExpect(jsonPath("$.data").isEmpty()); |
| 67 | + } |
| 68 | +} |
| 69 | + |
0 commit comments