Skip to content

Commit

Permalink
Merge pull request #132 from prgrms-be-devcourse/HIMIN-229--byeonggon…
Browse files Browse the repository at this point in the history
…-restdocs-order-get

[HIMIN-228] test : 주문 단건 조회 restdocs 추가
  • Loading branch information
Curry4182 committed Sep 22, 2023
2 parents fb3ac9d + 9f55365 commit 7cd4679
Showing 1 changed file with 33 additions and 0 deletions.
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

0 comments on commit 7cd4679

Please sign in to comment.