Skip to content

Commit

Permalink
Test : 세션에 값 임시 저장 테스트 추가
Browse files Browse the repository at this point in the history
-추가된 내용 :
1. 세션에 orderId, amount 값을 임시 저장한 것이 제대로 저장되었는지 테스트
이유 : 결제 최종 승인 요청 전에 값이 변조되지 않았는지 검증하기 위함

미흡 :
결제 요청 받았을 때, 세션에 값이 저장되지 않았을 경우에 대한 예외 처리 미완
  • Loading branch information
na0th committed Oct 16, 2024
1 parent e4213bc commit 5e7454b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tasksprints.auction.domain.payment.repository;

public class PaymentRepositoryTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.tasksprints.auction.domain.payment.service;

import com.tasksprints.auction.domain.payment.dto.request.PaymentRequest;
import jakarta.servlet.http.HttpSession;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
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.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;

import java.math.BigDecimal;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class PaymentServiceImplTest {
@InjectMocks
private PaymentServiceImpl paymentService;

@Mock
private HttpSession session;

@Nested
@DisplayName("결제 전 세션 임시 저장 테스트")
class 임시_저장_테스트{
@Test
void 결제_요청을_받았을__세션에_값이_저장되면_성공한다 () {
//given
String orderId = "testOrderId";
BigDecimal amount = BigDecimal.valueOf(1000.00);
PaymentRequest.Prepare prepareRequest = new PaymentRequest.Prepare(orderId, amount);

when(session.getAttribute("orderId")).thenReturn(orderId);
when(session.getAttribute("amount")).thenReturn(amount);
//when
paymentService.prepare(session, prepareRequest);
//then
verify(session).setAttribute("orderId", orderId);
verify(session).setAttribute("amount", amount);

assertThat(orderId).isEqualTo(session.getAttribute("orderId"));
assertThat(amount).isEqualTo(session.getAttribute("amount"));
}
@Test
void 결제_요청을_받았을__세션에_값이_저장되지_않으면_예외_처리 () {
//given
//when
//then
}
}
}

0 comments on commit 5e7454b

Please sign in to comment.