Skip to content

Commit

Permalink
Move CustoemrSheet card tests to their own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
samer-stripe committed May 24, 2024
1 parent 92496a8 commit 142b059
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ import com.stripe.android.paymentsheet.example.playground.settings.CollectAddres
import com.stripe.android.paymentsheet.example.playground.settings.CollectEmailSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CollectNameSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CollectPhoneSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerSheetPaymentMethodModeDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerType
import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddress
import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddressSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.PaymentMethodMode
import com.stripe.android.paymentsheet.example.samples.ui.shared.PAYMENT_METHOD_SELECTOR_TEST_TAG
import com.stripe.android.paymentsheet.ui.SAVED_PAYMENT_OPTION_TEST_TAG
import com.stripe.android.test.core.AuthorizeAction
Expand Down Expand Up @@ -318,112 +312,4 @@ internal class TestCard : BasePlaygroundTest() {
values = FieldPopulator.Values(cardNumber = "4000000000003220")
)
}

@Test
fun testCardInCustomerSheet() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.CreateAndAttach
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithSetupIntentInCustomerSheet() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.SetupIntent
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithNonUsMerchantInCustomerSheet() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.FR
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.CreateAndAttach
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithSetupIntentAndNonUsMerchantInCustomerSheet() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.FR
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.SetupIntent
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithBillingDetailsCollectionInCustomerSheet() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(
paymentMethodCode = "card",
) { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.Off
settings[CollectNameSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectEmailSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectPhoneSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectAddressSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
},
populateCustomLpmFields = {
populateCardDetails()
populateEmail()
populateName("Name on card")
populateAddress()
populatePhoneNumber()
},
)
}

@Test
fun testCardWithBillingDetailsCollectionWithDefaultsInCustomerSheet() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(
paymentMethodCode = "card",
) { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.On
settings[CollectNameSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectEmailSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectPhoneSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectAddressSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.stripe.android.lpm

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.example.playground.settings.CollectAddressSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CollectEmailSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CollectNameSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CollectPhoneSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerSheetPaymentMethodModeDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CustomerType
import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddress
import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddressSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.PaymentMethodMode
import com.stripe.android.test.core.TestParameters
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class TestCardInCustomerSheet : BasePlaygroundTest() {
@Test
fun testCard() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.CreateAndAttach
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithSetupIntent() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.SetupIntent
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithNonUsMerchant() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.FR
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.CreateAndAttach
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithSetupIntentAndNonUsMerchant() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(paymentMethodCode = "card").copyPlaygroundSettings { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.FR
settings[CustomerSheetPaymentMethodModeDefinition] = PaymentMethodMode.SetupIntent
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}

@Test
fun testCardWithBillingDetailsCollection() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(
paymentMethodCode = "card",
) { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.Off
settings[CollectNameSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectEmailSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectPhoneSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectAddressSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
},
populateCustomLpmFields = {
populateCardDetails()
populateEmail()
populateName("Name on card")
populateAddress()
populatePhoneNumber()
},
)
}

@Test
fun testCardWithBillingDetailsCollectionWithDefaults() {
testDriver.savePaymentMethodInCustomerSheet(
TestParameters.create(
paymentMethodCode = "card",
) { settings ->
settings[CustomerSettingsDefinition] = CustomerType.NEW
settings[CountrySettingsDefinition] = Country.US
settings[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.On
settings[CollectNameSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectEmailSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectPhoneSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
settings[CollectAddressSettingsDefinition] =
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
},
populateCustomLpmFields = {
populateCardDetails()
},
)
}
}

0 comments on commit 142b059

Please sign in to comment.