Test #466
@@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.can.charge
|
|||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
data class ChargeCompleteResponse(
|
data class ChargeCompleteResponse(
|
||||||
|
val chargeId: Long,
|
||||||
val price: BigDecimal,
|
val price: BigDecimal,
|
||||||
val currencyCode: String,
|
val currencyCode: String,
|
||||||
val isFirstCharged: Boolean,
|
val isFirstCharged: Boolean,
|
||||||
|
|||||||
@@ -716,6 +716,7 @@ class ChargeService(
|
|||||||
|
|
||||||
private fun completeResponse(charge: Charge): ChargeCompleteResponse {
|
private fun completeResponse(charge: Charge): ChargeCompleteResponse {
|
||||||
return ChargeCompleteResponse(
|
return ChargeCompleteResponse(
|
||||||
|
chargeId = charge.id!!,
|
||||||
price = charge.payment!!.price,
|
price = charge.payment!!.price,
|
||||||
currencyCode = charge.payment!!.locale?.takeLast(3) ?: "KRW",
|
currencyCode = charge.payment!!.locale?.takeLast(3) ?: "KRW",
|
||||||
isFirstCharged = charge.isFirstCharged == true,
|
isFirstCharged = charge.isFirstCharged == true,
|
||||||
|
|||||||
+16
-7
@@ -130,7 +130,7 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@EnumSource(VerificationPath::class)
|
@EnumSource(VerificationPath::class)
|
||||||
@DisplayName("다섯 완료 HTTP 경로는 실제 서비스 결과의 네 필드와 기존 envelope를 반환한다")
|
@DisplayName("다섯 완료 HTTP 경로는 저장된 충전 ID와 완료 정보 및 기존 envelope를 반환한다")
|
||||||
fun shouldReturnChargeCompleteDataForAllFiveVerificationEndpoints(path: VerificationPath) {
|
fun shouldReturnChargeCompleteDataForAllFiveVerificationEndpoints(path: VerificationPath) {
|
||||||
val owner = createMember(container = if (path.isIap) "web" else "ios")
|
val owner = createMember(container = if (path.isIap) "web" else "ios")
|
||||||
val chargeId = if (path == VerificationPath.GOOGLE) {
|
val chargeId = if (path == VerificationPath.GOOGLE) {
|
||||||
@@ -143,10 +143,10 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
|
|
||||||
val data = successData(post(path.path, verificationRequest(path, chargeId ?: 0), token(owner)))
|
val data = successData(post(path.path, verificationRequest(path, chargeId ?: 0), token(owner)))
|
||||||
|
|
||||||
assertCompletion(data, first = true, iap = path.isIap)
|
val expectedChargeId = chargeId ?: transactionTemplate.execute { chargeRepository.findAll().single().id!! }!!
|
||||||
|
assertCompletion(data, chargeId = expectedChargeId, first = true, iap = path.isIap)
|
||||||
if (chargeId == null) {
|
if (chargeId == null) {
|
||||||
val createdId = transactionTemplate.execute { chargeRepository.findAll().single().id!! }!!
|
assertCompleted(expectedChargeId, owner.id!!, PaymentGateway.GOOGLE_IAP, listOf(0, 0, 100, 0, 0, 0))
|
||||||
assertCompleted(createdId, owner.id!!, PaymentGateway.GOOGLE_IAP, listOf(0, 0, 100, 0, 0, 0))
|
|
||||||
Mockito.verify(googlePlayService).verifyAndConsumePurchase("http-purchase", "http-product")
|
Mockito.verify(googlePlayService).verifyAndConsumePurchase("http-purchase", "http-product")
|
||||||
Mockito.verifyNoInteractions(bootpay, okHttpClient)
|
Mockito.verifyNoInteractions(bootpay, okHttpClient)
|
||||||
} else {
|
} else {
|
||||||
@@ -170,6 +170,7 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
repeat(2) {
|
repeat(2) {
|
||||||
assertCompletion(
|
assertCompletion(
|
||||||
successData(post(path.path, verificationRequest(path, chargeId), bearer)),
|
successData(post(path.path, verificationRequest(path, chargeId), bearer)),
|
||||||
|
chargeId = chargeId,
|
||||||
first = expected,
|
first = expected,
|
||||||
iap = path.isIap
|
iap = path.isIap
|
||||||
)
|
)
|
||||||
@@ -191,10 +192,11 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
val legacyBefore = storedState(legacyId, owner.id!!)
|
val legacyBefore = storedState(legacyId, owner.id!!)
|
||||||
allowGooglePurchase()
|
allowGooglePurchase()
|
||||||
|
|
||||||
assertCompletion(successData(post("/charge/google", googleRequest(), token(owner))), first = false, iap = true)
|
val data = successData(post("/charge/google", googleRequest(), token(owner)))
|
||||||
|
|
||||||
transactionTemplate.executeWithoutResult {
|
transactionTemplate.executeWithoutResult {
|
||||||
val created = chargeRepository.findAll().single { it.id != legacyId }
|
val created = chargeRepository.findAll().single { it.id != legacyId }
|
||||||
|
assertCompletion(data, chargeId = created.id!!, first = false, iap = true)
|
||||||
assertEquals(false, created.isFirstCharged)
|
assertEquals(false, created.isFirstCharged)
|
||||||
assertEquals(PaymentStatus.COMPLETE, created.payment!!.status)
|
assertEquals(PaymentStatus.COMPLETE, created.payment!!.status)
|
||||||
assertEquals("http-google-order", created.payment!!.orderId)
|
assertEquals("http-google-order", created.payment!!.orderId)
|
||||||
@@ -265,6 +267,7 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
val chargeId = createCharge(owner, PaymentGateway.PG, first = true)
|
val chargeId = createCharge(owner, PaymentGateway.PG, first = true)
|
||||||
assertCompletion(
|
assertCompletion(
|
||||||
successData(post("/charge/verify", VerifyRequest("http-receipt", "$chargeId"), token(owner))),
|
successData(post("/charge/verify", VerifyRequest("http-receipt", "$chargeId"), token(owner))),
|
||||||
|
chargeId = chargeId,
|
||||||
first = true,
|
first = true,
|
||||||
iap = false
|
iap = false
|
||||||
)
|
)
|
||||||
@@ -352,6 +355,7 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
val completed = storedState(chargeId, owner.id!!)
|
val completed = storedState(chargeId, owner.id!!)
|
||||||
assertCompletion(
|
assertCompletion(
|
||||||
successData(post("/charge/payverse/verify", PayverseVerifyRequest("http-tid", "$chargeId"), token(owner))),
|
successData(post("/charge/payverse/verify", PayverseVerifyRequest("http-tid", "$chargeId"), token(owner))),
|
||||||
|
chargeId = chargeId,
|
||||||
first = true,
|
first = true,
|
||||||
iap = false
|
iap = false
|
||||||
)
|
)
|
||||||
@@ -453,8 +457,13 @@ class ChargeControllerIntegrationTest @Autowired constructor(
|
|||||||
return body["data"]
|
return body["data"]
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertCompletion(data: JsonNode, first: Boolean, iap: Boolean) {
|
private fun assertCompletion(data: JsonNode, chargeId: Long, first: Boolean, iap: Boolean) {
|
||||||
assertEquals(setOf("price", "currencyCode", "isFirstCharged", "isIap"), data.fieldNames().asSequence().toSet())
|
assertEquals(
|
||||||
|
setOf("chargeId", "price", "currencyCode", "isFirstCharged", "isIap"),
|
||||||
|
data.fieldNames().asSequence().toSet()
|
||||||
|
)
|
||||||
|
assertEquals(true, data["chargeId"].isIntegralNumber)
|
||||||
|
assertEquals(chargeId, data["chargeId"].longValue())
|
||||||
assertEquals(true, data["price"].isNumber)
|
assertEquals(true, data["price"].isNumber)
|
||||||
assertEquals(0, BigDecimal("9.99").compareTo(data["price"].decimalValue()))
|
assertEquals(0, BigDecimal("9.99").compareTo(data["price"].decimalValue()))
|
||||||
assertEquals("USD", data["currencyCode"].textValue())
|
assertEquals("USD", data["currencyCode"].textValue())
|
||||||
|
|||||||
Reference in New Issue
Block a user