|
| 1 | +package com.braintreepayments.api.paypal |
| 2 | + |
| 3 | +import org.json.JSONObject |
| 4 | +import org.junit.runner.RunWith |
| 5 | +import org.robolectric.RobolectricTestParameterInjector |
| 6 | +import kotlin.test.Test |
| 7 | +import kotlin.test.assertEquals |
| 8 | +import kotlin.test.assertFalse |
| 9 | +import kotlin.test.assertTrue |
| 10 | + |
| 11 | +@RunWith(RobolectricTestParameterInjector::class) |
| 12 | +class PayPalPaymentResourceUnitTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + fun `fromJson parses redirectUrl from one-time PaymentResource app switch flow`() { |
| 16 | + val oneTimePaymentJson = JSONObject() |
| 17 | + .put("paymentResource", JSONObject() |
| 18 | + .put("redirectUrl", "www.example.com/redirect") |
| 19 | + .put("launchPayPalApp", true) |
| 20 | + ).toString() |
| 21 | + |
| 22 | + val sut = PayPalPaymentResource.fromJson(oneTimePaymentJson) |
| 23 | + assertEquals("www.example.com/redirect", sut.redirectUrl) |
| 24 | + assertTrue(sut.isAppSwitchFlow) |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + fun `fromJson parses redirectUrl from one-time PaymentResource fallback flow`() { |
| 29 | + val oneTimePaymentJson = JSONObject() |
| 30 | + .put("paymentResource", JSONObject() |
| 31 | + .put("redirectUrl", "www.example.com/redirect") |
| 32 | + .put("launchPayPalApp", false) |
| 33 | + ).toString() |
| 34 | + |
| 35 | + val sut = PayPalPaymentResource.fromJson(oneTimePaymentJson) |
| 36 | + assertEquals("www.example.com/redirect", sut.redirectUrl) |
| 37 | + assertFalse(sut.isAppSwitchFlow) |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun `fromJson parses redirectUrl from billingAgreement PaymentResource`() { |
| 42 | + val billingAgreementJson = JSONObject() |
| 43 | + .put("agreementSetup", JSONObject() |
| 44 | + .put("approvalUrl", "www.example.com/redirect") |
| 45 | + ).toString() |
| 46 | + |
| 47 | + val sut = PayPalPaymentResource.fromJson(billingAgreementJson) |
| 48 | + assertEquals("www.example.com/redirect", sut.redirectUrl) |
| 49 | + assertFalse(sut.isAppSwitchFlow) |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun `fromJson parses redirectUrl from billingAgreement PaymentResource returns PayPalRedirectUrl`() { |
| 54 | + val billingAgreementJson = JSONObject() |
| 55 | + .put("agreementSetup", JSONObject() |
| 56 | + .put("approvalUrl", "www.example.com/redirect") |
| 57 | + .put("paypalAppApprovalUrl", "www.paypal.example.com/redirect") |
| 58 | + ).toString() |
| 59 | + |
| 60 | + val sut = PayPalPaymentResource.fromJson(billingAgreementJson) |
| 61 | + assertEquals("www.paypal.example.com/redirect", sut.redirectUrl) |
| 62 | + assertTrue(sut.isAppSwitchFlow) |
| 63 | + } |
| 64 | +} |
0 commit comments