Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ asciidoctor.doFirst {
}

asciidoctor {
baseDirFollowsSourceFile() // include ๊ธฐ์ค€์„ index.adoc ์œ„์น˜๋กœ ๊ณ ์ •
sources { include 'index.adoc' } // index.adoc์„ ์ง„์ž…์ ์œผ๋กœ
attributes('snippets': snippetsDir.get().asFile)
configurations 'asciidoctorExt'
dependsOn test
Expand Down
1 change: 0 additions & 1 deletion src/docs/asciidoc/_auth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

์š”์ฒญ ๋ณธ๋ฌธ:
include::{snippets}/member-login/request-fields.adoc[]

์‘๋‹ต ๋ณธ๋ฌธ:
include::{snippets}/member-login/response-fields.adoc[]

Expand Down
11 changes: 11 additions & 0 deletions src/docs/asciidoc/_payment.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
== ๊ฒฐ์ œ API

=== 1. ๊ฒฐ์ œ ์š”์ฒญ
`POST /payment`

์š”์ฒญ ๋ณธ๋ฌธ:
include::{snippets}/payment-create/request-fields.adoc[]
์‘๋‹ต ๋ณธ๋ฌธ:
include::{snippets}/payment-create/response-fields.adoc[]
์‘๋‹ต:
include::{snippets}/payment-create/http-response.adoc[]
1 change: 1 addition & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ include::_delivery_address.adoc[]
include::_discount.adoc[]

include::_deliverypolicy.adoc[]
include::_payment.adoc[]
// include::_product.adoc[]

Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ public CustomerOrderResponse prepareOrder(CustomerOrderRequest request) {
// ์ฟ ํฐ ๋ฏธ๋ฆฌ ์ฐจ๊ฐ
appliedCouponService.createAppliedCouponList(payment, request.couponIdList());

// ์ฃผ๋ฌธ ์—”ํ‹ฐํ‹ฐ ์ƒ์„ฑ PENDING ์ƒํƒœ
String orderNum = "ORD-" + (int) ((Math.random() * 10000000));
// ์ฃผ๋ฌธ ์—”ํ‹ฐํ‹ฐ ์ƒ์„ฑ PENDING ์ƒํƒœ 8 ์ž๋ฆฌ ๋žœ๋ค๊ฐ’
String orderNum = "ORD-" + (int) ((Math.random() * 100000000));

Order order =
Order.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.irum.come2us.domain.payment;

import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.irum.come2us.domain.payment.application.service.PaymentService;
import com.irum.come2us.domain.payment.presentation.controller.PaymentController;
import com.irum.come2us.domain.payment.presentation.dto.request.PaymentRequest;
import com.irum.come2us.domain.payment.presentation.dto.response.PaymentResponse;
import com.irum.come2us.global.config.SecurityTestConfig;
import com.irum.come2us.global.config.TestConfig;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(controllers = PaymentController.class)
@AutoConfigureRestDocs
@Import({SecurityTestConfig.class, TestConfig.class})
public class PaymentControllerTest {

@Autowired private MockMvc mockMvc;
@MockitoBean private PaymentService paymentService;
@Autowired private ObjectMapper objectMapper;

@Test
@DisplayName("๊ฒฐ์ œ ๋“ฑ๋ก API")
void paymentCreateApiTest() throws Exception {
UUID orderId = UUID.randomUUID();
String orderNum = "ORD-777777";
int totalAmount = 10000;
PaymentRequest request = new PaymentRequest("tossOrderId", "tosspaymentkey", orderId);
PaymentResponse response = new PaymentResponse(orderNum, totalAmount);

Mockito.when(paymentService.createPayment(request)).thenReturn(response);

mockMvc.perform(
post("/payment")
.with(csrf())
.with(user("100").roles("CUSTOMER"))
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.status").value(HttpStatus.OK.value()))
.andExpect(jsonPath("$.data.orderNum").value(orderNum))
.andExpect(jsonPath("$.data.totalAmount").value(totalAmount))
.andDo(
document(
"payment-create",
requestFields(
fieldWithPath("tossOrderId")
.description("ํ† ์Šค์—์„œ ๋ฐœ๊ธ‰ํ•ด์ฃผ๋Š” orderId"),
fieldWithPath("tossPaymentKey")
.description("ํ† ์Šค์—์„œ ๋ฐœ๊ธ‰ํ•ด์ฃผ๋Š” paymentKey"),
fieldWithPath("orderId").description("๊ฒฐ์ œํ•˜๋ ค๋Š” ์ฃผ๋ฌธ id")),
responseFields(
fieldWithPath("success").description("์„ฑ๊ณต ์—ฌ๋ถ€"),
fieldWithPath("status").description("HTTP ์ƒํƒœ ์ฝ”๋“œ"),
fieldWithPath("timestamp")
.description("์‘๋‹ต ์ƒ์„ฑ ์‹œ๊ฐ (ISO-8601)"),
subsectionWithPath("data").description("์‘๋‹ต ๋ฐ์ดํ„ฐ ๊ฐ์ฒด")),
responseFields(
beneathPath("data").withSubsectionId("data"),
fieldWithPath("orderNum").description("์ฃผ๋ฌธ ๋ฒˆํ˜ธ"),
fieldWithPath("totalAmount").description("์‹ค ๊ฒฐ์ œ ๊ธˆ์•ก"))));
}
}