test(회원가입 매장 등록 로직 추가): 회원가입 시 매장 정보 생성 테스트

This commit is contained in:
bum12ark
2022-03-21 13:09:19 +09:00
parent c1ea2320b8
commit d1a28f887c
3 changed files with 99 additions and 78 deletions

View File

@@ -76,6 +76,4 @@ operation::customers-get[snippets='curl-request,http-request,http-response,path-
== 점주
=== 회원가입 - 점주
operation::storeOwner-post[snippets='curl-request,http-request,http-response,request-fields,response-fields']
=== 회원가입 - 점주 : 중복 이메일
operation::storeOwner-post-duplicateUserEmailException[snippets='curl-request,http-request,http-response,request-fields,response-fields']
operation::api-owner-post-store-owner[snippets='curl-request,http-request,http-response,request-fields']

View File

@@ -3,7 +3,6 @@ package com.justpickup.userservice.domain.user.web;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.justpickup.userservice.config.TestConfig;
import com.justpickup.userservice.domain.user.dto.CustomerDto;
import com.justpickup.userservice.domain.user.exception.DuplicateUserEmail;
import com.justpickup.userservice.domain.user.exception.NotExistUserException;
import com.justpickup.userservice.domain.user.service.UserService;
import com.justpickup.userservice.global.dto.Code;
@@ -20,8 +19,6 @@ import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.restdocs.headers.HeaderDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
@@ -29,15 +26,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
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.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
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.pathParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@@ -185,74 +180,6 @@ class UserControllerTest {
;
}
@Test
@DisplayName("회원가입 - 점주")
void registerStoreOwner() throws Exception {
UserController.JoinStoreOwnerRequest requestBody =
new UserController.JoinStoreOwnerRequest("test@naver.com", "1234", "Park",
"010-1234-5678", "1234");
ResultActions actions = mockMvc.perform(post("/store-owner")
.content(objectMapper.writeValueAsString(requestBody))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
);
actions.andExpect(status().isCreated())
.andDo(print())
.andDo(document("storeOwner-post",
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
fieldWithPath("name").description("이름"),
fieldWithPath("phoneNumber").description("휴대폰번호"),
fieldWithPath("businessNumber").description("사업자등록번호")
),
responseFields(
fieldWithPath("code").description("결과코드 SUCCESS/ERROR"),
fieldWithPath("message").description("메시지"),
fieldWithPath("data").description("데이터")
)
))
;
}
@Test
@DisplayName("회원가입 - 점주 : 존재하는 회원 이메일")
void registerStoreOwnerDuplicateUserEmailException() throws Exception {
String email = "test@naver.com";
UserController.JoinStoreOwnerRequest requestBody =
new UserController.JoinStoreOwnerRequest(email, "1234", "Park",
"010-1234-5678", "1234");
willThrow(new DuplicateUserEmail(email + "은 중복된 이메일입니다."))
.given(userService).saveStoreOwner(any());
ResultActions actions = mockMvc.perform(post("/store-owner")
.content(objectMapper.writeValueAsString(requestBody))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
);
actions.andExpect(status().isConflict())
.andDo(print())
.andDo(document("storeOwner-post-duplicateUserEmailException",
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
fieldWithPath("name").description("이름"),
fieldWithPath("phoneNumber").description("휴대폰번호"),
fieldWithPath("businessNumber").description("사업자등록번호")
),
responseFields(
fieldWithPath("code").description("결과코드 SUCCESS/ERROR"),
fieldWithPath("message").description("메시지"),
fieldWithPath("data").description("데이터")
)
))
;
}
@Test
@DisplayName("[GET] 고객 리스트 조회")
void getCustomers() throws Exception {

View File

@@ -0,0 +1,96 @@
package com.justpickup.userservice.domain.user.web;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.justpickup.userservice.config.TestConfig;
import com.justpickup.userservice.domain.user.service.UserService;
import com.justpickup.userservice.global.security.SecurityConfig;
import com.justpickup.userservice.global.utils.CookieProvider;
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.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
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;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest(controllers = UserOwnerApiController.class,
excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = SecurityConfig.class)}
)
@AutoConfigureMockMvc(addFilters = false)
@Import(TestConfig.class)
@AutoConfigureRestDocs(uriHost = "admin.just-pickup.com", uriPort = 8001)
class UserOwnerApiControllerTest {
@Autowired
MockMvc mockMvc;
@Autowired
ObjectMapper objectMapper;
@SpyBean
CookieProvider cookieProvider;
@MockBean
UserService userService;
@Test
@DisplayName("점주 서비스 회원가입")
void postStoreOwner() throws Exception {
// GIVEN
UserOwnerApiController.PostStoreOwnerRequest requestBody
= UserOwnerApiController.PostStoreOwnerRequest.builder()
.email("test@gmail.com")
.password("1234")
.name("테스트 이름")
.phoneNumber("010-1234-5678")
.businessNumber("03124")
.storeName("테스트 매장")
.storePhoneNumber("010-1234-5678")
.address("충북 청주시 서원구 1순환로 627")
.zipcode("28562")
.latitude(36.6375346629654)
.longitude(127.459726819858)
.build();
String content = objectMapper.writeValueAsString(requestBody);
// THEN
ResultActions actions = mockMvc.perform(post("/api/owner/store-owner")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(content)
);
// WHEN
actions.andExpect(status().isCreated())
.andDo(print())
.andDo(document("api-owner-post-store-owner",
requestFields(
fieldWithPath("email").description("이메일"),
fieldWithPath("password").description("비밀번호"),
fieldWithPath("name").description("이름"),
fieldWithPath("phoneNumber").description("핸드폰 번호"),
fieldWithPath("businessNumber").description("사업자번호"),
fieldWithPath("storeName").description("매장 이름"),
fieldWithPath("storePhoneNumber").description("매장 번호"),
fieldWithPath("address").description("매장 주소"),
fieldWithPath("zipcode").description("매장 우편번호"),
fieldWithPath("latitude").description("위도"),
fieldWithPath("longitude").description("경도")
)
)
)
;
}
}