Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Dec 11, 2024
1 parent cf636a5 commit a347cd4
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class LinkActivityContractTest {
@Test
fun `LinkActivityContract creates intent with URL with native link disabled`() {
featureFlagTestRule.setEnabled(false)
val config = com.stripe.android.link.LinkConfiguration(
val config = LinkConfiguration(
stripeIntent = StripeIntentFixtures.PI_SUCCEEDED,
merchantName = "Merchant, Inc",
merchantCountryCode = "US",
customerInfo = com.stripe.android.link.LinkConfiguration.CustomerInfo(
customerInfo = LinkConfiguration.CustomerInfo(
name = "Name",
email = "customer@email.com",
phone = "1234567890",
Expand All @@ -58,27 +58,27 @@ class LinkActivityContractTest {
cardBrandChoice = null,
)

val args = com.stripe.android.link.LinkActivityContract.Args(
val args = LinkActivityContract.Args(
config,
)
val stripeRepository = mock<StripeRepository>()
whenever(stripeRepository.buildPaymentUserAgent(any())).thenReturn("test")
val contract = com.stripe.android.link.LinkActivityContract(stripeRepository)
val contract = LinkActivityContract(stripeRepository)
val intent = contract.createIntent(ApplicationProvider.getApplicationContext(), args)
assertThat(intent.component?.className).isEqualTo(com.stripe.android.link.LinkForegroundActivity::class.java.name)
assertThat(intent.extras?.getString(com.stripe.android.link.LinkForegroundActivity.EXTRA_POPUP_URL)).startsWith(
assertThat(intent.component?.className).isEqualTo(LinkForegroundActivity::class.java.name)
assertThat(intent.extras?.getString(LinkForegroundActivity.EXTRA_POPUP_URL)).startsWith(
"https://checkout.link.com/#"
)
}

@Test
fun `LinkActivityContract creates intent with with NativeLinkArgs when native link is enabled`() {
featureFlagTestRule.setEnabled(true)
val config = com.stripe.android.link.LinkConfiguration(
val config = LinkConfiguration(
stripeIntent = StripeIntentFixtures.PI_SUCCEEDED,
merchantName = "Merchant, Inc",
merchantCountryCode = "US",
customerInfo = com.stripe.android.link.LinkConfiguration.CustomerInfo(
customerInfo = LinkConfiguration.CustomerInfo(
name = "Name",
email = "customer@email.com",
phone = "1234567890",
Expand All @@ -90,16 +90,16 @@ class LinkActivityContractTest {
cardBrandChoice = null,
)

val args = com.stripe.android.link.LinkActivityContract.Args(
val args = LinkActivityContract.Args(
config,
)
val stripeRepository = mock<StripeRepository>()
whenever(stripeRepository.buildPaymentUserAgent(any())).thenReturn("test")
val contract = com.stripe.android.link.LinkActivityContract(stripeRepository)
val contract = LinkActivityContract(stripeRepository)
val intent = contract.createIntent(ApplicationProvider.getApplicationContext(), args)
assertThat(intent.component?.className).isEqualTo(com.stripe.android.link.LinkActivity::class.java.name)
assertThat(intent.extras?.getParcelable<com.stripe.android.link.NativeLinkArgs>(com.stripe.android.link.LinkActivity.EXTRA_ARGS)).isEqualTo(
com.stripe.android.link.NativeLinkArgs(
assertThat(intent.component?.className).isEqualTo(LinkActivity::class.java.name)
assertThat(intent.extras?.getParcelable<NativeLinkArgs>(LinkActivity.EXTRA_ARGS)).isEqualTo(
NativeLinkArgs(
configuration = config,
publishableKey = "pk_test_abcdefg",
stripeAccountId = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class LinkActivityResultTest {
"link-popup://complete?link_status=complete&pm=eyJpZCI6InBtXzFOSmVFckx1NW8zUDE4WnBtWHBDdElyUiIsIm9iamVjdCI6InBheW1lbnRfbWV0aG9kIiwiYmlsbGluZ19kZXRhaWxzIjp7ImFkZHJlc3MiOnsiY2l0eSI6bnVsbCwiY291bnRyeSI6bnVsbCwibGluZTEiOm51bGwsImxpbmUyIjpudWxsLCJwb3N0YWxfY29kZSI6bnVsbCwic3RhdGUiOm51bGx9LCJlbWFpbCI6bnVsbCwibmFtZSI6bnVsbCwicGhvbmUiOm51bGx9LCJjYXJkIjp7ImJyYW5kIjoidmlzYSIsImNoZWNrcyI6eyJhZGRyZXNzX2xpbmUxX2NoZWNrIjpudWxsLCJhZGRyZXNzX3Bvc3RhbF9jb2RlX2NoZWNrIjpudWxsLCJjdmNfY2hlY2siOm51bGx9LCJjb3VudHJ5IjpudWxsLCJleHBfbW9udGgiOjEyLCJleHBfeWVhciI6MjAzNCwiZnVuZGluZyI6ImNyZWRpdCIsImdlbmVyYXRlZF9mcm9tIjpudWxsLCJsYXN0NCI6IjAwMDAiLCJuZXR3b3JrcyI6eyJhdmFpbGFibGUiOlsidmlzYSJdLCJwcmVmZXJyZWQiOm51bGx9LCJ0aHJlZV9kX3NlY3VyZV91c2FnZSI6eyJzdXBwb3J0ZWQiOnRydWV9LCJ3YWxsZXQiOnsiZHluYW1pY19sYXN0NCI6bnVsbCwibGluayI6e30sInR5cGUiOiJsaW5rIn19LCJjcmVhdGVkIjoxNjg2OTI4MDIxLCJjdXN0b21lciI6bnVsbCwibGl2ZW1vZGUiOmZhbHNlLCJ0eXBlIjoiY2FyZCJ9ICAg"
val intent = Intent()
intent.data = redirectUrl.toUri()
val result = com.stripe.android.link.createLinkActivityResult(
com.stripe.android.link.LinkForegroundActivity.RESULT_COMPLETE,
val result = createLinkActivityResult(
LinkForegroundActivity.RESULT_COMPLETE,
intent
)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Completed::class.java)
val completed = result as com.stripe.android.link.LinkActivityResult.Completed
assertThat(result).isInstanceOf(LinkActivityResult.Completed::class.java)
val completed = result as LinkActivityResult.Completed
assertThat(completed.paymentMethod.type?.code).isEqualTo("card")
assertThat(completed.paymentMethod.card?.last4).isEqualTo("0000")
assertThat(completed.paymentMethod.id).isEqualTo("pm_1NJeErLu5o3P18ZpmXpCtIrR")
Expand All @@ -33,67 +33,67 @@ class LinkActivityResultTest {
val redirectUrl = "link-popup://complete?link_status=logout"
val intent = Intent()
intent.data = redirectUrl.toUri()
val result = com.stripe.android.link.createLinkActivityResult(
com.stripe.android.link.LinkForegroundActivity.RESULT_COMPLETE,
val result = createLinkActivityResult(
LinkForegroundActivity.RESULT_COMPLETE,
intent
)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Canceled::class.java)
val canceled = result as com.stripe.android.link.LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(com.stripe.android.link.LinkActivityResult.Canceled.Reason.LoggedOut)
assertThat(result).isInstanceOf(LinkActivityResult.Canceled::class.java)
val canceled = result as LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(LinkActivityResult.Canceled.Reason.LoggedOut)
}

@Test
fun `complete with unknown link_status results in canceled`() {
val redirectUrl = "link-popup://complete?link_status=shrug"
val intent = Intent()
intent.data = redirectUrl.toUri()
val result = com.stripe.android.link.createLinkActivityResult(
com.stripe.android.link.LinkForegroundActivity.RESULT_COMPLETE,
val result = createLinkActivityResult(
LinkForegroundActivity.RESULT_COMPLETE,
intent
)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Canceled::class.java)
val canceled = result as com.stripe.android.link.LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(com.stripe.android.link.LinkActivityResult.Canceled.Reason.BackPressed)
assertThat(result).isInstanceOf(LinkActivityResult.Canceled::class.java)
val canceled = result as LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(LinkActivityResult.Canceled.Reason.BackPressed)
}

@Test
fun `canceled result code`() {
val result = com.stripe.android.link.createLinkActivityResult(Activity.RESULT_CANCELED, null)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Canceled::class.java)
val canceled = result as com.stripe.android.link.LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(com.stripe.android.link.LinkActivityResult.Canceled.Reason.BackPressed)
val result = createLinkActivityResult(Activity.RESULT_CANCELED, null)
assertThat(result).isInstanceOf(LinkActivityResult.Canceled::class.java)
val canceled = result as LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(LinkActivityResult.Canceled.Reason.BackPressed)
}

@Test
fun `failure with data`() {
val intent = Intent()
intent.putExtra(com.stripe.android.link.LinkForegroundActivity.EXTRA_FAILURE, IllegalStateException("Foobar!"))
val result = com.stripe.android.link.createLinkActivityResult(
com.stripe.android.link.LinkForegroundActivity.RESULT_FAILURE,
intent.putExtra(LinkForegroundActivity.EXTRA_FAILURE, IllegalStateException("Foobar!"))
val result = createLinkActivityResult(
LinkForegroundActivity.RESULT_FAILURE,
intent
)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Failed::class.java)
val failed = result as com.stripe.android.link.LinkActivityResult.Failed
assertThat(result).isInstanceOf(LinkActivityResult.Failed::class.java)
val failed = result as LinkActivityResult.Failed
assertThat(failed.error).hasMessageThat().isEqualTo("Foobar!")
}

@Test
fun `failure without data results in canceled`() {
val result = com.stripe.android.link.createLinkActivityResult(
com.stripe.android.link.LinkForegroundActivity.RESULT_FAILURE,
val result = createLinkActivityResult(
LinkForegroundActivity.RESULT_FAILURE,
null
)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Canceled::class.java)
val canceled = result as com.stripe.android.link.LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(com.stripe.android.link.LinkActivityResult.Canceled.Reason.BackPressed)
assertThat(result).isInstanceOf(LinkActivityResult.Canceled::class.java)
val canceled = result as LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(LinkActivityResult.Canceled.Reason.BackPressed)
}

@Test
fun `unknown result code results in canceled`() {
val result = com.stripe.android.link.createLinkActivityResult(42, null)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Canceled::class.java)
val canceled = result as com.stripe.android.link.LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(com.stripe.android.link.LinkActivityResult.Canceled.Reason.BackPressed)
val result = createLinkActivityResult(42, null)
assertThat(result).isInstanceOf(LinkActivityResult.Canceled::class.java)
val canceled = result as LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(LinkActivityResult.Canceled.Reason.BackPressed)
}

@Test
Expand All @@ -102,12 +102,12 @@ class LinkActivityResultTest {
"link-popup://complete?link_status=complete&pm=🤷‍"
val intent = Intent()
intent.data = redirectUrl.toUri()
val result = com.stripe.android.link.createLinkActivityResult(
com.stripe.android.link.LinkForegroundActivity.RESULT_COMPLETE,
val result = createLinkActivityResult(
LinkForegroundActivity.RESULT_COMPLETE,
intent
)
assertThat(result).isInstanceOf(com.stripe.android.link.LinkActivityResult.Canceled::class.java)
val canceled = result as com.stripe.android.link.LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(com.stripe.android.link.LinkActivityResult.Canceled.Reason.BackPressed)
assertThat(result).isInstanceOf(LinkActivityResult.Canceled::class.java)
val canceled = result as LinkActivityResult.Canceled
assertThat(canceled.reason).isEqualTo(LinkActivityResult.Canceled.Reason.BackPressed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ internal class LinkActivityTest {
@Test
fun `finishes with a cancelled result when no arg is passed`() {
val intent =
Intent(ApplicationProvider.getApplicationContext(), com.stripe.android.link.LinkActivity::class.java)
Intent(ApplicationProvider.getApplicationContext(), LinkActivity::class.java)

val scenario = ActivityScenario.launchActivityForResult<com.stripe.android.link.LinkActivity>(intent)
val scenario = ActivityScenario.launchActivityForResult<LinkActivity>(intent)

assertThat(scenario.result.resultCode)
.isEqualTo(Activity.RESULT_CANCELED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import kotlin.test.assertFailsWith
internal class LinkActivityViewModelTest {
private val dispatcher = UnconfinedTestDispatcher()
private val linkAccountManager = FakeLinkAccountManager()
private val vm = com.stripe.android.link.LinkActivityViewModel(mock(), linkAccountManager)
private val vm = LinkActivityViewModel(mock(), linkAccountManager)
private val navController: NavHostController = mock()
private val dismissWithResult: (com.stripe.android.link.LinkActivityResult) -> Unit = mock()
private val dismissWithResult: (LinkActivityResult) -> Unit = mock()

private val application: Application = ApplicationProvider.getApplicationContext()

Expand All @@ -57,20 +57,20 @@ internal class LinkActivityViewModelTest {
fun `test that cancel result is called on back pressed with empty stack`() = runTest(dispatcher) {
whenever(navController.popBackStack()).thenReturn(false)

vm.handleViewAction(com.stripe.android.link.LinkAction.BackPressed)
vm.handleViewAction(LinkAction.BackPressed)

verify(navController).popBackStack()
verify(dismissWithResult).invoke(com.stripe.android.link.LinkActivityResult.Canceled())
verify(dismissWithResult).invoke(LinkActivityResult.Canceled())
}

@Test
fun `test that cancel result is called on back pressed with non-empty stack`() = runTest(dispatcher) {
whenever(navController.popBackStack()).thenReturn(true)

vm.handleViewAction(com.stripe.android.link.LinkAction.BackPressed)
vm.handleViewAction(LinkAction.BackPressed)

verify(navController).popBackStack()
verify(dismissWithResult, times(0)).invoke(com.stripe.android.link.LinkActivityResult.Canceled())
verify(dismissWithResult, times(0)).invoke(LinkActivityResult.Canceled())
}

@Test
Expand All @@ -85,30 +85,30 @@ internal class LinkActivityViewModelTest {
fun `initializer throws exception when args are null`() {
val savedStateHandle = SavedStateHandle()
.apply {
set(com.stripe.android.link.LinkActivity.EXTRA_ARGS, null)
set(LinkActivity.EXTRA_ARGS, null)
}

val factory = com.stripe.android.link.LinkActivityViewModel.factory(savedStateHandle)
val factory = LinkActivityViewModel.factory(savedStateHandle)

assertFailsWith<com.stripe.android.link.NoArgsException> {
factory.create(com.stripe.android.link.LinkActivityViewModel::class.java, creationExtras())
assertFailsWith<NoArgsException> {
factory.create(LinkActivityViewModel::class.java, creationExtras())
}.also { exception ->
assertThat(exception.message).isEqualTo("NativeLinkArgs not found")
}
}

@Test
fun `initializer creates ViewModel when args are valid`() {
val mockArgs = com.stripe.android.link.NativeLinkArgs(
val mockArgs = NativeLinkArgs(
configuration = mock(),
publishableKey = "",
stripeAccountId = null
)
val savedStateHandle = SavedStateHandle()
val factory = com.stripe.android.link.LinkActivityViewModel.factory(savedStateHandle)
savedStateHandle[com.stripe.android.link.LinkActivity.EXTRA_ARGS] = mockArgs
val factory = LinkActivityViewModel.factory(savedStateHandle)
savedStateHandle[LinkActivity.EXTRA_ARGS] = mockArgs

val viewModel = factory.create(com.stripe.android.link.LinkActivityViewModel::class.java, creationExtras())
val viewModel = factory.create(LinkActivityViewModel::class.java, creationExtras())
assertThat(viewModel.activityRetainedComponent.configuration).isEqualTo(mockArgs.configuration)
}

Expand All @@ -127,7 +127,7 @@ internal class LinkActivityViewModelTest {
set(SAVED_STATE_REGISTRY_OWNER_KEY, mockOwner)
set(APPLICATION_KEY, application)
set(VIEW_MODEL_STORE_OWNER_KEY, mockViewModelStoreOwner)
set(VIEW_MODEL_KEY, com.stripe.android.link.LinkActivityViewModel::class.java.name)
set(VIEW_MODEL_KEY, LinkActivityViewModel::class.java.name)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class LinkConfigurationCoordinatorTest {
private val config = com.stripe.android.link.LinkConfiguration(
private val config = LinkConfiguration(
stripeIntent = StripeIntentFixtures.PI_SUCCEEDED,
merchantName = MERCHANT_NAME,
merchantCountryCode = "US",
customerInfo = com.stripe.android.link.LinkConfiguration.CustomerInfo(
customerInfo = LinkConfiguration.CustomerInfo(
name = CUSTOMER_NAME,
email = CUSTOMER_EMAIL,
phone = CUSTOMER_PHONE,
Expand All @@ -35,13 +35,12 @@ class LinkConfigurationCoordinatorTest {

private val linkComponentBuilder: LinkComponent.Builder = mock()

private var linkConfigurationCoordinator =
com.stripe.android.link.RealLinkConfigurationCoordinator(linkComponentBuilder)
private var linkConfigurationCoordinator = RealLinkConfigurationCoordinator(linkComponentBuilder)

init {
FakeAndroidKeyStore.setup()

val configurationCapture = argumentCaptor<com.stripe.android.link.LinkConfiguration>()
val configurationCapture = argumentCaptor<LinkConfiguration>()

whenever(linkComponentBuilder.configuration(configurationCapture.capture()))
.thenReturn(linkComponentBuilder)
Expand Down
Loading

0 comments on commit a347cd4

Please sign in to comment.