test: 토스페이 계좌이체 클라이언트 테스트 추가

This commit is contained in:
이상진 2025-09-09 09:34:03 +09:00
parent 211edcaffd
commit 1cb1a97703
2 changed files with 159 additions and 19 deletions

View File

@ -8,9 +8,18 @@ object SampleTosspayConstant {
const val AMOUNT: Int = 100_000 const val AMOUNT: Int = 100_000
const val CANCEL_REASON: String = "테스트 결제 취소" const val CANCEL_REASON: String = "테스트 결제 취소"
val confirmRequestJson: String = """
{
"paymentKey": "$PAYMENT_KEY",
"orderId": "$ORDER_ID",
"amount": "$AMOUNT"
}
""".trimIndent()
val cancelRequestJson: String = """ val cancelRequestJson: String = """
{ {
"cancelReason": "$CANCEL_REASON" "cancelReason": "$CANCEL_REASON",
"cancelAmount": "$AMOUNT"
} }
""".trimIndent() """.trimIndent()
@ -21,7 +30,7 @@ object SampleTosspayConstant {
} }
""".trimIndent() """.trimIndent()
val confirmJson: String = """ val easypayCardConfirmJson: String = """
{ {
"mId": "tgen_docs", "mId": "tgen_docs",
"lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky", "lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky",
@ -84,7 +93,7 @@ object SampleTosspayConstant {
} }
""".trimIndent() """.trimIndent()
val cancelJson: String = """ val easypayCardCancelJson: String = """
{ {
"mId": "tgen_docs", "mId": "tgen_docs",
"lastTransactionKey": "txrd_a01k4mtgh26vgrn1evbdckyqmdr", "lastTransactionKey": "txrd_a01k4mtgh26vgrn1evbdckyqmdr",
@ -162,4 +171,118 @@ object SampleTosspayConstant {
"metadata": null "metadata": null
} }
""".trimIndent() """.trimIndent()
val transferConfirmJson: String = """
{
"mId": "tgen_docs",
"lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky",
"paymentKey": "$PAYMENT_KEY",
"orderId": "$ORDER_ID",
"orderName": "Sonya Aguirre 예약 결제",
"taxExemptionAmount": 0,
"status": "DONE",
"requestedAt": "${OffsetDateTime.now()}",
"approvedAt": "${OffsetDateTime.now().plusSeconds(5)}",
"useEscrow": false,
"cultureExpense": false,
"card": null,
"virtualAccount": null,
"transfer": {
"bankCode": "92",
"settlementStatus": "COMPLETED"
},
"mobilePhone": null,
"giftCertificate": null,
"cashReceipt": null,
"cashReceipts": null,
"discount": null,
"cancels": null,
"secret": "ps_6BYq7GWPVvGNAwZeRBDLrNE5vbo1",
"type": "NORMAL",
"easyPay": null,
"country": "KR",
"failure": null,
"isPartialCancelable": true,
"receipt": {
"url": "https://dashboard-sandbox.tosspayments.com/receipt/redirection?transactionId=tgen_20250908230510v2rY2&ref=PX"
},
"checkout": {
"url": "https://api.tosspayments.com/v1/payments/tgen_20250908230510v2rY2/checkout"
},
"currency": "KRW",
"totalAmount": $AMOUNT,
"balanceAmount": $AMOUNT,
"suppliedAmount": ${(AMOUNT * 0.9).toInt()},
"vat": ${(AMOUNT * 0.1).toInt()},
"taxFreeAmount": 0,
"method": "간편결제",
"version": "2022-11-16",
"metadata": null
}
""".trimIndent()
val transferCancelJson: String = """
{
"mId": "tgen_docs",
"lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky",
"paymentKey": "$PAYMENT_KEY",
"orderId": "$ORDER_ID",
"orderName": "Sonya Aguirre 예약 결제",
"taxExemptionAmount": 0,
"status": "DONE",
"requestedAt": "${OffsetDateTime.now()}",
"approvedAt": "${OffsetDateTime.now().plusSeconds(5)}",
"useEscrow": false,
"cultureExpense": false,
"card": null,
"virtualAccount": null,
"transfer": {
"bankCode": "92",
"settlementStatus": "COMPLETED"
},
"mobilePhone": null,
"giftCertificate": null,
"cashReceipt": null,
"cashReceipts": null,
"discount": null,
"cancels": [
{
"transactionKey": "txrd_a01k4mtgh26vgrn1evbdckyqmdr",
"cancelReason": "$CANCEL_REASON",
"taxExemptionAmount": 0,
"canceledAt": "${OffsetDateTime.now().plusMinutes(1)}",
"cardDiscountAmount": 0,
"transferDiscountAmount": 0,
"easyPayDiscountAmount": 0,
"receiptKey": null,
"cancelStatus": "DONE",
"cancelRequestId": null,
"cancelAmount": $AMOUNT,
"taxFreeAmount": 0,
"refundableAmount": 0
}
],
"secret": "ps_6BYq7GWPVvGNAwZeRBDLrNE5vbo1",
"type": "NORMAL",
"easyPay": null,
"country": "KR",
"failure": null,
"isPartialCancelable": true,
"receipt": {
"url": "https://dashboard-sandbox.tosspayments.com/receipt/redirection?transactionId=tgen_20250908230510v2rY2&ref=PX"
},
"checkout": {
"url": "https://api.tosspayments.com/v1/payments/tgen_20250908230510v2rY2/checkout"
},
"currency": "KRW",
"totalAmount": $AMOUNT,
"balanceAmount": $AMOUNT,
"suppliedAmount": ${(AMOUNT * 0.9).toInt()},
"vat": ${(AMOUNT * 0.1).toInt()},
"taxFreeAmount": 0,
"method": "간편결제",
"version": "2022-11-16",
"metadata": null
}
""".trimIndent()
} }

