Skip to content

Commit

Permalink
test: OrderPayment 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hgo641 committed Apr 11, 2024
1 parent c8a3269 commit b7e43f4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/main/kotlin/com/petqua/domain/order/OrderPayment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.petqua.domain.order.OrderStatus.ORDER_CREATED
import com.petqua.domain.order.OrderStatus.PAYMENT_CONFIRMED
import com.petqua.exception.order.OrderException
import com.petqua.exception.order.OrderExceptionType
import jakarta.persistence.AttributeOverride
import jakarta.persistence.Column
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
Expand All @@ -32,7 +30,7 @@ class OrderPayment(
val prevId: Long? = null,
) {

companion object{
companion object {
fun from(order: Order): OrderPayment {
return OrderPayment(
orderId = order.id,
Expand All @@ -54,7 +52,7 @@ class OrderPayment(
}

fun pay(tossPaymentId: Long): OrderPayment {
throwExceptionWhen(!status.isAbleToPay()) { // TODO OrderPayment는 결제가 성공될 때 생성되므로 OrderCreated 상태를 가질 수 없음
throwExceptionWhen(!status.isAbleToPay()) {
throw OrderException(OrderExceptionType.ORDER_CAN_NOT_PAY)
}
return OrderPayment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ class OrderServiceTest(
orders.forAll {
it.orderNumber.value shouldBe response.orderId
it.orderName.value shouldBe response.orderName
// it.status shouldBe ORDER_CREATED
}
orders.distinctBy { it.orderProduct.shippingNumber }.size shouldBe 2

Expand Down
48 changes: 48 additions & 0 deletions src/test/kotlin/com/petqua/domain/order/OrderPaymentTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.petqua.domain.order

import com.petqua.domain.order.OrderStatus.CANCELED
import com.petqua.domain.order.OrderStatus.PAYMENT_CONFIRMED
import com.petqua.exception.order.OrderException
import com.petqua.exception.order.OrderExceptionType
import com.petqua.test.fixture.orderPayment
import io.kotest.assertions.assertSoftly
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe

class OrderPaymentTest : StringSpec({

"결제를 진행한다" {
val orderPayment = orderPayment()
val payedOrderPayment = orderPayment.pay(tossPaymentId = 1L)

assertSoftly(payedOrderPayment) {
orderId shouldBe orderPayment.orderId
tossPaymentId shouldBe 1L
status shouldBe PAYMENT_CONFIRMED
prevId shouldBe orderPayment.id
}
}

"결제 시도시 결제가 가능한 상태가 아니라면 예외를 던진다" {
val orderPayment = orderPayment(
status = PAYMENT_CONFIRMED
)

shouldThrow<OrderException> {
orderPayment.pay(tossPaymentId = 1L)
}.exceptionType() shouldBe OrderExceptionType.ORDER_CAN_NOT_PAY
}

"주문을 취소한다" {
val orderPayment = orderPayment()
val payedOrderPayment = orderPayment.cancel()

assertSoftly(payedOrderPayment) {
orderId shouldBe orderPayment.orderId
tossPaymentId shouldBe orderPayment.tossPaymentId
status shouldBe CANCELED
prevId shouldBe orderPayment.id
}
}
})

0 comments on commit b7e43f4

Please sign in to comment.