Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HIMIN-228] test : 주문 단건 조회 restdocs 추가 #132

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import java.util.List;
Expand All @@ -18,6 +19,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
Expand Down Expand Up @@ -104,6 +106,37 @@ void createOrder() throws Exception {
)));
}

@Test
@DisplayName("주문 조회를 할 수 있다.")
void getOrder() throws Exception {
// given
OrderResponse response = OrderResponseBuilder.successBuild();
given(orderService.getOrder(anyLong())).willReturn(response);

// when
ResultActions resultActions = mvc.perform(RestDocumentationRequestBuilders.get("/api/orders/{orderId}", 1L));

// then
resultActions.andExpect(status().isOk())
.andDo(document("order-get",
preprocessResponse(prettyPrint()),
pathParameters(
parameterWithName("orderId").description("주문 ID")
),
responseFields(
fieldWithPath("orderId").type(JsonFieldType.NUMBER).description("주문 ID"),
fieldWithPath("memberId").type(JsonFieldType.NUMBER).description("회원 ID"),
fieldWithPath("shopId").type(JsonFieldType.NUMBER).description("가게 ID"),
fieldWithPath("address").type(JsonFieldType.STRING).description("배달 도착 주소"),
fieldWithPath("requirement").type(JsonFieldType.STRING).description("요구사항"),
fieldWithPath("selectedMenus[].menuId").type(JsonFieldType.NUMBER).description("선택 메뉴 ID"),
fieldWithPath("selectedMenus[].quantity").type(JsonFieldType.NUMBER).description("선택 메뉴 수량"),
fieldWithPath("selectedMenus[].selectedOptionIds[]").type(JsonFieldType.ARRAY)
.description("선택 메뉴 옵션 ID 목록"),
fieldWithPath("price").type(JsonFieldType.NUMBER).description("선택 메뉴 총 가격")
)));
}

@DisplayName("주문 다건조회를 할 수 있다.")
@Test
void getOrders() throws Exception {
Expand Down
Loading