generated from pricelees/issue-pr-template
[#16] Reservation 도메인 코드 코틀린 마이그레이션 #17
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
|||||||
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
|
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||||
import roomescape.reservation.web.ReservationResponse
|
import roomescape.reservation.web.ReservationResponse
|
||||||
|
import roomescape.reservation.web.toResponse
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
class PaymentApprove {
|
class PaymentApprove {
|
||||||
@ -60,6 +61,6 @@ fun PaymentEntity.toReservationPaymentResponse(): ReservationPaymentResponse = R
|
|||||||
orderId = this.orderId,
|
orderId = this.orderId,
|
||||||
paymentKey = this.paymentKey,
|
paymentKey = this.paymentKey,
|
||||||
totalAmount = this.totalAmount,
|
totalAmount = this.totalAmount,
|
||||||
reservation = ReservationResponse.from(this.reservation),
|
reservation = this.reservation.toResponse(),
|
||||||
approvedAt = this.approvedAt
|
approvedAt = this.approvedAt
|
||||||
)
|
)
|
||||||
@ -1,56 +1,58 @@
|
|||||||
package roomescape.reservation.business;
|
package roomescape.reservation.business
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import org.springframework.stereotype.Service;
|
import roomescape.payment.business.PaymentService
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import roomescape.payment.web.PaymentApprove
|
||||||
|
import roomescape.payment.web.PaymentCancel
|
||||||
import roomescape.payment.business.PaymentService;
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
import roomescape.payment.web.PaymentApprove;
|
import roomescape.reservation.web.ReservationRequest
|
||||||
import roomescape.payment.web.PaymentCancel;
|
import roomescape.reservation.web.ReservationResponse
|
||||||
import roomescape.payment.web.ReservationPaymentResponse;
|
import java.time.OffsetDateTime
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity;
|
|
||||||
import roomescape.reservation.web.ReservationRequest;
|
|
||||||
import roomescape.reservation.web.ReservationResponse;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class ReservationWithPaymentService {
|
class ReservationWithPaymentService(
|
||||||
|
private val reservationService: ReservationService,
|
||||||
|
private val paymentService: PaymentService
|
||||||
|
) {
|
||||||
|
fun addReservationWithPayment(
|
||||||
|
request: ReservationRequest,
|
||||||
|
paymentInfo: PaymentApprove.Response,
|
||||||
|
memberId: Long
|
||||||
|
): ReservationResponse {
|
||||||
|
val reservation: ReservationEntity = reservationService.addReservation(request, memberId)
|
||||||
|
|
||||||
private final ReservationService reservationService;
|
return paymentService.savePayment(paymentInfo, reservation)
|
||||||
private final PaymentService paymentService;
|
.reservation
|
||||||
|
|
||||||
public ReservationWithPaymentService(ReservationService reservationService,
|
|
||||||
PaymentService paymentService) {
|
|
||||||
this.reservationService = reservationService;
|
|
||||||
this.paymentService = paymentService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReservationResponse addReservationWithPayment(ReservationRequest request,
|
fun saveCanceledPayment(
|
||||||
PaymentApprove.Response paymentInfo,
|
cancelInfo: PaymentCancel.Response,
|
||||||
Long memberId) {
|
approvedAt: OffsetDateTime,
|
||||||
ReservationEntity reservation = reservationService.addReservation(request, memberId);
|
paymentKey: String
|
||||||
ReservationPaymentResponse reservationPaymentResponse = paymentService.savePayment(paymentInfo, reservation);
|
) {
|
||||||
|
paymentService.saveCanceledPayment(cancelInfo, approvedAt, paymentKey)
|
||||||
return reservationPaymentResponse.reservation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCanceledPayment(PaymentCancel.Response cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
fun removeReservationWithPayment(
|
||||||
paymentService.saveCanceledPayment(cancelInfo, approvedAt, paymentKey);
|
reservationId: Long,
|
||||||
}
|
memberId: Long
|
||||||
|
): PaymentCancel.Request {
|
||||||
|
val paymentCancelRequest = paymentService.cancelPaymentByAdmin(reservationId)
|
||||||
|
reservationService.removeReservationById(reservationId, memberId)
|
||||||
|
|
||||||
public PaymentCancel.Request removeReservationWithPayment(Long reservationId, Long memberId) {
|
return paymentCancelRequest
|
||||||
PaymentCancel.Request paymentCancelRequest = paymentService.cancelPaymentByAdmin(reservationId);
|
|
||||||
reservationService.removeReservationById(reservationId, memberId);
|
|
||||||
return paymentCancelRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public boolean isNotPaidReservation(Long reservationId) {
|
fun isNotPaidReservation(reservationId: Long): Boolean = !paymentService.isReservationPaid(reservationId)
|
||||||
return !paymentService.isReservationPaid(reservationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCanceledTime(String paymentKey, OffsetDateTime canceledAt) {
|
|
||||||
paymentService.updateCanceledTime(paymentKey, canceledAt);
|
fun updateCanceledTime(
|
||||||
|
paymentKey: String,
|
||||||
|
canceledAt: OffsetDateTime
|
||||||
|
) {
|
||||||
|
paymentService.updateCanceledTime(paymentKey, canceledAt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package roomescape.reservation.web
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import roomescape.member.web.MemberResponse
|
import roomescape.member.web.MemberResponse
|
||||||
import roomescape.member.web.MemberResponse.Companion.fromEntity
|
|
||||||
import roomescape.member.web.toResponse
|
import roomescape.member.web.toResponse
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
||||||
@ -78,9 +77,9 @@ data class ReservationResponse(
|
|||||||
return ReservationResponse(
|
return ReservationResponse(
|
||||||
reservation.id!!,
|
reservation.id!!,
|
||||||
reservation.date,
|
reservation.date,
|
||||||
fromEntity(reservation.member),
|
reservation.member.toResponse(),
|
||||||
ReservationTimeResponse.Companion.from(reservation.reservationTime),
|
reservation.reservationTime.toResponse(),
|
||||||
ThemeResponse.Companion.from(reservation.theme),
|
reservation.theme.toResponse(),
|
||||||
reservation.reservationStatus
|
reservation.reservationStatus
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import io.kotest.matchers.shouldBe
|
|||||||
import jakarta.persistence.EntityManager
|
import jakarta.persistence.EntityManager
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
import roomescape.util.PaymentFixture
|
import roomescape.util.PaymentFixture
|
||||||
import roomescape.util.ReservationFixture
|
import roomescape.util.ReservationFixture
|
||||||
|
|
||||||
@ -15,23 +16,23 @@ class PaymentRepositoryTest(
|
|||||||
@Autowired val entityManager: EntityManager
|
@Autowired val entityManager: EntityManager
|
||||||
) : FunSpec() {
|
) : FunSpec() {
|
||||||
|
|
||||||
var reservationId: Long = 0L
|
lateinit var reservation: ReservationEntity
|
||||||
|
|
||||||
init {
|
init {
|
||||||
context("existsByReservationId") {
|
context("existsByReservationId") {
|
||||||
beforeTest {
|
beforeTest {
|
||||||
reservationId = setupReservation()
|
reservation = setupReservation()
|
||||||
PaymentFixture.create(reservationId = reservationId)
|
PaymentFixture.create(reservation = reservation)
|
||||||
.also { paymentRepository.save(it) }
|
.also { paymentRepository.save(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
test("true") {
|
test("true") {
|
||||||
paymentRepository.existsByReservationId(reservationId)
|
paymentRepository.existsByReservationId(reservation.id!!)
|
||||||
.also { it shouldBe true }
|
.also { it shouldBe true }
|
||||||
}
|
}
|
||||||
|
|
||||||
test("false") {
|
test("false") {
|
||||||
paymentRepository.existsByReservationId(reservationId + 1)
|
paymentRepository.existsByReservationId(reservation.id!! + 1L)
|
||||||
.also { it shouldBe false }
|
.also { it shouldBe false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,20 +41,20 @@ class PaymentRepositoryTest(
|
|||||||
lateinit var paymentKey: String
|
lateinit var paymentKey: String
|
||||||
|
|
||||||
beforeTest {
|
beforeTest {
|
||||||
reservationId = setupReservation()
|
reservation = setupReservation()
|
||||||
paymentKey = PaymentFixture.create(reservationId = reservationId)
|
paymentKey = PaymentFixture.create(reservation = reservation)
|
||||||
.also { paymentRepository.save(it) }
|
.also { paymentRepository.save(it) }
|
||||||
.paymentKey
|
.paymentKey
|
||||||
}
|
}
|
||||||
|
|
||||||
test("정상 반환") {
|
test("정상 반환") {
|
||||||
paymentRepository.findPaymentKeyByReservationId(reservationId)
|
paymentRepository.findPaymentKeyByReservationId(reservation.id!!)
|
||||||
?.let { it shouldBe paymentKey }
|
?.let { it shouldBe paymentKey }
|
||||||
?: throw AssertionError("Unexpected null value")
|
?: throw AssertionError("Unexpected null value")
|
||||||
}
|
}
|
||||||
|
|
||||||
test("null 반환") {
|
test("null 반환") {
|
||||||
paymentRepository.findPaymentKeyByReservationId(reservationId + 1)
|
paymentRepository.findPaymentKeyByReservationId(reservation.id!! + 1)
|
||||||
.also { it shouldBe null }
|
.also { it shouldBe null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,8 +63,8 @@ class PaymentRepositoryTest(
|
|||||||
lateinit var payment: PaymentEntity
|
lateinit var payment: PaymentEntity
|
||||||
|
|
||||||
beforeTest {
|
beforeTest {
|
||||||
reservationId = setupReservation()
|
reservation = setupReservation()
|
||||||
payment = PaymentFixture.create(reservationId = reservationId)
|
payment = PaymentFixture.create(reservation = reservation)
|
||||||
.also { paymentRepository.save(it) }
|
.also { paymentRepository.save(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ class PaymentRepositoryTest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupReservation(): Long {
|
private fun setupReservation(): ReservationEntity {
|
||||||
return ReservationFixture.create().also {
|
return ReservationFixture.create().also {
|
||||||
entityManager.persist(it.member)
|
entityManager.persist(it.member)
|
||||||
entityManager.persist(it.theme)
|
entityManager.persist(it.theme)
|
||||||
@ -98,6 +99,6 @@ class PaymentRepositoryTest(
|
|||||||
|
|
||||||
entityManager.flush()
|
entityManager.flush()
|
||||||
entityManager.clear()
|
entityManager.clear()
|
||||||
}.id!!
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,170 +1,122 @@
|
|||||||
package roomescape.reservation.business;
|
package roomescape.reservation.business
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import io.kotest.assertions.assertSoftly
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
import io.mockk.Runs
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.just
|
||||||
|
import io.mockk.mockk
|
||||||
|
import roomescape.payment.business.PaymentService
|
||||||
|
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||||
|
import roomescape.payment.web.PaymentCancel
|
||||||
|
import roomescape.payment.web.toReservationPaymentResponse
|
||||||
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||||
|
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
||||||
|
import roomescape.reservation.web.ReservationRequest
|
||||||
|
import roomescape.reservation.web.ReservationResponse
|
||||||
|
import roomescape.util.*
|
||||||
|
|
||||||
import java.time.LocalDate;
|
class ReservationWithPaymentServiceTest : FunSpec({
|
||||||
import java.time.LocalDateTime;
|
val reservationService: ReservationService = mockk()
|
||||||
import java.time.OffsetDateTime;
|
val paymentService: PaymentService = mockk()
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
val reservationWithPaymentService = ReservationWithPaymentService(
|
||||||
import org.junit.jupiter.api.Test;
|
reservationService = reservationService,
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
paymentService = paymentService
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
)
|
||||||
import org.springframework.test.context.jdbc.Sql;
|
|
||||||
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
|
|
||||||
|
|
||||||
import roomescape.member.infrastructure.persistence.MemberEntity;
|
val reservationRequest: ReservationRequest = ReservationFixture.createRequest()
|
||||||
import roomescape.member.infrastructure.persistence.MemberRepository;
|
val paymentApproveResponse = PaymentFixture.createApproveResponse()
|
||||||
import roomescape.member.infrastructure.persistence.Role;
|
val memberId = 1L
|
||||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
val reservationEntity: ReservationEntity = ReservationFixture.create(
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentEntity;
|
id = 1L,
|
||||||
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
date = reservationRequest.date,
|
||||||
import roomescape.payment.web.PaymentApprove;
|
reservationTime = ReservationTimeFixture.create(id = reservationRequest.timeId),
|
||||||
import roomescape.payment.web.PaymentCancel;
|
theme = ThemeFixture.create(id = reservationRequest.themeId),
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity;
|
member = MemberFixture.create(id = memberId),
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationRepository;
|
status = ReservationStatus.CONFIRMED
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationStatus;
|
)
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationTimeEntity;
|
val paymentEntity: PaymentEntity = PaymentFixture.create(
|
||||||
import roomescape.reservation.infrastructure.persistence.ReservationTimeRepository;
|
id = 1L,
|
||||||
import roomescape.reservation.web.ReservationRequest;
|
orderId = reservationRequest.orderId,
|
||||||
import roomescape.reservation.web.ReservationResponse;
|
paymentKey = reservationRequest.paymentKey,
|
||||||
import roomescape.theme.infrastructure.persistence.ThemeEntity;
|
totalAmount = reservationRequest.amount,
|
||||||
import roomescape.theme.infrastructure.persistence.ThemeRepository;
|
reservation = reservationEntity,
|
||||||
|
)
|
||||||
|
|
||||||
@SpringBootTest
|
context("addReservationWithPayment") {
|
||||||
@Sql(scripts = "/truncate.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
|
test("예약 및 결제 정보를 저장한다.") {
|
||||||
class ReservationWithPaymentServiceTest {
|
every {
|
||||||
|
reservationService.addReservation(reservationRequest, memberId)
|
||||||
|
} returns reservationEntity
|
||||||
|
|
||||||
@Autowired
|
every {
|
||||||
private ReservationWithPaymentService reservationWithPaymentService;
|
paymentService.savePayment(paymentApproveResponse, reservationEntity)
|
||||||
@Autowired
|
} returns paymentEntity.toReservationPaymentResponse()
|
||||||
private ReservationRepository reservationRepository;
|
|
||||||
@Autowired
|
|
||||||
private MemberRepository memberRepository;
|
|
||||||
@Autowired
|
|
||||||
private ReservationTimeRepository reservationTimeRepository;
|
|
||||||
@Autowired
|
|
||||||
private ThemeRepository themeRepository;
|
|
||||||
@Autowired
|
|
||||||
private PaymentRepository paymentRepository;
|
|
||||||
@Autowired
|
|
||||||
private CanceledPaymentRepository canceledPaymentRepository;
|
|
||||||
|
|
||||||
@Test
|
val result: ReservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
||||||
@DisplayName("예약과 결제 정보를 추가한다.")
|
request = reservationRequest,
|
||||||
void addReservationWithPayment() {
|
paymentInfo = paymentApproveResponse,
|
||||||
// given
|
memberId = memberId
|
||||||
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
)
|
||||||
OffsetDateTime.now(), 10000L);
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
|
||||||
ReservationTimeEntity time = reservationTimeRepository.save(
|
|
||||||
new ReservationTimeEntity(null, localDateTime.toLocalTime()));
|
|
||||||
MemberEntity member = memberRepository.save(
|
|
||||||
new MemberEntity(null, "member", "email@email.com", "password", Role.MEMBER));
|
|
||||||
ThemeEntity theme = themeRepository.save(new ThemeEntity(null, "name", "desc", "thumbnail"));
|
|
||||||
ReservationRequest reservationRequest = new ReservationRequest(date, time.getId(), theme.getId(), "payment-key",
|
|
||||||
"order-id", 10000L, "NORMAL");
|
|
||||||
|
|
||||||
// when
|
assertSoftly(result) {
|
||||||
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
this.id shouldBe reservationEntity.id
|
||||||
reservationRequest, paymentInfo, member.getId());
|
this.date shouldBe reservationEntity.date
|
||||||
|
this.member.id shouldBe reservationEntity.member.id
|
||||||
// then
|
this.time.id shouldBe reservationEntity.reservationTime.id
|
||||||
reservationRepository.findById(reservationResponse.id)
|
this.theme.id shouldBe reservationEntity.theme.id
|
||||||
.ifPresent(reservation -> {
|
this.status shouldBe ReservationStatus.CONFIRMED
|
||||||
assertThat(reservation.getMember().getId()).isEqualTo(member.getId());
|
}
|
||||||
assertThat(reservation.getTheme().getId()).isEqualTo(theme.getId());
|
|
||||||
assertThat(reservation.getDate()).isEqualTo(date);
|
|
||||||
assertThat(reservation.getReservationTime().getId()).isEqualTo(time.getId());
|
|
||||||
assertThat(reservation.getReservationStatus()).isEqualTo(ReservationStatus.CONFIRMED);
|
|
||||||
});
|
|
||||||
|
|
||||||
PaymentEntity payment = paymentRepository.findByPaymentKey("payment-key");
|
|
||||||
assertThat(payment).isNotNull();
|
|
||||||
assertThat(payment.getReservation().getId()).isEqualTo(reservationResponse.id);
|
|
||||||
assertThat(payment.getPaymentKey()).isEqualTo("payment-key");
|
|
||||||
assertThat(payment.getOrderId()).isEqualTo("order-id");
|
|
||||||
assertThat(payment.getTotalAmount()).isEqualTo(10000L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("예약 ID를 이용하여 예약과 결제 정보를 제거하고, 결제 취소 정보를 저장한다.")
|
|
||||||
void removeReservationWithPayment() {
|
|
||||||
// given
|
|
||||||
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
|
||||||
OffsetDateTime.now(), 10000L);
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
|
||||||
ReservationTimeEntity time = reservationTimeRepository.save(
|
|
||||||
new ReservationTimeEntity(null, localDateTime.toLocalTime()));
|
|
||||||
MemberEntity member = memberRepository.save(
|
|
||||||
new MemberEntity(null, "member", "admin@email.com", "password", Role.ADMIN));
|
|
||||||
ThemeEntity theme = themeRepository.save(new ThemeEntity(null, "name", "desc", "thumbnail"));
|
|
||||||
ReservationRequest reservationRequest = new ReservationRequest(date, time.getId(), theme.getId(), "payment-key",
|
|
||||||
"order-id", 10000L, "NORMAL");
|
|
||||||
|
|
||||||
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
context("removeReservationWithPayment") {
|
||||||
reservationRequest, paymentInfo, member.getId());
|
test("예약 및 결제 정보를 삭제하고, 결제 취소 정보를 저장한다.") {
|
||||||
|
val paymentCancelRequest: PaymentCancel.Request = PaymentFixture.createCancelRequest().copy(
|
||||||
|
paymentKey = paymentEntity.paymentKey,
|
||||||
|
amount = paymentEntity.totalAmount,
|
||||||
|
cancelReason = "고객 요청"
|
||||||
|
)
|
||||||
|
|
||||||
// when
|
every {
|
||||||
PaymentCancel.Request paymentCancelRequest = reservationWithPaymentService.removeReservationWithPayment(
|
paymentService.cancelPaymentByAdmin(reservationEntity.id!!)
|
||||||
reservationResponse.id, member.getId());
|
} returns paymentCancelRequest
|
||||||
|
|
||||||
// then
|
every {
|
||||||
assertThat(paymentCancelRequest.cancelReason).isEqualTo("고객 요청");
|
reservationService.removeReservationById(reservationEntity.id!!, reservationEntity.member.id!!)
|
||||||
assertThat(reservationRepository.findById(reservationResponse.id)).isEmpty();
|
} just Runs
|
||||||
assertThat(paymentRepository.findByPaymentKey("payment-key")).isNull();
|
|
||||||
assertThat(canceledPaymentRepository.findByPaymentKey("payment-key")).isNotNull();
|
val result: PaymentCancel.Request = reservationWithPaymentService.removeReservationWithPayment(
|
||||||
|
reservationId = reservationEntity.id!!,
|
||||||
|
memberId = reservationEntity.member.id!!
|
||||||
|
)
|
||||||
|
|
||||||
|
result shouldBe paymentCancelRequest
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
context("isNotPaidReservation") {
|
||||||
@DisplayName("결제 정보가 없으면 True를 반환한다.")
|
test("결제된 예약이면 true를 반환한다.") {
|
||||||
void isNotPaidReservation() {
|
every {
|
||||||
// given
|
paymentService.isReservationPaid(reservationEntity.id!!)
|
||||||
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
} returns false
|
||||||
OffsetDateTime.now(), 10000L);
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusHours(1L);
|
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
|
||||||
ReservationTimeEntity time = reservationTimeRepository.save(
|
|
||||||
new ReservationTimeEntity(null, localDateTime.toLocalTime()));
|
|
||||||
MemberEntity member = memberRepository.save(
|
|
||||||
new MemberEntity(null, "member", "admin@email.com", "password", Role.ADMIN));
|
|
||||||
ThemeEntity theme = themeRepository.save(new ThemeEntity(null, "name", "desc", "thumbnail"));
|
|
||||||
|
|
||||||
ReservationEntity saved = reservationRepository.save(
|
val result: Boolean = reservationWithPaymentService.isNotPaidReservation(reservationEntity.id!!)
|
||||||
new ReservationEntity(null, date, time, theme, member, ReservationStatus.CONFIRMED_PAYMENT_REQUIRED));
|
|
||||||
|
|
||||||
// when
|
result shouldBe true
|
||||||
boolean result = reservationWithPaymentService.isNotPaidReservation(saved.getId());
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(result).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
test("결제되지 않은 예약이면 false를 반환한다.") {
|
||||||
@DisplayName("결제 정보가 있으면 False를 반환한다.")
|
every {
|
||||||
void isPaidReservation() {
|
paymentService.isReservationPaid(reservationEntity.id!!)
|
||||||
// given
|
} returns true
|
||||||
PaymentApprove.Response paymentInfo = new PaymentApprove.Response("payment-key", "order-id",
|
|
||||||
OffsetDateTime.now(), 10000L);
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.now().plusDays(1L).withNano(0);
|
|
||||||
LocalDate date = localDateTime.toLocalDate();
|
|
||||||
ReservationTimeEntity time = reservationTimeRepository.save(
|
|
||||||
new ReservationTimeEntity(null, localDateTime.toLocalTime()));
|
|
||||||
MemberEntity member = memberRepository.save(
|
|
||||||
new MemberEntity(null, "member", "admin@email.com", "password", Role.ADMIN));
|
|
||||||
ThemeEntity theme = themeRepository.save(new ThemeEntity(null, "name", "desc", "thumbnail"));
|
|
||||||
ReservationRequest reservationRequest = new ReservationRequest(date, time.getId(), theme.getId(), "payment-key",
|
|
||||||
"order-id", 10000L, "NORMAL");
|
|
||||||
|
|
||||||
ReservationResponse reservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
val result: Boolean = reservationWithPaymentService.isNotPaidReservation(reservationEntity.id!!)
|
||||||
reservationRequest, paymentInfo, member.getId());
|
|
||||||
|
|
||||||
// when
|
result shouldBe false
|
||||||
boolean result = reservationWithPaymentService.isNotPaidReservation(reservationResponse.id);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(result).isFalse();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
@ -161,7 +161,7 @@ class ReservationRepositoryTest(
|
|||||||
|
|
||||||
test("결제 정보를 포함한 회원의 예약 목록을 반환한다.") {
|
test("결제 정보를 포함한 회원의 예약 목록을 반환한다.") {
|
||||||
val payment: PaymentEntity = PaymentFixture.create(
|
val payment: PaymentEntity = PaymentFixture.create(
|
||||||
reservationId = reservation.id!!
|
reservation = reservation
|
||||||
).also {
|
).also {
|
||||||
entityManager.persist(it)
|
entityManager.persist(it)
|
||||||
entityManager.flush()
|
entityManager.flush()
|
||||||
|
|||||||
@ -128,14 +128,14 @@ object PaymentFixture {
|
|||||||
orderId: String = ORDER_ID,
|
orderId: String = ORDER_ID,
|
||||||
paymentKey: String = PAYMENT_KEY,
|
paymentKey: String = PAYMENT_KEY,
|
||||||
totalAmount: Long = AMOUNT,
|
totalAmount: Long = AMOUNT,
|
||||||
reservationId: Long = Random.nextLong(),
|
reservation: ReservationEntity = ReservationFixture.create(id = 1L),
|
||||||
approvedAt: OffsetDateTime = OffsetDateTime.now()
|
approvedAt: OffsetDateTime = OffsetDateTime.now()
|
||||||
): PaymentEntity = PaymentEntity(
|
): PaymentEntity = PaymentEntity(
|
||||||
id = id,
|
id = id,
|
||||||
orderId = orderId,
|
orderId = orderId,
|
||||||
paymentKey = paymentKey,
|
paymentKey = paymentKey,
|
||||||
totalAmount = totalAmount,
|
totalAmount = totalAmount,
|
||||||
reservation = ReservationFixture.create(id = reservationId),
|
reservation = reservation,
|
||||||
approvedAt = approvedAt
|
approvedAt = approvedAt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user