From 06296416277cf0753c3bcdbfc0afc599dd734838 Mon Sep 17 00:00:00 2001 From: pushedrumex Date: Thu, 21 Sep 2023 18:10:50 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20API=20=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/index.adoc | 551 ++++++++++++++++++ .../global/config/WebSecurityConfig.java | 3 +- .../nabmart/base/BaseControllerTest.java | 9 + .../controller/CartItemControllerTest.java | 2 +- .../controller/CategoryControllerTest.java | 24 +- .../controller/CouponControllerTest.java | 39 +- .../event/controller/EventControllerTest.java | 13 +- .../item/controller/ItemControllerTest.java | 19 +- .../order/controller/OrderControllerTest.java | 13 +- .../controller/PaymentControllerTest.java | 12 +- 10 files changed, 609 insertions(+), 76 deletions(-) create mode 100644 src/docs/asciidoc/index.adoc diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc new file mode 100644 index 000000000..3c25af2c4 --- /dev/null +++ b/src/docs/asciidoc/index.adoc @@ -0,0 +1,551 @@ +:doctype: book +:icons: font +:source-highlighter: highlightjs +:sectlinks: +:toc: left +:toclevels: 2 +:sectnums: + +ifndef::snippets[] +:snippets: ./build/generated-snippets +endif::[] + += Nabmart Application API Document + +== 회원(User) + +=== 회원 정보 조회 + +==== Request + +include::{snippets}/find-user/http-request.adoc[] + +==== Response + +include::{snippets}/find-user/http-response.adoc[] +include::{snippets}/find-user/response-fields.adoc[] + +=== 회원 탈퇴 + +==== Request + +include::{snippets}/delete-user/http-request.adoc[] + +==== Response + +include::{snippets}/delete-user/http-response.adoc[] + +== 상품(Item) + +=== 대카테고리 상품 목록 조회 + +==== Request + +include::{snippets}/find-items-by-main-category/http-request.adoc[] +include::{snippets}/find-items-by-main-category/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-items-by-main-category/http-response.adoc[] + +=== 소카테고리 상품 목록 조회 + +==== Request + +include::{snippets}/find-items-by-sub-category/http-request.adoc[] +include::{snippets}/find-items-by-sub-category/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-items-by-sub-category/http-response.adoc[] + +=== 상품 상세 조회 + +==== Request + +include::{snippets}/find-item-detail/http-request.adoc[] +include::{snippets}/find-item-detail/path-parameters.adoc[] + +==== Response + +include::{snippets}/find-item-detail/http-response.adoc[] +include::{snippets}/find-item-detail/response-fields.adoc[] + +=== 신상품 조회 + +==== Request + +include::{snippets}/find-new-items/http-request.adoc[] +include::{snippets}/find-new-items/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-new-items/http-response.adoc[] +include::{snippets}/find-new-items/response-fields.adoc[] + +=== 인기 상품 조회 + +==== Request + +include::{snippets}/find-hot-items/http-request.adoc[] +include::{snippets}/find-hot-items/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-hot-items/http-response.adoc[] +include::{snippets}/find-hot-items/response-fields.adoc[] + +=== 상품 수정 + +==== Request + +include::{snippets}/update-item/http-request.adoc[] +include::{snippets}/update-item/request-fields.adoc[] + +==== Response + +include::{snippets}/update-item/http-response.adoc[] + +=== 상품 등록 + +==== Request + +include::{snippets}/register-item/http-request.adoc[] +include::{snippets}/register-item/request-fields.adoc[] + +==== Response + +include::{snippets}/register-item/http-response.adoc[] + +=== 상품 삭제 + +==== Request + +include::{snippets}/delete-item/http-request.adoc[] +include::{snippets}/delete-item/path-parameters.adoc[] + +==== Response + +include::{snippets}/delete-item/http-response.adoc[] + +=== 신상품 조회 + +==== Request + +include::{snippets}/find-new-items/http-request.adoc[] +include::{snippets}/find-new-items/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-new-items/http-response.adoc[] +include::{snippets}/find-new-items/response-fields.adoc[] + +== 쿠폰(Coupon) + +=== 쿠폰 등록 + +==== Request + +include::{snippets}/register-coupon/http-request.adoc[] +include::{snippets}/register-coupon/request-fields.adoc[] + +==== Response + +include::{snippets}/register-coupon/http-response.adoc[] + +=== 쿠폰 발급 + +==== Request + +include::{snippets}/register-user-coupon/http-request.adoc[] +include::{snippets}/register-user-coupon/request-fields.adoc[] + +==== Response + +include::{snippets}/register-user-coupon/http-response.adoc[] + +=== 쿠폰 조회 + +==== Request + +include::{snippets}/find-coupons/http-request.adoc[] + +==== Response + +include::{snippets}/find-coupons/http-response.adoc[] +include::{snippets}/find-coupons/response-fields.adoc[] + +=== 발행된 쿠폰 조회 + +==== Request + +include::{snippets}/find-issued-coupons/http-request.adoc[] + +==== Response + +include::{snippets}/find-issued-coupons/http-response.adoc[] +include::{snippets}/find-issued-coupons/response-fields.adoc[] + +== 카테고리(Category) + +=== 대카테고리 등록 + +==== Request + +include::{snippets}/save-main-category/http-request.adoc[] +include::{snippets}/save-main-category/request-fields.adoc[] + +==== Response + +include::{snippets}/save-main-category/http-response.adoc[] + +=== 소카테고리 등록 + +==== Request + +include::{snippets}/save-sub-category/http-request.adoc[] +include::{snippets}/save-sub-category/request-fields.adoc[] + +==== Response + +include::{snippets}/save-sub-category/http-response.adoc[] + +=== 대카테고리 목록 조회 + +==== Request + +include::{snippets}/find-all-main-categories/http-request.adoc[] + +==== Response + +include::{snippets}/find-all-main-categories/http-response.adoc[] +include::{snippets}/find-all-main-categories/response-fields.adoc[] + +=== 소카테고리 목록 조회 + +==== Request + +include::{snippets}/find-all-sub-categories/http-request.adoc[] +include::{snippets}/find-all-sub-categories/path-parameters.adoc[] + +==== Response + +include::{snippets}/find-all-sub-categories/http-response.adoc[] +include::{snippets}/find-all-sub-categories/response-fields.adoc[] + +== 이벤트(Event) + +=== 이벤트 등록 + +==== Request + +include::{snippets}/register-event/http-request.adoc[] + +==== Response + +include::{snippets}/register-event/http-response.adoc[] + +=== 이벤트 목록 조회 + +==== Request + +include::{snippets}/find-events/http-request.adoc[] + +==== Response + +include::{snippets}/find-events/http-response.adoc[] +include::{snippets}/find-events/response-fields.adoc[] + +=== 이벤트 상세 조회 + +==== Request + +include::{snippets}/find-event-detail/http-request.adoc[] + +==== Response + +include::{snippets}/find-event-detail/http-response.adoc[] +include::{snippets}/find-event-detail/response-fields.adoc[] + +=== 이벤트 상품 등록 + +==== Request + +include::{snippets}/register-event-items/http-request.adoc[] + +==== Response + +include::{snippets}/register-event-items/http-response.adoc[] + +== 리뷰(Review) + +=== 리뷰 등록 + +==== Request + +include::{snippets}/register-review/http-request.adoc[] +include::{snippets}/register-review/request-fields.adoc[] + +==== Response + +include::{snippets}/register-review/http-response.adoc[] + +=== 리뷰 삭제 + +==== Request + +include::{snippets}/delete-review/http-request.adoc[] +include::{snippets}/delete-review/path-parameters.adoc[] + +==== Response + +include::{snippets}/delete-review/http-response.adoc[] + +=== 리뷰 수정 + +==== Request + +include::{snippets}/update-review/http-request.adoc[] +include::{snippets}/update-review/path-parameters.adoc[] + +==== Response + +include::{snippets}/update-review/http-response.adoc[] + +=== 회원 리뷰 목록 조회 + +==== Request + +include::{snippets}/find-reviews-by-user/http-request.adoc[] + +==== Response + +include::{snippets}/find-reviews-by-user/http-response.adoc[] +include::{snippets}/find-reviews-by-user/response-fields.adoc[] + +=== 상품 리뷰 목록 조회 + +==== Request + +include::{snippets}/find-reviews-by-item/http-request.adoc[] + +==== Response + +include::{snippets}/find-reviews-by-item/http-response.adoc[] +include::{snippets}/find-reviews-by-item/response-fields.adoc[] + +== 장바구니(Cart) + +=== 장바구니 상품 등록 + +==== Request + +include::{snippets}/register-cart-item/http-request.adoc[] +include::{snippets}/register-cart-item/request-fields.adoc[] + +==== Response + +include::{snippets}/register-cart-item/http-response.adoc[] + +=== 장바구니 상품 삭제 + +==== Request + +include::{snippets}/delete-cart-item/http-request.adoc[] +include::{snippets}/delete-cart-item/path-parameters.adoc[] + +==== Response + +include::{snippets}/delete-cart-item/http-response.adoc[] + +=== 장바구니 상품 수량 수정 + +==== Request + +include::{snippets}/update-cart-item/http-request.adoc[] +include::{snippets}/update-cart-item/path-parameters.adoc[] + +==== Response + +include::{snippets}/update-cart-item/http-response.adoc[] + +=== 장바구니 상품 목록 조회 + +==== Request + +include::{snippets}/find-cart-items/http-request.adoc[] + +==== Response + +include::{snippets}/find-cart-items/http-response.adoc[] +include::{snippets}/find-cart-items/response-fields.adoc[] + +== 주문(Order) + +=== 주문 상세 조회 + +==== Request + +include::{snippets}/find-order/http-request.adoc[] +include::{snippets}/find-order/path-parameters.adoc[] + +==== Response + +include::{snippets}/find-order/http-response.adoc[] +include::{snippets}/find-order/response-fields.adoc[] + +=== 주문 목록 조회 + +==== Request + +include::{snippets}/find-orders/http-request.adoc[] +include::{snippets}/find-orders/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-orders/http-response.adoc[] +include::{snippets}/find-orders/response-fields.adoc[] + +=== 주문 생성 + +==== Request + +include::{snippets}/create-order/http-request.adoc[] + +==== Response + +include::{snippets}/create-order/http-response.adoc[] +include::{snippets}/create-order/response-fields.adoc[] + +=== 주문 쿠폰 적용 + +==== Request + +include::{snippets}/update-order-by-coupon/http-request.adoc[] +include::{snippets}/update-order-by-coupon/path-parameters.adoc[] + +==== Response + +include::{snippets}/update-order-by-coupon/http-response.adoc[] +include::{snippets}/update-order-by-coupon/response-fields.adoc[] + +=== 주문 삭제 + +==== Request + +include::{snippets}/delete-order/http-request.adoc[] +include::{snippets}/delete-order/path-parameters.adoc[] + +==== Response + +include::{snippets}/delete-order/http-response.adoc[] + +== 결제(Payment) + +=== 결제 + +==== Request + +include::{snippets}/pay/http-request.adoc[] +include::{snippets}/pay/path-parameters.adoc[] + +==== Response + +include::{snippets}/pay/http-response.adoc[] +include::{snippets}/pay/response-fields.adoc[] + +=== 결제 성공 + +==== Request + +include::{snippets}/pay-success/http-request.adoc[] +include::{snippets}/pay-success/query-parameters.adoc[] + +==== Response + +include::{snippets}/pay-success/http-response.adoc[] +include::{snippets}/pay-success/response-fields.adoc[] + +=== 결제 실패 + +==== Request + +include::{snippets}/pay-fail/http-request.adoc[] +include::{snippets}/pay-fail/query-parameters.adoc[] + +==== Response + +include::{snippets}/pay-fail/http-response.adoc[] +include::{snippets}/pay-fail/response-fields.adoc[] + +== 배달(Delivery) + +=== 배달 현황 조회 + +==== Request + +include::{snippets}/find-delivery/http-request.adoc[] +include::{snippets}/find-delivery/path-parameters.adoc[] + +==== Response + +include::{snippets}/find-delivery/http-response.adoc[] +include::{snippets}/find-delivery/response-fields.adoc[] + +=== 배차 요청 + +==== Request + +include::{snippets}/accept-delivery/http-request.adoc[] +include::{snippets}/accept-delivery/path-parameters.adoc[] + +==== Response + +include::{snippets}/accept-delivery/http-response.adoc[] + +=== 배달 시작 + +==== Request + +include::{snippets}/start-delivery/http-request.adoc[] +include::{snippets}/start-delivery/path-parameters.adoc[] +include::{snippets}/start-delivery/request-fields.adoc[] + +==== Response + +include::{snippets}/start-delivery/http-response.adoc[] + +=== 배달 완료 + +==== Request + +include::{snippets}/complete-delivery/http-request.adoc[] +include::{snippets}/complete-delivery/path-parameters.adoc[] + +==== Response + +include::{snippets}/complete-delivery/http-response.adoc[] + +=== 대기상태 배달 목록 조회 + +==== Request + +include::{snippets}/find-waiting-deliveries/http-request.adoc[] +include::{snippets}/find-waiting-deliveries/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-waiting-deliveries/http-response.adoc[] +include::{snippets}/find-waiting-deliveries/response-fields.adoc[] + +=== 라이더 배달 목록 조회 + +==== Request + +include::{snippets}/find-rider-deliveries/http-request.adoc[] +include::{snippets}/find-rider-deliveries/query-parameters.adoc[] + +==== Response + +include::{snippets}/find-rider-deliveries/http-response.adoc[] +include::{snippets}/find-rider-deliveries/response-fields.adoc[] diff --git a/src/main/java/com/prgrms/nabmart/global/config/WebSecurityConfig.java b/src/main/java/com/prgrms/nabmart/global/config/WebSecurityConfig.java index 60d3cc4b6..68e023f52 100644 --- a/src/main/java/com/prgrms/nabmart/global/config/WebSecurityConfig.java +++ b/src/main/java/com/prgrms/nabmart/global/config/WebSecurityConfig.java @@ -69,7 +69,8 @@ private RequestMatcher[] requestPermitAll() { antMatcher(POST, "/api/v1/riders/**"), antMatcher(GET, "/api/v1/categories/**"), antMatcher(GET, "/api/v1/items/**"), - antMatcher(GET, "/api/v1/events/**")); + antMatcher(GET, "/api/v1/events/**"), + antMatcher(GET, "/docs/**")); return requestMatchers.toArray(RequestMatcher[]::new); } diff --git a/src/test/java/com/prgrms/nabmart/base/BaseControllerTest.java b/src/test/java/com/prgrms/nabmart/base/BaseControllerTest.java index 28c3cf31c..769b2c2cc 100644 --- a/src/test/java/com/prgrms/nabmart/base/BaseControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/base/BaseControllerTest.java @@ -1,5 +1,9 @@ package com.prgrms.nabmart.base; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import com.fasterxml.jackson.databind.ObjectMapper; @@ -120,6 +124,11 @@ void mockMvcSetUp( this.mockMvc = MockMvcBuilders.webAppContextSetup(context) .alwaysDo(print()) .alwaysDo(restDocs) + .alwaysDo( + document("{method-name}", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint())) + ) .addFilter(new CharacterEncodingFilter("UTF-8", true)) .addFilter(new JwtAuthenticationFilter(jwtAuthenticationProvider)) .apply(MockMvcRestDocumentation.documentationConfiguration(provider)) diff --git a/src/test/java/com/prgrms/nabmart/domain/cart/controller/CartItemControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/cart/controller/CartItemControllerTest.java index 6dd5c1151..93503a36f 100644 --- a/src/test/java/com/prgrms/nabmart/domain/cart/controller/CartItemControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/cart/controller/CartItemControllerTest.java @@ -130,7 +130,7 @@ class FindCartItemsAPITest { @Test @DisplayName("성공") - void findCartItemsByUserId() throws Exception { + void findCartItems() throws Exception { // given Long userId = 1L; Long cartId = 1L; diff --git a/src/test/java/com/prgrms/nabmart/domain/category/controller/CategoryControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/category/controller/CategoryControllerTest.java index 5f3dbd8be..f28f1faba 100644 --- a/src/test/java/com/prgrms/nabmart/domain/category/controller/CategoryControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/category/controller/CategoryControllerTest.java @@ -4,10 +4,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.restdocs.payload.JsonFieldType.ARRAY; import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; import static org.springframework.restdocs.payload.JsonFieldType.STRING; @@ -53,9 +50,7 @@ public void saveMainCategory() throws Exception { .andExpect(status().isCreated()) .andExpect(header().string("Location", "/api/v1/main-categories/1")) .andDo(print()) - .andDo(document( - "Save MainCategory", - requestFields( + .andDo(restDocs.document(requestFields( fieldWithPath("name").type(STRING) .description("대카테고리명") ) @@ -85,9 +80,7 @@ public void saveSubCategory() throws Exception { .andExpect(status().isCreated()) .andExpect(header().string("Location", "/api/v1/sub-categories/1")) .andDo(print()) - .andDo(document( - "Save SubCategory", - requestFields( + .andDo(restDocs.document(requestFields( fieldWithPath("mainCategoryId").type(NUMBER) .description("대카테고리 Id"), fieldWithPath("name").type(STRING) @@ -115,9 +108,7 @@ public void findAllMainCategories() throws Exception { .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) - .andDo(document( - "Find All MainCategories", - responseFields( + .andDo(restDocs.document(responseFields( fieldWithPath("mainCategoryNames").type(ARRAY) .description("대카테고리 리스트") ) @@ -131,7 +122,7 @@ class findSubCategoriesApi { @Test @DisplayName("성공") - public void findSubCategories() throws Exception { + public void findAllSubCategories() throws Exception { // Given Long mainCategoryId = 1L; FindSubCategoriesResponse subCategoriesResponse = CategoryFixture.findSubCategoriesResponse(); @@ -142,12 +133,7 @@ public void findSubCategories() throws Exception { mockMvc.perform(get("/api/v1/categories/{mainCategoryId}", mainCategoryId) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andDo(document( - "Find SubCategories By MainCategory", - preprocessRequest( - prettyPrint() - ), - pathParameters( + .andDo(restDocs.document(pathParameters( parameterWithName("mainCategoryId").description("대카테고리 Id") ), responseFields( diff --git a/src/test/java/com/prgrms/nabmart/domain/coupon/controller/CouponControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/coupon/controller/CouponControllerTest.java index 67e353a11..45c6f6769 100644 --- a/src/test/java/com/prgrms/nabmart/domain/coupon/controller/CouponControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/coupon/controller/CouponControllerTest.java @@ -2,9 +2,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.restdocs.payload.JsonFieldType.ARRAY; import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; import static org.springframework.restdocs.payload.JsonFieldType.STRING; @@ -59,20 +56,16 @@ void RegisterCoupon() throws Exception { .andExpect(status().isCreated()) .andExpect(header().string("Location", "/api/v1/coupons/1")) .andDo(print()) - .andDo(document("Register coupon", - preprocessRequest( - prettyPrint() - ), - requestFields( - fieldWithPath("name").type(STRING).description("couponName"), - fieldWithPath("discount").type(NUMBER) - .description("discount"), - fieldWithPath("description").type(STRING) - .description("couponDescription"), - fieldWithPath("minOrderPrice").type(NUMBER) - .description("minOrderPrice"), - fieldWithPath("endAt").type(STRING) - .description("endAt (yyyy-MM-dd)")) + .andDo(restDocs.document(requestFields( + fieldWithPath("name").type(STRING).description("couponName"), + fieldWithPath("discount").type(NUMBER) + .description("discount"), + fieldWithPath("description").type(STRING) + .description("couponDescription"), + fieldWithPath("minOrderPrice").type(NUMBER) + .description("minOrderPrice"), + fieldWithPath("endAt").type(STRING) + .description("endAt (yyyy-MM-dd)")) ) ); } @@ -103,14 +96,10 @@ void RegisterUserCoupon() throws Exception { .andExpect(status().isCreated()) .andExpect(header().string("Location", "/api/v1/my-coupons/1")) .andDo(print()) - .andDo(document("Register userCoupon", - preprocessRequest( - prettyPrint() - ), - requestFields( - fieldWithPath("userId").type(NUMBER).description("userId"), - fieldWithPath("couponId").type(NUMBER) - .description("couponId")) + .andDo(restDocs.document(requestFields( + fieldWithPath("userId").type(NUMBER).description("userId"), + fieldWithPath("couponId").type(NUMBER) + .description("couponId")) ) ); } diff --git a/src/test/java/com/prgrms/nabmart/domain/event/controller/EventControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/event/controller/EventControllerTest.java index 285a74770..2e3427083 100644 --- a/src/test/java/com/prgrms/nabmart/domain/event/controller/EventControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/event/controller/EventControllerTest.java @@ -2,9 +2,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; 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.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -48,8 +49,7 @@ public void registerEvent() throws Exception { // Then resultActions.andExpect(status().isCreated()) - .andDo(document("Register Event" - )); + .andDo(restDocs.document()); } } @@ -74,7 +74,7 @@ public void findEvents() throws Exception { // Then resultActions.andExpect(status().isOk()) - .andDo(document("Find Events", + .andDo(restDocs.document( responseFields( fieldWithPath("events[].eventId").type(JsonFieldType.NUMBER) .description("이벤트 ID"), @@ -118,7 +118,7 @@ public void findEventDetail() throws Exception { // Then resultActions.andExpect(status().isOk()) - .andDo(document("Find Event Detail", + .andDo(restDocs.document( responseFields( fieldWithPath("event.eventId").type(JsonFieldType.NUMBER) .description("이벤트 ID"), @@ -167,8 +167,7 @@ public void registerEventItems() throws Exception { // Then resultActions.andExpect(status().isCreated()) - .andDo(document("Register Event Items" - )); + .andDo(restDocs.document()); } } } diff --git a/src/test/java/com/prgrms/nabmart/domain/item/controller/ItemControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/item/controller/ItemControllerTest.java index fcadb97a5..4cecee3f7 100644 --- a/src/test/java/com/prgrms/nabmart/domain/item/controller/ItemControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/item/controller/ItemControllerTest.java @@ -3,7 +3,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; @@ -120,7 +119,7 @@ public void findItemDetail() throws Exception { // Then resultActions.andExpect(status().isOk()) - .andDo(document("Find Item Detail", + .andDo(restDocs.document( pathParameters( parameterWithName("itemId").description("상품 ID") ), @@ -173,7 +172,7 @@ public void findNewItems() throws Exception { // Then resultActions.andExpect(status().isOk()) - .andDo(document("Find New Items", + .andDo(restDocs.document( queryParameters( parameterWithName("lastItemId").description("마지막에 조회한 아이템의 특성값"), parameterWithName("lastItemId").description("마지막에 조회한 아이템 ID"), @@ -225,7 +224,7 @@ public void findHotItems() throws Exception { // Then resultActions.andExpect(status().isOk()) - .andDo(document("Find Hot Items", + .andDo(restDocs.document( queryParameters( parameterWithName("lastItemId").description("마지막에 조회한 아이템의 특성값"), parameterWithName("lastItemId").description("마지막에 조회한 아이템 ID"), @@ -273,8 +272,7 @@ public void updateItem() throws Exception { // Then resultActions.andExpect(status().isNoContent()) - .andDo(document( - "Update Item", + .andDo(restDocs.document( requestFields( fieldWithPath("name").type(STRING) .description("상품명"), @@ -317,8 +315,7 @@ public void registerItem() throws Exception { // Then resultActions.andExpect(status().isCreated()) - .andDo(document( - "Register Item", + .andDo(restDocs.document( requestFields( fieldWithPath("name").type(STRING) .description("상품명"), @@ -359,8 +356,7 @@ public void deleteItem() throws Exception { // Then resultActions.andExpect(status().isNoContent()) - .andDo(document( - "Delete Item", + .andDo(restDocs.document( pathParameters( parameterWithName("itemId").description("상품 ID") )) @@ -380,7 +376,6 @@ public void findNewItemsWithRedis() throws Exception { // Given given(itemService.findNewItemsWithRedis(any())).willReturn(findNewItemsResponse); - // When ResultActions resultActions = mockMvc.perform( get("/api/v1/items/new-items") @@ -392,7 +387,7 @@ public void findNewItemsWithRedis() throws Exception { // Then resultActions.andExpect(status().isOk()) - .andDo(document("Find New Items with Redis", + .andDo(restDocs.document( queryParameters( parameterWithName("lastIdx").description("마지막에 조회한 아이템의 특성값"), parameterWithName("lastItemId").description("마지막에 조회한 아이템 ID"), diff --git a/src/test/java/com/prgrms/nabmart/domain/order/controller/OrderControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/order/controller/OrderControllerTest.java index 6f77c5413..53ea443c4 100644 --- a/src/test/java/com/prgrms/nabmart/domain/order/controller/OrderControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/order/controller/OrderControllerTest.java @@ -11,7 +11,6 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; @@ -68,7 +67,7 @@ void findOrder() throws Exception { // then result .andExpect(status().isOk()) - .andDo(document("get-order", + .andDo(restDocs.document( pathParameters( parameterWithName("orderId").description("주문 ID") ), @@ -108,7 +107,7 @@ void findOrders() throws Exception { // then result .andExpect(status().isOk()) - .andDo(document("get-orders", + .andDo(restDocs.document( queryParameters( parameterWithName("page").description("페이지 번호") ), @@ -174,7 +173,7 @@ class UpdateOrderByCoupon { @Test @DisplayName("성공") - void createOrder() throws Exception { + void updateOrderByCoupon() throws Exception { // given User user = user(); UserCoupon userCoupon = userCoupon(user); @@ -194,6 +193,9 @@ void createOrder() throws Exception { result .andExpect(status().isOk()) .andDo(restDocs.document( + pathParameters( + parameterWithName("orderId").description("주문 ID") + ), responseFields( fieldWithPath("totalPrice").type(NUMBER).description("쿠폰 적용후 총 가격"), fieldWithPath("discountPrice").type(NUMBER).description("쿠폰 할인 금액") @@ -221,6 +223,9 @@ void deleteOrder() throws Exception { result .andExpect(status().isNoContent()) .andDo(restDocs.document( + pathParameters( + parameterWithName("orderId").description("주문 ID") + ) )); } } diff --git a/src/test/java/com/prgrms/nabmart/domain/payment/controller/PaymentControllerTest.java b/src/test/java/com/prgrms/nabmart/domain/payment/controller/PaymentControllerTest.java index d5041f429..0895e72ec 100644 --- a/src/test/java/com/prgrms/nabmart/domain/payment/controller/PaymentControllerTest.java +++ b/src/test/java/com/prgrms/nabmart/domain/payment/controller/PaymentControllerTest.java @@ -4,7 +4,6 @@ import static com.prgrms.nabmart.domain.payment.support.PaymentDtoFixture.paymentRequestResponse; import static com.prgrms.nabmart.domain.user.support.UserFixture.userWithUserId; import static org.mockito.Mockito.when; -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.JsonFieldType.NUMBER; @@ -43,7 +42,7 @@ class payTest { @Test @DisplayName("성공") - void postPay() throws Exception { + void pay() throws Exception { // given User user = userWithUserId(); Order order = pendingOrder(1, user); @@ -65,7 +64,7 @@ void postPay() throws Exception { // then result .andExpect(status().isOk()) - .andDo(document("post-pay", + .andDo(restDocs.document( pathParameters( parameterWithName("orderId").description("주문 ID") ), @@ -111,8 +110,7 @@ void paySuccess() throws Exception { // then result .andExpect(status().isOk()) - .andDo(document("get-pay-success", - queryParameters( + .andDo(restDocs.document(queryParameters( parameterWithName("orderId").description("주문 ID"), parameterWithName("paymentKey").description("결제 키"), parameterWithName("amount").description("금액") @@ -131,7 +129,7 @@ class payFailTest { @Test @DisplayName("성공") - void pay() throws Exception { + void payFail() throws Exception { // given User user = userWithUserId(); Order order = pendingOrder(1, user); @@ -151,7 +149,7 @@ void pay() throws Exception { // then result .andExpect(status().isOk()) - .andDo(document("get-pay-fail", + .andDo(restDocs.document( queryParameters( parameterWithName("orderId").description("주문 ID"), parameterWithName("message").description("에러 메시지")