generated from pricelees/issue-pr-template
test: Payment / CanceledPaymentRepository 테스트 추가
This commit is contained in:
parent
cd6f44ca60
commit
c308401f3f
@ -0,0 +1,37 @@
|
|||||||
|
package roomescape.payment.infrastructure.persistence
|
||||||
|
|
||||||
|
import io.kotest.assertions.assertSoftly
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
|
import roomescape.util.PaymentFixture
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@DataJpaTest
|
||||||
|
class CanceledPaymentRepositoryTest(
|
||||||
|
@Autowired val canceledPaymentRepository: CanceledPaymentRepository,
|
||||||
|
): FunSpec() {
|
||||||
|
init {
|
||||||
|
context("paymentKey로 CanceledPaymentEntity 조회") {
|
||||||
|
val paymentKey = "test-payment-key"
|
||||||
|
beforeTest {
|
||||||
|
PaymentFixture.createCanceled(paymentKey = paymentKey)
|
||||||
|
.also { canceledPaymentRepository.save(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
test("정상 반환") {
|
||||||
|
canceledPaymentRepository.findByPaymentKey(paymentKey)?.let {
|
||||||
|
assertSoftly(it) {
|
||||||
|
this.paymentKey shouldBe paymentKey
|
||||||
|
}
|
||||||
|
} ?: throw AssertionError("Unexpected null value")
|
||||||
|
}
|
||||||
|
|
||||||
|
test("null 반환") {
|
||||||
|
canceledPaymentRepository.findByPaymentKey(UUID.randomUUID().toString())
|
||||||
|
.also { it shouldBe null }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,103 @@
|
|||||||
|
package roomescape.payment.infrastructure.persistence
|
||||||
|
|
||||||
|
import io.kotest.assertions.assertSoftly
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
import jakarta.persistence.EntityManager
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
|
import roomescape.util.PaymentFixture
|
||||||
|
import roomescape.util.ReservationFixture
|
||||||
|
|
||||||
|
@DataJpaTest
|
||||||
|
class PaymentRepositoryTest(
|
||||||
|
@Autowired val paymentRepository: PaymentRepository,
|
||||||
|
@Autowired val entityManager: EntityManager
|
||||||
|
) : FunSpec() {
|
||||||
|
|
||||||
|
var reservationId: Long = 0L
|
||||||
|
|
||||||
|
init {
|
||||||
|
context("existsByReservationId") {
|
||||||
|
beforeTest {
|
||||||
|
reservationId = setupReservation()
|
||||||
|
PaymentFixture.create(reservationId = reservationId)
|
||||||
|
.also { paymentRepository.save(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
test("true") {
|
||||||
|
paymentRepository.existsByReservationId(reservationId)
|
||||||
|
.also { it shouldBe true }
|
||||||
|
}
|
||||||
|
|
||||||
|
test("false") {
|
||||||
|
paymentRepository.existsByReservationId(reservationId + 1)
|
||||||
|
.also { it shouldBe false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context("findPaymentKeyByReservationId") {
|
||||||
|
lateinit var paymentKey: String
|
||||||
|
|
||||||
|
beforeTest {
|
||||||
|
reservationId = setupReservation()
|
||||||
|
paymentKey = PaymentFixture.create(reservationId = reservationId)
|
||||||
|
.also { paymentRepository.save(it) }
|
||||||
|
.paymentKey
|
||||||
|
}
|
||||||
|
|
||||||
|
test("정상 반환") {
|
||||||
|
paymentRepository.findPaymentKeyByReservationId(reservationId)
|
||||||
|
?.let { it shouldBe paymentKey }
|
||||||
|
?: throw AssertionError("Unexpected null value")
|
||||||
|
}
|
||||||
|
|
||||||
|
test("null 반환") {
|
||||||
|
paymentRepository.findPaymentKeyByReservationId(reservationId + 1)
|
||||||
|
.also { it shouldBe null }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context("findByPaymentKey") {
|
||||||
|
lateinit var payment: PaymentEntity
|
||||||
|
|
||||||
|
beforeTest {
|
||||||
|
reservationId = setupReservation()
|
||||||
|
payment = PaymentFixture.create(reservationId = reservationId)
|
||||||
|
.also { paymentRepository.save(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
test("정상 반환") {
|
||||||
|
paymentRepository.findByPaymentKey(payment.paymentKey)
|
||||||
|
?.also {
|
||||||
|
assertSoftly(it) {
|
||||||
|
this.id shouldBe payment.id
|
||||||
|
this.orderId shouldBe payment.orderId
|
||||||
|
this.paymentKey shouldBe payment.paymentKey
|
||||||
|
this.totalAmount shouldBe payment.totalAmount
|
||||||
|
this.reservation.id shouldBe payment.reservation.id
|
||||||
|
this.approvedAt shouldBe payment.approvedAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?: throw AssertionError("Unexpected null value")
|
||||||
|
}
|
||||||
|
|
||||||
|
test("null 반환") {
|
||||||
|
paymentRepository.findByPaymentKey("non-existent-key")
|
||||||
|
.also { it shouldBe null }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupReservation(): Long {
|
||||||
|
return ReservationFixture.create().also {
|
||||||
|
entityManager.persist(it.member)
|
||||||
|
entityManager.persist(it.theme)
|
||||||
|
entityManager.persist(it.reservationTime)
|
||||||
|
entityManager.persist(it)
|
||||||
|
|
||||||
|
entityManager.flush()
|
||||||
|
entityManager.clear()
|
||||||
|
}.id
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,15 +9,6 @@ spring:
|
|||||||
sql:
|
sql:
|
||||||
init:
|
init:
|
||||||
data-locations:
|
data-locations:
|
||||||
h2:
|
|
||||||
console:
|
|
||||||
enabled: true
|
|
||||||
path: /h2-console
|
|
||||||
datasource:
|
|
||||||
driver-class-name: org.h2.Driver
|
|
||||||
url: jdbc:h2:mem:database-test
|
|
||||||
username: sa
|
|
||||||
password:
|
|
||||||
|
|
||||||
security:
|
security:
|
||||||
jwt:
|
jwt:
|
||||||
@ -30,4 +21,9 @@ payment:
|
|||||||
api-base-url: https://api.tosspayments.com
|
api-base-url: https://api.tosspayments.com
|
||||||
confirm-secret-key: test_gsk_docs_OaPz8L5KdmQXkzRz3y47BMw6
|
confirm-secret-key: test_gsk_docs_OaPz8L5KdmQXkzRz3y47BMw6
|
||||||
read-timeout: 3
|
read-timeout: 3
|
||||||
connect-timeout: 30
|
connect-timeout: 30
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.orm.jpa: DEBUG
|
||||||
|
org.springframework.transaction: DEBUG
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user