#33 tdd(order-service): payment - api test
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.example.productorderservice.payment;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/payments")
|
||||
@RequiredArgsConstructor
|
||||
public class PaymentController {
|
||||
|
||||
private final PaymentService paymentService;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Void> payment(@RequestBody final PaymentRequest paymentRequest) {
|
||||
paymentService.payment(paymentRequest);
|
||||
return ResponseEntity.status(HttpStatus.OK).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.example.productorderservice.payment;
|
||||
|
||||
import com.example.productorderservice.ApiTest;
|
||||
import com.example.productorderservice.order.OrderSteps;
|
||||
import com.example.productorderservice.product.ProductSteps;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
class PaymentApiTest extends ApiTest {
|
||||
|
||||
@Test
|
||||
void 상품주문() {
|
||||
ProductSteps.상품등록요청(ProductSteps.상품등록요청_생성());
|
||||
OrderSteps.상품주문요청(OrderSteps.상품주문요청_생성());
|
||||
final var request = PaymentSteps.주문결제요청_생성();
|
||||
|
||||
final var response = PaymentSteps.주문결제요청(request);
|
||||
|
||||
Assertions.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.example.productorderservice.payment;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
public class PaymentSteps {
|
||||
|
||||
public static PaymentRequest 주문결제요청_생성() {
|
||||
@@ -7,4 +12,14 @@ public class PaymentSteps {
|
||||
final String cardNumber = "1234-1234-1234-1234";
|
||||
return new PaymentRequest(orderId, cardNumber);
|
||||
}
|
||||
|
||||
public static ExtractableResponse<Response> 주문결제요청(PaymentRequest request) {
|
||||
return RestAssured.given().log().all()
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.body(request)
|
||||
.when()
|
||||
.post("/payments")
|
||||
.then().log().all()
|
||||
.extract();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user