From cf03d7e2333e4c475c3c496e5baab2cda0e64d51 Mon Sep 17 00:00:00 2001 From: bum12ark Date: Thu, 3 Mar 2022 20:50:03 +0900 Subject: [PATCH] =?UTF-8?q?test(store,=20customer-vue):=20=EB=A7=A4?= =?UTF-8?q?=EC=9E=A5=20=EA=B2=80=EC=83=89=20API=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - searchStore -> search-store : url 변경 - 매장 검색 API 테스트 추가 --- customer-vue/src/api/store.js | 2 +- store-service/src/docs/asciidoc/api-docs.adoc | 18 ++-- .../domain/store/web/StoreController.java | 2 +- .../domain/store/web/StoreControllerTest.java | 98 +++++++++++++++++++ 4 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreControllerTest.java diff --git a/customer-vue/src/api/store.js b/customer-vue/src/api/store.js index df0c8dc..074fd51 100644 --- a/customer-vue/src/api/store.js +++ b/customer-vue/src/api/store.js @@ -10,6 +10,6 @@ export default { page: page } } - return axios.get("http://localhost:8000/store-service/searchStore", options); + return axios.get("http://localhost:8000/store-service/search-store", options); } } \ No newline at end of file diff --git a/store-service/src/docs/asciidoc/api-docs.adoc b/store-service/src/docs/asciidoc/api-docs.adoc index 8bb165c..c6b070b 100644 --- a/store-service/src/docs/asciidoc/api-docs.adoc +++ b/store-service/src/docs/asciidoc/api-docs.adoc @@ -64,17 +64,21 @@ == snippets 작성 컨벤션 domain-httpRequestCode-etc -== 주문 -=== 점주 서비스 - 카테고리 페이지 -- 페이지 offset : 6 +== 상품 +=== 상품 조회 +operation::item-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields'] +=== 상품 조회 (존재하지 않는 상품) +operation::item-get-notExistItemException[snippets='curl-request,http-request,http-response,path-parameters,response-fields'] +== 카테고리 == 카테고리 조회 - operation::get-categoryList[snippets='curl-request,http-request,http-response,request-parameters,response-fields'] ---- - == 카테고리 수정 +operation::put-categoryList[snippets='curl-request,http-request,http-response,request-body,request-fields'] + +== 매장 +=== 매장 검색 조회 +operation::searchStore-get[snippets='curl-request,http-request,http-response,request-parameters,response-fields'] -operation::put-categoryList[snippets='curl-request,http-request,http-response,request-parameters,response-fields'] diff --git a/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreController.java b/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreController.java index a63359a..98fb92e 100644 --- a/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreController.java +++ b/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreController.java @@ -26,7 +26,7 @@ public class StoreController { private final StoreService storeService; - @GetMapping("/searchStore") + @GetMapping("/search-store") public ResponseEntity searchStore(@Valid SearchStoreCondition condition, @PageableDefault(page = 0, size = 2) Pageable pageable) { SliceImpl searchStoreScroll = storeService.findSearchStoreScroll(condition, pageable); diff --git a/store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreControllerTest.java b/store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreControllerTest.java new file mode 100644 index 0000000..37016b1 --- /dev/null +++ b/store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreControllerTest.java @@ -0,0 +1,98 @@ +package com.justpickup.storeservice.domain.store.web; + +import com.justpickup.storeservice.config.TestConfig; +import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition; +import com.justpickup.storeservice.domain.store.dto.SearchStoreResult; +import com.justpickup.storeservice.domain.store.repository.StoreRepository; +import com.justpickup.storeservice.domain.store.service.StoreService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.SliceImpl; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(StoreController.class) +@Import(TestConfig.class) +@AutoConfigureRestDocs(uriHost = "127.0.0.1", uriPort = 8000) +class StoreControllerTest { + + @Autowired + MockMvc mockMvc; + + @MockBean + StoreService storeService; + + @MockBean + StoreRepository storeRepository; + + @Test + @DisplayName("[API] [GET] 매장 검색 페이지 조회") + void getSearchStore() throws Exception { + // GIVEN + double latitude = 37.5403912; + double longitude = 126.9438922; + SearchStoreCondition condition = new SearchStoreCondition(latitude, longitude, null); + PageRequest pageable = PageRequest.of(0, 2); + + given(storeService.findSearchStoreScroll(any(SearchStoreCondition.class), any(Pageable.class))) + .willReturn(getWillReturnSearchStore(pageable)); + + // WHEN + ResultActions actions = mockMvc.perform(get("/search-store") + .param("latitude", String.valueOf(condition.getLatitude())) + .param("longitude", String.valueOf(condition.getLongitude())) + .param("page", String.valueOf(pageable.getPageNumber())) + .param("size", String.valueOf(pageable.getPageSize())) + ); + + // THEN + actions.andExpect(status().isOk()) + .andDo(print()) + .andDo(document("searchStore-get", + requestParameters( + parameterWithName("latitude").description("고객의 위도 [필수]"), + parameterWithName("longitude").description("고객의 경도 [필수]"), + parameterWithName("page").description("검색할 페이지 [Optional, default: 0]"), + parameterWithName("size").description("검색할 페이지 사이즈 [Optional, default: 2]") + ), + responseFields( + fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"), + fieldWithPath("message").description("메시지"), + fieldWithPath("data.stores[*].id").description("매장 고유번호"), + fieldWithPath("data.stores[*].name").description("매장 이름"), + fieldWithPath("data.stores[*].distance").description("고객과의 거리차이 m/km"), + fieldWithPath("data.hasNext").description("더보기 버튼 유무") + ) + )) + ; + } + + private SliceImpl getWillReturnSearchStore(Pageable pageable) { + SearchStoreResult result_1 = new SearchStoreResult(1L, "이디야커피 마포오벨리스크점", 145.11980562222007); + SearchStoreResult result_2 = new SearchStoreResult(2L, "만랩커피 마포점", 150.97181089895466); + SearchStoreResult result_3 = new SearchStoreResult(3L, "커피온리 마포역점", 341.25696860337655); + return new SliceImpl<>(List.of(result_1, result_2, result_3), pageable,true); + } + + +} \ No newline at end of file