Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 결제 테스트코드 작성 #245

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ private void validateRefundReceiveAccount(PaymentMethod paymentMethod, PaymentSt
}

public Integer calculateRefundAmount(Booking booking) {
Payment payment = booking.getPayment();
if (booking.isPaid())
return booking.getAmount();

Payment payment = booking.getPayment();
return (payment.getMethod() == PaymentMethod.VIRTUAL_ACCOUNT &&
else if (payment.getMethod() == PaymentMethod.VIRTUAL_ACCOUNT &&
payment.getStatus() == PaymentStatus.WAITING_FOR_DEPOSIT)
? null
: 0;
return null;
else
throw new BookingException(BookingErrorCode.UNCANCELABLE_BOOKING);
}

private Member getMemberById(Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public record PaymentCancelDetailResponse(
String cancelReason,
int cancelAmount,
Integer cancelAmount,
String canceledAt
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public record PaymentCancelResponse(
String paymentKey,
String orderId,
String orderName, // 토스페이먼츠에서 제공해주는 값이라 booing으로 변경x
String orderName, // 토스페이먼츠에서 제공해주는 값이라 booking으로 변경x
String method,
int totalAmount,
String status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public PaymentSuccessResponse successPayment(String paymentKey, String bookingId
return response;
}

public PaymentFailResponse failPayment(String errorCode, String errorMessage, String bookingId) {//TODO : booking 상태값 변경
public PaymentFailResponse failPayment(String errorCode, String errorMessage, String bookingId) {
Payment payment = getPaymentByBookingId(bookingId);
payment.updateStatus(PaymentStatus.ABORTED);
payment.updateFailedMsg(errorMessage);
Expand Down Expand Up @@ -108,9 +108,8 @@ public void confirmVirtualAccountIncome(ConfirmVirtualIncomeRequest request) {
}

private Booking getBookingById(String bookingId) {
Booking booking = bookingRepository.findWithPaymentById(bookingId)
return bookingRepository.findWithPaymentById(bookingId)
.orElseThrow(() -> new BookingException(BookingErrorCode.BOOKING_NOT_FOUND));
return booking;
}

private Payment getPaymentByPaymentKey(String paymentKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pgms.apibooking.fake;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import com.pgms.apibooking.domain.payment.dto.request.PaymentCancelRequest;
Expand All @@ -25,7 +26,8 @@
@RequiredArgsConstructor
public class TossPaymentServiceFake implements TossPaymentService {

private static final LocalDateTime NOW = LocalDateTime.now();
OffsetDateTime NOW = OffsetDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");

private final BookingRepository bookingRepository;
private final PaymentRepository paymentRepository;
Expand All @@ -44,8 +46,8 @@ public PaymentSuccessResponse requestTossPaymentConfirmation(PaymentConfirmReque
booking.getPayment().getMethod().getDescription(),
request.amount(),
PaymentStatus.DONE.name(),
NOW.toString(),
NOW.toString(),
NOW.format(formatter),
NOW.format(formatter),
new PaymentCardResponse(
"61",
"12341234****123*",
Expand All @@ -63,14 +65,14 @@ public PaymentSuccessResponse requestTossPaymentConfirmation(PaymentConfirmReque
booking.getPayment().getMethod().getDescription(),
request.amount(),
PaymentStatus.DONE.name(),
NOW.toString(),
NOW.toString(),
NOW.format(formatter),
NOW.format(formatter),
null,
new PaymentVirtualResponse(
"X6505636518308",
"20",
"박토스",
NOW.plusDays(7).toString()
NOW.plusDays(7).format(formatter)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ void setup() {
}

@Test
void 결제_수단이_가상게좌인데_환불계좌정보가_없다면_예매를_취소할_수_없다() {
void 결제_수단이_가상계좌이고_입금되었는데_환불계좌정보가_없다면_예매를_취소할_수_없다() {
// given
LocalDateTime eventStartedAt = NOW.plusDays(2);
LocalDateTime eventEndedAt = NOW.plusDays(2).plusMinutes(120);
Expand Down
Loading