View File

@ -39,26 +39,30 @@ class TosspayClientTest(
}.andExpect { }.andExpect {
content().contentType(MediaType.APPLICATION_JSON) content().contentType(MediaType.APPLICATION_JSON)
}.andExpect { }.andExpect {
content().json(SampleTosspayConstant.confirmJson) content().json(SampleTosspayConstant.confirmRequestJson)
} }
test("성공 응답") { context("성공 응답") {
test("간편결제 + 카드") {
commonAction().andRespond { commonAction().andRespond {
withSuccess() withSuccess()
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.body(SampleTosspayConstant.confirmJson) .body(SampleTosspayConstant.easypayCardConfirmJson)
.createResponse(it) .createResponse(it)
} }
val paymentResponse: PaymentClientConfirmResponse = client.confirm( runConfirmTest()
SampleTosspayConstant.PAYMENT_KEY, }
SampleTosspayConstant.ORDER_ID,
SampleTosspayConstant.AMOUNT
)
assertSoftly(paymentResponse) { test("계좌이체") {
this.paymentKey shouldBe SampleTosspayConstant.PAYMENT_KEY commonAction().andRespond {
this.totalAmount shouldBe SampleTosspayConstant.AMOUNT withSuccess()
.contentType(MediaType.APPLICATION_JSON)
.body(SampleTosspayConstant.transferConfirmJson)
.createResponse(it)
}
runConfirmTest()
} }
} }
@ -107,7 +111,7 @@ class TosspayClientTest(
commonAction().andRespond { commonAction().andRespond {
withSuccess() withSuccess()
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.body(SampleTosspayConstant.cancelJson) .body(SampleTosspayConstant.easypayCardCancelJson)
.createResponse(it) .createResponse(it)
} }
@ -155,4 +159,17 @@ class TosspayClientTest(
} }
} }
} }
fun runConfirmTest() {
val paymentResponse: PaymentClientConfirmResponse = client.confirm(
SampleTosspayConstant.PAYMENT_KEY,
SampleTosspayConstant.ORDER_ID,
SampleTosspayConstant.AMOUNT
)
assertSoftly(paymentResponse) {
this.paymentKey shouldBe SampleTosspayConstant.PAYMENT_KEY
this.totalAmount shouldBe SampleTosspayConstant.AMOUNT
}
}
} }