test(store): 매장 고유번호들로 매장 리스트 가져오기
This commit is contained in:
@@ -100,4 +100,5 @@ operation::favoriteStore-get[snippets='curl-request,http-request,http-response,r
|
||||
operation::store-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||
=== 매장 조회 (회원 고유번호)
|
||||
operation::api-get-store-byUserId[snippets='curl-request,http-request,http-response,request-headers,response-fields']
|
||||
|
||||
=== 매장 리스트 조회
|
||||
operation::stores-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.justpickup.storeservice.domain.store.web;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.store.dto.StoreDto;
|
||||
import com.justpickup.storeservice.domain.store.service.StoreService;
|
||||
import com.justpickup.storeservice.global.dto.Code;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -13,6 +14,10 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
@@ -21,6 +26,7 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.response
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(StoreController.class)
|
||||
@@ -66,4 +72,52 @@ class StoreControllerTest {
|
||||
private StoreDto getWillReturnStore() {
|
||||
return StoreDto.builder().id(1L).name("이디야커피 대림역점").phoneNumber("010-1234-5678").build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("[GET] 매장 정보들 가져오기")
|
||||
void getStores() throws Exception {
|
||||
// GIVEN
|
||||
List<Long> storeIds = List.of(1L, 2L, 3L);
|
||||
|
||||
given(storeService.findStoreAllById(storeIds))
|
||||
.willReturn(storesWillReturnDto(storeIds));
|
||||
|
||||
String storeIdsParam = storeIds.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
// THEN
|
||||
ResultActions actions = mockMvc.perform(get("/stores/{storeIds}", storeIdsParam));
|
||||
// WHEN
|
||||
actions.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("code").value(Code.SUCCESS.name()))
|
||||
.andExpect(jsonPath("message").value(""))
|
||||
.andDo(print())
|
||||
.andDo(document("stores-get",
|
||||
pathParameters(
|
||||
parameterWithName("storeIds").description("매장 고유 번호들")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data[*].id").description("매장 고유 번호"),
|
||||
fieldWithPath("data[*].name").description("매장 이름"),
|
||||
fieldWithPath("data[*].phoneNumber").description("매장 휴대폰 번호")
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
private List<StoreDto> storesWillReturnDto(List<Long> storeIds) {
|
||||
List<StoreDto> stores = new ArrayList<>();
|
||||
for (Long storeId : storeIds) {
|
||||
StoreDto storeDto = StoreDto.builder()
|
||||
.id(storeId)
|
||||
.name("매장 이름" + storeId)
|
||||
.phoneNumber("010-1234-5678")
|
||||
.build();
|
||||
stores.add(storeDto);
|
||||
}
|
||||
return stores;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user