Skip to content

Commit

Permalink
Fix Voucher redeemer test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sabercodic committed Oct 13, 2023
1 parent 9612179 commit 3407ded
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class VoucherDialogViewModel(
private val vmState = MutableStateFlow<VoucherDialogState>(VoucherDialogState.Default)
private val voucherInput = MutableStateFlow(LoginUiState.INITIAL.accountNumberInput)

private lateinit var voucherRedeemer: VoucherRedeemer
lateinit var voucherRedeemer: VoucherRedeemer
private val _shared: SharedFlow<ServiceConnectionContainer> =
serviceConnectionManager.connectionState
.flatMapLatest { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.model.VoucherSubmissionError
import net.mullvad.mullvadvpn.model.VoucherSubmissionResult
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionContainer
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionState
import net.mullvad.mullvadvpn.ui.serviceconnection.VoucherRedeemer
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

class VoucherDialogViewModelTest {
@get:Rule val testCoroutineRule = TestCoroutineRule()

private val serviceConnectionState =
MutableStateFlow<ServiceConnectionState>(ServiceConnectionState.Disconnected)
private val mockServiceConnectionManager: ServiceConnectionManager = mockk()
private val mockVoucherRedeemer: VoucherRedeemer = mockk()
private val mockServiceConnectionContainer: ServiceConnectionContainer = mockk()
Expand All @@ -36,8 +39,7 @@ class VoucherDialogViewModelTest {
@Before
fun setUp() {
mockkStatic(CACHE_EXTENSION_CLASS)
every { mockServiceConnectionManager.connectionState.value.readyContainer() } returns
mockServiceConnectionContainer
every { mockServiceConnectionManager.connectionState } returns serviceConnectionState
every { mockServiceConnectionContainer.voucherRedeemer } returns mockVoucherRedeemer

viewModel =
Expand All @@ -53,11 +55,13 @@ class VoucherDialogViewModelTest {
}

@Test
@Ignore("TODO: Fix this failing test and then enable it again.")
fun test_submit_invalid_voucher() = runTest {
val voucher = DUMMY_VALID_VOUCHER
val dummyStringResource = DUMMY_STRING_RESOURCE
// Arrange
serviceConnectionState.value =
ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer)
viewModel.voucherRedeemer = mockVoucherRedeemer
every { mockResources.getString(any()) } returns dummyStringResource
coEvery { mockVoucherRedeemer.submit(voucher) } returns mockVoucherSubmissionErrorResult
// Act, Assert
Expand Down

0 comments on commit 3407ded

Please sign in to comment.