-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use locale in PopupPayload
#8147
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package com.stripe.android.link.serialization | ||
|
||
import android.content.Context | ||
import android.os.LocaleList | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.core.networking.AnalyticsRequestFactory | ||
import com.stripe.android.link.LinkConfiguration | ||
import com.stripe.android.link.ui.inline.LinkSignupMode | ||
import com.stripe.android.testing.PaymentIntentFactory | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import java.util.Locale | ||
import java.util.UUID | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
|
@@ -28,6 +35,52 @@ internal class PopupPayloadTest { | |
assertThat(createPayload().toUrl()).isEqualTo("https://checkout.link.com/#eyJwdWJsaXNoYWJsZUtleSI6InBrX3Rlc3RfYWJjIiwic3RyaXBlQWNjb3VudCI6IjEyMyIsIm1lcmNoYW50SW5mbyI6eyJidXNpbmVzc05hbWUiOiJKYXkncyBUYWNvIFN0YW5kIiwiY291bnRyeSI6IlVTIn0sImN1c3RvbWVySW5mbyI6eyJlbWFpbCI6ImpheXN0YWNvc3RhbmRmYWtlQGdtYWlsLmNvbSIsImNvdW50cnkiOiJVUyJ9LCJwYXltZW50SW5mbyI6eyJjdXJyZW5jeSI6IlVTRCIsImFtb3VudCI6NTU1NX0sImFwcElkIjoiZXhhbXBsZS5zdHJpcGUudW5pdHRlc3QiLCJsb2NhbGUiOiJVUyIsInBheW1lbnRVc2VyQWdlbnQiOiJ0ZXN0IiwicGF5bWVudE9iamVjdCI6ImxpbmtfcGF5bWVudF9tZXRob2QiLCJmbGFncyI6eyJsaW5rX2F1dGhlbnRpY2F0ZWRfY2hhbmdlX2V2ZW50X2VuYWJsZWQiOmZhbHNlLCJsaW5rX2JhbmtfaW5jZW50aXZlc19lbmFibGVkIjpmYWxzZSwibGlua19iYW5rX29uYm9hcmRpbmdfZW5hYmxlZCI6ZmFsc2UsImxpbmtfZW1haWxfdmVyaWZpY2F0aW9uX2xvZ2luX2VuYWJsZWQiOmZhbHNlLCJsaW5rX2ZpbmFuY2lhbF9pbmNlbnRpdmVzX2V4cGVyaW1lbnRfZW5hYmxlZCI6ZmFsc2UsImxpbmtfbG9jYWxfc3RvcmFnZV9sb2dpbl9lbmFibGVkIjp0cnVlLCJsaW5rX29ubHlfZm9yX3BheW1lbnRfbWV0aG9kX3R5cGVzX2VuYWJsZWQiOmZhbHNlLCJsaW5rX3Bhc3N0aHJvdWdoX21vZGVfZW5hYmxlZCI6dHJ1ZX0sInBhdGgiOiJtb2JpbGVfcGF5IiwiaW50ZWdyYXRpb25UeXBlIjoibW9iaWxlIiwibG9nZ2VyTWV0YWRhdGEiOnsibW9iaWxlX3Nlc3Npb25faWQiOiI1MzdhODhmZi1hNTRmLTQyY2MtYmE1Mi1jN2M1NjIzNzMwYjYifSwiZXhwZXJpbWVudHMiOnt9fQ==") | ||
} | ||
|
||
@Test | ||
fun `on 'create' with customer billing country provided, should use provided country`() { | ||
val payload = PopupPayload.create( | ||
configuration = createLinkConfiguration(customerCountryCode = "US"), | ||
context = getContext(Locale.CANADA), | ||
paymentUserAgent = "Android", | ||
publishableKey = "pk_123", | ||
stripeAccount = "str_123" | ||
) | ||
|
||
assertThat(payload.customerInfo.country).isEqualTo("US") | ||
} | ||
|
||
@Test | ||
fun `on 'create' with no customer billing country provided, should use locale`() { | ||
val payload = PopupPayload.create( | ||
configuration = createLinkConfiguration(customerCountryCode = null), | ||
context = getContext(Locale.CANADA), | ||
paymentUserAgent = "Android", | ||
publishableKey = "pk_123", | ||
stripeAccount = "str_123" | ||
) | ||
|
||
assertThat(payload.customerInfo.country).isEqualTo("CA") | ||
} | ||
|
||
private fun createLinkConfiguration( | ||
customerCountryCode: String? | ||
): LinkConfiguration { | ||
return LinkConfiguration( | ||
merchantName = "Jay's Taco Stand", | ||
merchantCountryCode = "US", | ||
customerInfo = LinkConfiguration.CustomerInfo( | ||
name = "John", | ||
email = "john@email.com", | ||
billingCountryCode = customerCountryCode, | ||
phone = null, | ||
), | ||
flags = emptyMap(), | ||
passthroughModeEnabled = true, | ||
shippingValues = emptyMap(), | ||
signupMode = LinkSignupMode.InsteadOfSaveForFutureUse, | ||
stripeIntent = PaymentIntentFactory.create() | ||
) | ||
} | ||
|
||
private fun createPayload(): PopupPayload = PopupPayload( | ||
publishableKey = "pk_test_abc", | ||
stripeAccount = "123", | ||
|
@@ -58,4 +111,16 @@ internal class PopupPayloadTest { | |
"link_passthrough_mode_enabled" to true, | ||
), | ||
) | ||
|
||
private fun getContext(locale: Locale): Context { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems useful! Do we have test utils or anything like that? It'd be nice to have an easy way to find functions like this if I ever wanted to use one. Not necessary for this PR just an idea :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a test util for this as part of the new testing module @tjclawson-stripe will be adding. |
||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
|
||
val configuration = context.resources.configuration | ||
|
||
configuration.setLocales(LocaleList(locale)) | ||
|
||
context.createConfigurationContext(configuration) | ||
|
||
return context | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