Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Aug 9, 2024
1 parent c2b67ce commit e29b0a0
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.mullvad.mullvadvpn.compose.state.VoucherDialogState
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.lib.model.RedeemVoucherError
import net.mullvad.mullvadvpn.lib.model.RedeemVoucherSuccess
import net.mullvad.mullvadvpn.lib.model.VoucherCode
import net.mullvad.mullvadvpn.lib.shared.VoucherRepository
import org.joda.time.DateTime
import org.junit.jupiter.api.AfterEach
Expand Down Expand Up @@ -45,19 +46,20 @@ class VoucherDialogViewModelTest {
@Test
fun `ensure onRedeem invokes submit on VoucherRedeemer with same voucher code`() = runTest {
val voucher = DUMMY_INVALID_VOUCHER
val parsedVoucher = VoucherCode.fromString(voucher).getOrNull()!!

// Arrange
val timeAdded = 0L
val newExpiry = DateTime()
coEvery { mockVoucherRepository.submitVoucher(voucher) } returns
coEvery { mockVoucherRepository.submitVoucher(parsedVoucher) } returns
RedeemVoucherSuccess(timeAdded, newExpiry).right()

// Act
assertIs<VoucherDialogState.Default>(viewModel.uiState.value.voucherState)
viewModel.onRedeem(voucher)

// Assert
coVerify(exactly = 1) { mockVoucherRepository.submitVoucher(voucher) }
coVerify(exactly = 1) { mockVoucherRepository.submitVoucher(parsedVoucher) }
}

@Test
Expand All @@ -66,8 +68,9 @@ class VoucherDialogViewModelTest {

// Arrange
every { mockVoucherSubmission.timeAdded } returns 0
coEvery { mockVoucherRepository.submitVoucher(voucher) } returns
RedeemVoucherError.InvalidVoucher.left()
coEvery {
mockVoucherRepository.submitVoucher(VoucherCode.fromString(voucher).getOrNull()!!)
} returns RedeemVoucherError.InvalidVoucher.left()

// Act, Assert
viewModel.uiState.test {
Expand All @@ -84,8 +87,9 @@ class VoucherDialogViewModelTest {

// Arrange
every { mockVoucherSubmission.timeAdded } returns 0
coEvery { mockVoucherRepository.submitVoucher(voucher) } returns
RedeemVoucherSuccess(0, DateTime()).right()
coEvery {
mockVoucherRepository.submitVoucher(VoucherCode.fromString(voucher).getOrNull()!!)
} returns RedeemVoucherSuccess(0, DateTime()).right()

// Act, Assert
viewModel.uiState.test {
Expand All @@ -102,8 +106,9 @@ class VoucherDialogViewModelTest {

// Arrange
every { mockVoucherSubmission.timeAdded } returns 0
coEvery { mockVoucherRepository.submitVoucher(voucher) } returns
RedeemVoucherError.VoucherAlreadyUsed.left()
coEvery {
mockVoucherRepository.submitVoucher(VoucherCode.fromString(voucher).getOrNull()!!)
} returns RedeemVoucherError.VoucherAlreadyUsed.left()

// Act, Assert
viewModel.uiState.test {
Expand Down

0 comments on commit e29b0a0

Please sign in to comment.