mirror of
https://github.com/bitwarden/android.git
synced 2026-05-01 04:38:52 -05:00
BIT-398: Launch ACTION_VIEW Intent with captcha URL and handle callback (#88)
This commit is contained in:
committed by
Álison Fernandes
parent
9d9ee38070
commit
c6ce992342
64
app/src/test/java/com/x8bit/bitwarden/MainViewModelTest.kt
Normal file
64
app/src/test/java/com/x8bit/bitwarden/MainViewModelTest.kt
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.x8bit.bitwarden
|
||||
|
||||
import android.content.Intent
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.util.CaptchaCallbackTokenResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
||||
class MainViewModelTest {
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
mockkStatic(LOGIN_RESULT_PATH)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun tearDown() {
|
||||
unmockkStatic(LOGIN_RESULT_PATH)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ReceiveNewIntent with captcha host should call setCaptchaCallbackToken`() {
|
||||
val authRepository = mockk<AuthRepository> {
|
||||
every {
|
||||
setCaptchaCallbackTokenResult(
|
||||
tokenResult = CaptchaCallbackTokenResult.Success(
|
||||
token = "mockk_token",
|
||||
),
|
||||
)
|
||||
} returns Unit
|
||||
}
|
||||
val mockIntent = mockk<Intent> {
|
||||
every { data?.host } returns "captcha-callback"
|
||||
every { data?.getQueryParameter("token") } returns "mockk_token"
|
||||
every { action } returns Intent.ACTION_VIEW
|
||||
}
|
||||
val viewModel = MainViewModel(
|
||||
authRepository = authRepository,
|
||||
)
|
||||
viewModel.sendAction(
|
||||
MainAction.ReceiveNewIntent(
|
||||
intent = mockIntent,
|
||||
),
|
||||
)
|
||||
verify {
|
||||
authRepository.setCaptchaCallbackTokenResult(
|
||||
tokenResult = CaptchaCallbackTokenResult.Success(
|
||||
token = "mockk_token",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val LOGIN_RESULT_PATH =
|
||||
"com.x8bit.bitwarden.data.auth.datasource.network.util.LoginResultExtensionsKt"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user