Fix instrumentation tests for payments.

This commit is contained in:
Alex Hart
2025-03-26 10:12:00 -03:00
committed by Cody Henthorne
parent 71a44e1ebd
commit c0113436a2
3 changed files with 11 additions and 28 deletions

View File

@@ -11,6 +11,7 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToNode
import androidx.compose.ui.test.performTextInput
import androidx.core.content.ContextCompat
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -158,7 +159,7 @@ class MessageBackupsCheckoutActivityTest {
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__copy_to_clipboard)).performClick()
scenario.onActivity {
val backupKeyString = SignalStore.account.accountEntropyPool.value.chunked(4).joinToString(" ")
val backupKeyString = SignalStore.account.accountEntropyPool.displayValue.chunked(4).joinToString(" ")
val clipboardManager = ContextCompat.getSystemService(context, ClipboardManager::class.java)
assertThat(clipboardManager?.primaryClip?.getItemAt(0)?.coerceToText(context)).isEqualTo(backupKeyString)
}
@@ -166,12 +167,18 @@ class MessageBackupsCheckoutActivityTest {
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__next)).assertIsDisplayed()
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__next)).performClick()
// Key verification page
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyVerifyScreen__enter_the_backup_key_that_you_just_recorded)).assertIsDisplayed()
composeTestRule.onNodeWithTag("message-backups-key-verify-screen-backup-key-input-field").performTextInput(
SignalStore.account.accountEntropyPool.displayValue
)
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__next)).assertIsEnabled()
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__next)).performClick()
// Key record bottom sheet
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__keep_your_key_safe)).assertIsDisplayed()
composeTestRule.onNodeWithTag("message-backups-key-record-screen-sheet-content")
.performScrollToNode(hasText(context.getString(R.string.MessageBackupsKeyRecordScreen__continue)))
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__continue)).assertIsNotEnabled()
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__ive_recorded_my_key)).performClick()
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__continue)).assertIsEnabled()
composeTestRule.onNodeWithText(context.getString(R.string.MessageBackupsKeyRecordScreen__continue)).performClick()

View File

@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.jobs
import androidx.test.ext.junit.runners.AndroidJUnit4
import assertk.assertThat
import assertk.assertions.hasSize
import assertk.assertions.isEmpty
import okhttp3.mockwebserver.MockResponse
import org.junit.Before
@@ -69,30 +68,6 @@ class InAppPaymentAuthCheckJobTest {
assertThat(receipts).isEmpty()
}
@Test
fun givenSuccessfulOneTimeAuthRequiredPayment_whenICheck_thenIExpectAReceipt() {
initializeMockGetPaymentIntent(status = StripeIntentStatus.SUCCEEDED)
SignalDatabase.inAppPayments.insert(
type = InAppPaymentType.ONE_TIME_DONATION,
state = InAppPaymentTable.State.WAITING_FOR_AUTHORIZATION,
subscriberId = null,
endOfPeriod = null,
inAppPaymentData = InAppPaymentData(
amount = FiatMoney(BigDecimal.ONE, Currency.getInstance("USD")).toFiatValue(),
waitForAuth = InAppPaymentData.WaitingForAuthorizationState(
stripeIntentId = TEST_INTENT_ID,
stripeClientSecret = TEST_CLIENT_SECRET
)
)
)
InAppPaymentAuthCheckJob().run()
val receipts = SignalDatabase.donationReceipts.getReceipts(InAppPaymentReceiptRecord.Type.ONE_TIME_DONATION)
assertThat(receipts).hasSize(1)
}
private fun initializeMockGetPaymentIntent(status: StripeIntentStatus) {
InstrumentationApplicationDependencyProvider.addMockWebRequestHandlers(
Get(TestStripePaths.getPaymentIntentPath(TEST_INTENT_ID, TEST_CLIENT_SECRET)) {