test(user-service): 고객 고유번호 리스트로 고객 가져오기 테스트
This commit is contained in:
@@ -69,6 +69,8 @@ domain-httpRequestCode-etc
|
|||||||
operation::customer-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
operation::customer-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||||
=== 회원 조회 (존재하지 않는 회원)
|
=== 회원 조회 (존재하지 않는 회원)
|
||||||
operation::customer-get-notExistUserException[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
operation::customer-get-notExistUserException[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||||
|
=== 회원 조회
|
||||||
|
operation::customers-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||||
|
|
||||||
== 점주
|
== 점주
|
||||||
=== 회원가입 - 점주
|
=== 회원가입 - 점주
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class UserController {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@GetMapping("/customer/{userId}")
|
@GetMapping("/customer/{userId}")
|
||||||
public ResponseEntity getCustomer(@Valid @PathVariable("userId") Long userId) {
|
public ResponseEntity getCustomer(@PathVariable("userId") Long userId) {
|
||||||
|
|
||||||
CustomerDto customerDto = userService.findCustomerByUserId(userId);
|
CustomerDto customerDto = userService.findCustomerByUserId(userId);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.BDDMockito.willThrow;
|
import static org.mockito.BDDMockito.willThrow;
|
||||||
@@ -198,4 +202,51 @@ class UserControllerTest {
|
|||||||
))
|
))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("[GET] 고객 리스트 조회")
|
||||||
|
void getCustomers() throws Exception {
|
||||||
|
// GIVEN
|
||||||
|
List<Long> customerIds = List.of(1L, 2L, 3L);
|
||||||
|
|
||||||
|
given(userService.findCustomerByUserIds(customerIds))
|
||||||
|
.willReturn(customerWillReturnDto(customerIds));
|
||||||
|
|
||||||
|
String customerIdsParam = customerIds.stream()
|
||||||
|
.map(String::valueOf)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
// THEN
|
||||||
|
ResultActions actions = mockMvc.perform(get("/customers/{customerIds}", customerIdsParam));
|
||||||
|
// WHEN
|
||||||
|
actions.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("code").value(Code.SUCCESS.name()))
|
||||||
|
.andExpect(jsonPath("message").value(""))
|
||||||
|
.andDo(print())
|
||||||
|
.andDo(document("customers-get",
|
||||||
|
pathParameters(
|
||||||
|
parameterWithName("customerIds").description("회원 고유 번호들")
|
||||||
|
),
|
||||||
|
responseFields(
|
||||||
|
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||||
|
fieldWithPath("message").description("메시지"),
|
||||||
|
fieldWithPath("data[*].userId").description("회원 고유 번호"),
|
||||||
|
fieldWithPath("data[*].userName").description("회원 이름"),
|
||||||
|
fieldWithPath("data[*].phoneNumber").description("회원 전화번호")
|
||||||
|
)
|
||||||
|
))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CustomerDto> customerWillReturnDto(List<Long> customerIds) {
|
||||||
|
List<CustomerDto> customerDtoList = new ArrayList<>();
|
||||||
|
for (Long customerId : customerIds) {
|
||||||
|
CustomerDto customerDto = CustomerDto.builder()
|
||||||
|
.id(customerId)
|
||||||
|
.name("이름" + customerId)
|
||||||
|
.phoneNumber("010-1234-5678")
|
||||||
|
.build();
|
||||||
|
customerDtoList.add(customerDto);
|
||||||
|
}
|
||||||
|
return customerDtoList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user