Skip to content

Commit

Permalink
Add PaymentController test:
Browse files Browse the repository at this point in the history
`given collect payment shown, when SWIPE_CARD received, then collect payment hint updated`
  • Loading branch information
samiuelson committed Nov 18, 2024
1 parent 662b0f2 commit d5c8096
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.woocommerce.android.cardreader.connection.event.BluetoothCardReaderMe
import com.woocommerce.android.cardreader.connection.event.CardReaderBatteryStatus
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.AdditionalInfoType
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.SWIPE_CARD
import com.woocommerce.android.cardreader.payments.CardPaymentStatus.CollectingPayment
import com.woocommerce.android.model.Address
import com.woocommerce.android.model.Order
Expand Down Expand Up @@ -182,6 +184,44 @@ class CardReaderPaymentControllerTest : BaseUnitTest() {
.isEqualTo(R.string.card_reader_payment_collect_payment_hint)
}

@Test
fun `given collect payment shown, when INSERT_OR_SWIPE_CARD received, then collect payment hint updated`() =
testBlocking {
whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer {
flow {
emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(INSERT_OR_SWIPE_CARD))
}
}

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

controller.start()

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

@Test
fun `given collect payment shown, when SWIPE_CARD received, then collect payment hint updated`() =
testBlocking {
whenever(cardReaderManager.displayBluetoothCardReaderMessages).thenAnswer {
flow {
emit(BluetoothCardReaderMessages.CardReaderDisplayMessage(SWIPE_CARD))
}
}

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

controller.start()

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

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 d5c8096

Please sign in to comment.