Skip to content

Commit

Permalink
Add PaymentController test:
Browse files Browse the repository at this point in the history
`given collect payment shown, when TRY_OTHER_READ message received, then collect payment hint updated`
  • Loading branch information
samiuelson committed Nov 18, 2024
1 parent 4a52038 commit 96d03b9
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalI
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.REMOVE_CARD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.SWIPE_CARD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.TRY_ANOTHER_CARD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.TRY_ANOTHER_READ_METHOD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.CollectingPayment
import com.woocommerce.android.model.Address
import com.woocommerce.android.model.Order
Expand Down Expand Up @@ -288,6 +289,27 @@ class CardReaderPaymentControllerTest : BaseUnitTest() {
.isEqualTo(R.string.card_reader_payment_card_removed_too_early)
}

@Test
fun `given collect payment shown, when TRY_OTHER_READ message received, then collect payment hint updated`() =
testBlocking {
whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer {
flow {
delay(1) // make sure it's run after collecting payment starts
emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(TRY_ANOTHER_READ_METHOD))
}
}

whenever(cardReaderManager.collectPayment(any())).thenAnswer {
flow { emit(CollectingPayment) }
}

controller.start()
advanceUntilIdle()

assertThat((controller.paymentState.value as CardReaderPaymentState.CollectingPayment).cardReaderHint)
.isEqualTo(R.string.card_reader_payment_try_another_read_method_prompt)
}

companion object {
private const val ORDER_ID = 1L
private val siteModel = SiteModel().apply { name = "testName" }.apply { url = "testUrl.com" }
Expand Down

0 comments on commit 96d03b9

Please sign in to comment.