-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-추가된 내용 : 1. 세션에 orderId, amount 값을 임시 저장한 것이 제대로 저장되었는지 테스트 이유 : 결제 최종 승인 요청 전에 값이 변조되지 않았는지 검증하기 위함 미흡 : 결제 요청 받았을 때, 세션에 값이 저장되지 않았을 경우에 대한 예외 처리 미완 테스트 코드에 대한 부족함이 느껴져 찜찜함이 있다.
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/test/java/com/tasksprints/auction/api/PaymentControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.tasksprints.auction.api; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.tasksprints.auction.api.payment.PaymentController; | ||
import com.tasksprints.auction.common.constant.ApiResponseMessages; | ||
import com.tasksprints.auction.domain.payment.dto.request.PaymentRequest; | ||
import com.tasksprints.auction.domain.payment.service.PaymentService; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mock.web.MockHttpSession; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.math.BigDecimal; | ||
|
||
|
||
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; | ||
|
||
@WebMvcTest(PaymentController.class) | ||
@MockBean(JpaMetamodelMappingContext.class) | ||
public class PaymentControllerTest { | ||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private PaymentService paymentService; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@MockBean MockHttpSession session; | ||
@Test | ||
@DisplayName("결제 전 임시 값 저장") | ||
public void 결제_전_임시_값_저장() throws Exception { | ||
PaymentRequest.Prepare prepareRequest = new PaymentRequest.Prepare("test1", BigDecimal.valueOf(1000.00)); | ||
|
||
mockMvc.perform(post("/api/v1/payment/prepare") | ||
.session(session) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(prepareRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.message").value(ApiResponseMessages.PAYMENT_PREPARED_SUCCESS)); | ||
|
||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/com/tasksprints/auction/domain/payment/repository/PaymentRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.tasksprints.auction.domain.payment.repository; | ||
|
||
public class PaymentRepositoryTest { | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/tasksprints/auction/domain/payment/service/PaymentServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.tasksprints.auction.domain.payment.service; | ||
|
||
import com.tasksprints.auction.domain.payment.dto.request.PaymentRequest; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
|
||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.mock.web.MockHttpSession; | ||
|
||
import java.math.BigDecimal; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class PaymentServiceImplTest { | ||
|
||
@InjectMocks | ||
private PaymentServiceImpl paymentService; | ||
|
||
// @Mock | ||
// private MockHttpSession MockSession; | ||
|
||
@Nested | ||
@DisplayName("결제 전 세션 임시 저장 테스트") | ||
class 임시_저장_테스트{ | ||
@Test | ||
void 결제_요청을_받았을_때_세션에_값이_저장되면_성공한다 () { | ||
//given | ||
MockHttpSession session = new MockHttpSession(); | ||
String orderId = "testOrderId"; | ||
BigDecimal amount = BigDecimal.valueOf(1000.00); | ||
PaymentRequest.Prepare prepareRequest = new PaymentRequest.Prepare(orderId, amount); | ||
//when | ||
paymentService.prepare(session, prepareRequest); | ||
//then | ||
assertThat(session.getAttribute("orderId")).isEqualTo(orderId); | ||
assertThat(session.getAttribute("amount")).isEqualTo(amount); | ||
} | ||
@Test | ||
void 결제_요청을_받았을_때_세션에_값이_저장되지_않으면_예외_처리 () { | ||
//given | ||
//when | ||
//then | ||
} | ||
} | ||
} |