From 8b017aee399f9d081985fa1f123721c350aba1d9 Mon Sep 17 00:00:00 2001 From: bum12ark Date: Fri, 11 Mar 2022 15:43:04 +0900 Subject: [PATCH] =?UTF-8?q?test(store):=20=ED=9A=8C=EC=9B=90=20=EA=B3=A0?= =?UTF-8?q?=EC=9C=A0=EB=B2=88=ED=98=B8=EB=A1=9C=20=EB=A7=A4=EC=9E=A5=20?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- store-service/src/docs/asciidoc/api-docs.adoc | 5 +- .../store/web/StoreOwnerApiController.java | 2 +- .../web/StoreOwnerApiControllerTest.java | 75 +++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiControllerTest.java diff --git a/store-service/src/docs/asciidoc/api-docs.adoc b/store-service/src/docs/asciidoc/api-docs.adoc index cdb3467..25dd173 100644 --- a/store-service/src/docs/asciidoc/api-docs.adoc +++ b/store-service/src/docs/asciidoc/api-docs.adoc @@ -89,9 +89,6 @@ operation::get-categoryList[snippets='curl-request,http-request,http-response,re operation::put-categoryList[snippets='curl-request,http-request,http-response,request-body,request-fields'] - - - == 매장 === 매장 검색 조회 operation::api-customer-store-search[snippets='curl-request,http-request,http-response,request-parameters,response-fields'] @@ -99,4 +96,6 @@ operation::api-customer-store-search[snippets='curl-request,http-request,http-re operation::favoriteStore-get[snippets='curl-request,http-request,http-response,request-headers,request-parameters,response-fields'] === 매장 조회 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'] diff --git a/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiController.java b/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiController.java index 9979e5b..8e13161 100644 --- a/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiController.java +++ b/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiController.java @@ -20,7 +20,7 @@ public class StoreOwnerApiController { private final StoreService storeService; - @GetMapping("/api/store") + @GetMapping("/owner/store") public ResponseEntity getStoreByUserId(@RequestHeader("user-id") String userHeader) { Long userId = Long.valueOf(userHeader); diff --git a/store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiControllerTest.java b/store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiControllerTest.java new file mode 100644 index 0000000..598ef1e --- /dev/null +++ b/store-service/src/test/java/com/justpickup/storeservice/domain/store/web/StoreOwnerApiControllerTest.java @@ -0,0 +1,75 @@ +package com.justpickup.storeservice.domain.store.web; + +import com.justpickup.storeservice.config.TestConfig; +import com.justpickup.storeservice.domain.store.dto.StoreByUserIdDto; +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; +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.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +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.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(StoreOwnerApiController.class) +@Import(TestConfig.class) +@AutoConfigureRestDocs(uriHost = "just-pickup.com", uriPort = 8000) +class StoreOwnerApiControllerTest { + + private final String url = "/api"; + + @Autowired + MockMvc mockMvc; + + @MockBean + StoreService storeService; + + @Test + @DisplayName("[API] [GET] 회원 고유번호로 매장 정보 찾기") + void getStoreByUserId() throws Exception { + // GIVEN + String userHeader = "1"; + Long userId = Long.valueOf(userHeader); + StoreByUserIdDto willReturnDto = StoreByUserIdDto.builder().id(10L).name("한강커피").build(); + given(storeService.findStoreByUserId(userId)).willReturn(willReturnDto); + + // THEN + ResultActions actions = mockMvc.perform(get(url + "/owner/store") + .header("user-id", userHeader) + ); + + // WHEN + actions.andExpect(status().isOk()) + .andExpect(jsonPath("code").value(Code.SUCCESS.name())) + .andExpect(jsonPath("data").exists()) + .andDo(print()) + .andDo(document("api-get-store-byUserId", + requestHeaders( + headerWithName("user-id").description("로그인한 유저 id") + ), + responseFields( + fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"), + fieldWithPath("message").description("메시지"), + fieldWithPath("data.id").description("매장 고유번호"), + fieldWithPath("data.name").description("매장 이름") + ) + )) + ; + + } +} \ No newline at end of file