test(store): 매장 생성 테스트 구현
This commit is contained in:
@@ -108,6 +108,8 @@ operation::store-get[snippets='curl-request,http-request,http-response,path-para
|
||||
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']
|
||||
=== 매장 생성 (점주 서비스)
|
||||
operation::api-post-store[snippets='curl-request,http-request,http-response,request-headers,request-fields']
|
||||
|
||||
== 즐겨찾는 매장
|
||||
=== 즐겨찾는 매장 조회
|
||||
|
||||
@@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.SliceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -71,6 +72,7 @@ public class StoreServiceImpl implements StoreService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public PostStoreDto saveStore(PostStoreDto postStoreDto) {
|
||||
PostStoreDto._PostStoreAddress postStoreAddress = postStoreDto.getAddress();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.justpickup.storeservice.domain.store.web;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.store.dto.StoreByUserIdDto;
|
||||
import com.justpickup.storeservice.domain.store.service.StoreService;
|
||||
@@ -11,6 +12,7 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDoc
|
||||
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.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
@@ -20,8 +22,8 @@ import static org.springframework.restdocs.headers.HeaderDocumentation.headerWit
|
||||
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.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
|
||||
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;
|
||||
@@ -36,6 +38,9 @@ class StoreOwnerApiControllerTest {
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@MockBean
|
||||
StoreService storeService;
|
||||
|
||||
@@ -70,6 +75,48 @@ class StoreOwnerApiControllerTest {
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("[API] 점주 등록")
|
||||
void postStore() throws Exception {
|
||||
// GIVEN
|
||||
StoreOwnerApiController.PostStoreRequest request = StoreOwnerApiController.PostStoreRequest.builder()
|
||||
.name("점주 이름")
|
||||
.phoneNumber("010-1234-5678")
|
||||
.address("서울특별시 마포구 용강동 123-1길")
|
||||
.zipcode("129845")
|
||||
.latitude(30.90199982)
|
||||
.longitude(112.1298347)
|
||||
.build();
|
||||
|
||||
Long userId = 1L;
|
||||
String content = objectMapper.writeValueAsString(request);
|
||||
|
||||
// THEN
|
||||
ResultActions actions = mockMvc.perform(post(url + "/owner/store")
|
||||
.content(content)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.header("user-id", String.valueOf(userId))
|
||||
);
|
||||
|
||||
// WHEN
|
||||
actions.andExpect(status().isCreated())
|
||||
.andDo(print())
|
||||
.andDo(document("api-post-store",
|
||||
requestHeaders(
|
||||
headerWithName("user-id").description("JWT 유저 고유 번호")
|
||||
),
|
||||
requestFields(
|
||||
fieldWithPath("name").description("매징 이름"),
|
||||
fieldWithPath("phoneNumber").description("매장 번호"),
|
||||
fieldWithPath("address").description("매장 주소"),
|
||||
fieldWithPath("zipcode").description("매장 우편번호"),
|
||||
fieldWithPath("latitude").description("위도"),
|
||||
fieldWithPath("longitude").description("경도")
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user