From 1cb1a977033dccff9c56b9682e96f5bde34b0c11 Mon Sep 17 00:00:00 2001 From: pricelees Date: Tue, 9 Sep 2025 09:34:03 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=ED=86=A0=EC=8A=A4=ED=8E=98=EC=9D=B4=20?= =?UTF-8?q?=EA=B3=84=EC=A2=8C=EC=9D=B4=EC=B2=B4=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/SampleTosspayConstant.kt | 129 +++++++++++++++++- .../roomescape/payment/TosspayClientTest.kt | 49 ++++--- 2 files changed, 159 insertions(+), 19 deletions(-) diff --git a/src/test/kotlin/roomescape/payment/SampleTosspayConstant.kt b/src/test/kotlin/roomescape/payment/SampleTosspayConstant.kt index e54745f7..07c4a2ad 100644 --- a/src/test/kotlin/roomescape/payment/SampleTosspayConstant.kt +++ b/src/test/kotlin/roomescape/payment/SampleTosspayConstant.kt @@ -8,9 +8,18 @@ object SampleTosspayConstant { const val AMOUNT: Int = 100_000 const val CANCEL_REASON: String = "테스트 결제 취소" + val confirmRequestJson: String = """ + { + "paymentKey": "$PAYMENT_KEY", + "orderId": "$ORDER_ID", + "amount": "$AMOUNT" + } + """.trimIndent() + val cancelRequestJson: String = """ { - "cancelReason": "$CANCEL_REASON" + "cancelReason": "$CANCEL_REASON", + "cancelAmount": "$AMOUNT" } """.trimIndent() @@ -21,7 +30,7 @@ object SampleTosspayConstant { } """.trimIndent() - val confirmJson: String = """ + val easypayCardConfirmJson: String = """ { "mId": "tgen_docs", "lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky", @@ -84,7 +93,7 @@ object SampleTosspayConstant { } """.trimIndent() - val cancelJson: String = """ + val easypayCardCancelJson: String = """ { "mId": "tgen_docs", "lastTransactionKey": "txrd_a01k4mtgh26vgrn1evbdckyqmdr", @@ -162,4 +171,118 @@ object SampleTosspayConstant { "metadata": null } """.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() } diff --git a/src/test/kotlin/roomescape/payment/TosspayClientTest.kt b/src/test/kotlin/roomescape/payment/TosspayClientTest.kt index d511e0b5..d0665a06 100644 --- a/src/test/kotlin/roomescape/payment/TosspayClientTest.kt +++ b/src/test/kotlin/roomescape/payment/TosspayClientTest.kt @@ -39,26 +39,30 @@ class TosspayClientTest( }.andExpect { content().contentType(MediaType.APPLICATION_JSON) }.andExpect { - content().json(SampleTosspayConstant.confirmJson) + content().json(SampleTosspayConstant.confirmRequestJson) } - test("성공 응답") { - commonAction().andRespond { - withSuccess() - .contentType(MediaType.APPLICATION_JSON) - .body(SampleTosspayConstant.confirmJson) - .createResponse(it) + context("성공 응답") { + test("간편결제 + 카드") { + commonAction().andRespond { + withSuccess() + .contentType(MediaType.APPLICATION_JSON) + .body(SampleTosspayConstant.easypayCardConfirmJson) + .createResponse(it) + } + + runConfirmTest() } - val paymentResponse: PaymentClientConfirmResponse = client.confirm( - SampleTosspayConstant.PAYMENT_KEY, - SampleTosspayConstant.ORDER_ID, - SampleTosspayConstant.AMOUNT - ) + test("계좌이체") { + commonAction().andRespond { + withSuccess() + .contentType(MediaType.APPLICATION_JSON) + .body(SampleTosspayConstant.transferConfirmJson) + .createResponse(it) + } - assertSoftly(paymentResponse) { - this.paymentKey shouldBe SampleTosspayConstant.PAYMENT_KEY - this.totalAmount shouldBe SampleTosspayConstant.AMOUNT + runConfirmTest() } } @@ -107,7 +111,7 @@ class TosspayClientTest( commonAction().andRespond { withSuccess() .contentType(MediaType.APPLICATION_JSON) - .body(SampleTosspayConstant.cancelJson) + .body(SampleTosspayConstant.easypayCardCancelJson) .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 + } + } }