Skip to content

Commit

Permalink
Add PaymentController test:
Browse files Browse the repository at this point in the history
`given collect payment shown, when CARD_REMOVED_TOO_EARLY message received, then collect payment hint updated`
  • Loading branch information
samiuelson committed Nov 18, 2024
1 parent 9086eba commit 4a52038
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.woocommerce.android.cardreader.connection.CardReaderStatus
import com.woocommerce.android.cardreader.connection.event.BluetoothCardReaderMessages
import com.woocommerce.android.cardreader.connection.event.CardReaderBatteryStatus
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.CARD_REMOVED_TOO_EARLY
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.INSERT_CARD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.INSERT_OR_SWIPE_CARD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType.REMOVE_CARD
Expand Down Expand Up @@ -266,6 +267,27 @@ class CardReaderPaymentControllerTest : BaseUnitTest() {
.isEqualTo(R.string.card_reader_payment_try_another_card_prompt)
}

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

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_card_removed_too_early)
}

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 4a52038

Please sign in to comment.