From c9fa802cbc1f23ac61d78b59bf4540410a3c0578 Mon Sep 17 00:00:00 2001 From: pricelees Date: Mon, 29 Sep 2025 22:00:45 +0900 Subject: [PATCH] =?UTF-8?q?test:=20PaymentType=20enum=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roomescape/payment/PaymentTypeTest.kt | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 service/src/test/kotlin/com/sangdol/roomescape/payment/PaymentTypeTest.kt diff --git a/service/src/test/kotlin/com/sangdol/roomescape/payment/PaymentTypeTest.kt b/service/src/test/kotlin/com/sangdol/roomescape/payment/PaymentTypeTest.kt new file mode 100644 index 00000000..5831bc95 --- /dev/null +++ b/service/src/test/kotlin/com/sangdol/roomescape/payment/PaymentTypeTest.kt @@ -0,0 +1,148 @@ +package com.sangdol.roomescape.payment + +import com.sangdol.roomescape.payment.exception.PaymentErrorCode +import com.sangdol.roomescape.payment.exception.PaymentException +import com.sangdol.roomescape.payment.infrastructure.common.BankCode +import com.sangdol.roomescape.payment.infrastructure.common.CardIssuerCode +import com.sangdol.roomescape.payment.infrastructure.common.CardOwnerType +import com.sangdol.roomescape.payment.infrastructure.common.CardType +import com.sangdol.roomescape.payment.infrastructure.common.EasyPayCompanyCode +import com.sangdol.roomescape.payment.infrastructure.common.PaymentMethod +import com.sangdol.roomescape.payment.infrastructure.common.PaymentStatus +import com.sangdol.roomescape.payment.infrastructure.common.PaymentType +import io.kotest.assertions.assertSoftly +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldHaveLength +import org.junit.jupiter.api.assertThrows + +class PaymentTypeTest : FunSpec({ + + context("PaymentType") { + test("한글 이름으로 가져온다.") { + PaymentType.entries.forEach { + PaymentType.Companion.get(it.name) shouldBe it + } + } + + test("없는 이름이면 실패한다.") { + assertThrows { + PaymentType.Companion.get("NORMAR") + }.also { + it.errorCode shouldBe PaymentErrorCode.TYPE_NOT_FOUND + } + } + } + + context("PaymentMethod") { + test("결제수단 한글명으로 가져온다.") { + PaymentMethod.entries.forEach { + PaymentMethod.Companion.get(it.koreanName) shouldBe it + } + } + + test("없는 이름이면 실패한다.") { + assertThrows { + PaymentMethod.Companion.get("카드12") + }.also { + it.errorCode shouldBe PaymentErrorCode.TYPE_NOT_FOUND + } + } + } + + context("PaymentStatus") { + test("상수 이름으로 가져온다.") { + PaymentStatus.entries.forEach { + PaymentStatus.Companion.get(it.name) shouldBe it + } + } + + test("없는 이름이면 실패한다.") { + assertThrows { + PaymentStatus.Companion.get("DONEE") + }.also { + it.errorCode shouldBe PaymentErrorCode.TYPE_NOT_FOUND + } + } + } + + context("CardType") { + test("한글 이름으로 가져온다.") { + CardType.entries.forEach { + CardType.Companion.get(it.koreanName) shouldBe it + } + } + + test("없는 이름을 입력하면 UNKNOWN을 반환한다.") { + CardType.Companion.get("신용카드") shouldBe CardType.UNKNOWN + } + } + + context("CardOwnerType") { + test("한글 이름으로 가져온다.") { + CardOwnerType.entries.forEach { + CardOwnerType.Companion.get(it.koreanName) shouldBe it + } + } + + test("없는 이름을 입력하면 UNKNOWN을 반환한다.") { + CardOwnerType.Companion.get("개인카드") shouldBe CardOwnerType.UNKNOWN + } + } + + context("BankCode") { + test("숫자 코드로 가져온다.") { + BankCode.entries.forEach { + BankCode.Companion.get(it.code) shouldBe it + } + } + + test("숫자가 두글자이면 앞에 0을 붙인다.") { + assertSoftly(BankCode.SHINHAN.code) { + this shouldHaveLength 3 + BankCode.Companion.get(this.substring(1)) shouldBe BankCode.Companion.get(this) + + } + } + + test("없는 코드이면 실패한다") { + assertThrows { + BankCode.Companion.get("9999") + }.also { + it.errorCode shouldBe PaymentErrorCode.ORGANIZATION_CODE_NOT_FOUND + } + } + } + + context("CardIssuerCode") { + test("숫자 코드로 가져온다.") { + CardIssuerCode.entries.forEach { + CardIssuerCode.Companion.get(it.code) shouldBe it + } + } + + test("없는 코드이면 실패한다") { + assertThrows { + CardIssuerCode.Companion.get("9999") + }.also { + it.errorCode shouldBe PaymentErrorCode.ORGANIZATION_CODE_NOT_FOUND + } + } + } + + context("EasyPayCompanyCode") { + test("한글 이름으로 가져온다.") { + EasyPayCompanyCode.entries.forEach { + EasyPayCompanyCode.Companion.get(it.koreanName) shouldBe it + } + } + + test("없는 이름이면 실패한다") { + assertThrows { + EasyPayCompanyCode.Companion.get("상돌페이") + }.also { + it.errorCode shouldBe PaymentErrorCode.ORGANIZATION_CODE_NOT_FOUND + } + } + } +}) \ No newline at end of file