Add getTrustDevice API to AuthSdkSource (#1147)

This commit is contained in:
David Perez
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 058c4f0dfc
commit 2244e21e29
3 changed files with 40 additions and 0 deletions
@@ -6,9 +6,11 @@ import com.bitwarden.core.MasterPasswordPolicyOptions
import com.bitwarden.core.RegisterKeyResponse
import com.bitwarden.crypto.HashPurpose
import com.bitwarden.crypto.Kdf
import com.bitwarden.crypto.TrustDeviceResponse
import com.bitwarden.sdk.ClientAuth
import com.bitwarden.sdk.ClientPlatform
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
import com.x8bit.bitwarden.data.platform.util.asFailure
import com.x8bit.bitwarden.data.platform.util.asSuccess
import io.mockk.coEvery
import io.mockk.coVerify
@@ -27,6 +29,33 @@ class AuthSdkSourceTest {
clientPlatform = clientPlatform,
)
@Test
fun `getTrustDevice with trustDevice success should return success with correct data`() =
runBlocking {
val expectedResult = mockk<TrustDeviceResponse>()
coEvery { clientAuth.trustDevice() } returns expectedResult
val result = authSkdSource.getTrustDevice()
assertEquals(expectedResult.asSuccess(), result)
coVerify(exactly = 1) {
clientAuth.trustDevice()
}
}
@Test
fun `getTrustDevice with trustDevice exception should return a failure`() = runBlocking {
val error = Throwable("Fail")
coEvery { clientAuth.trustDevice() } throws error
val result = authSkdSource.getTrustDevice()
assertEquals(error.asFailure(), result)
coVerify(exactly = 1) {
clientAuth.trustDevice()
}
}
@Test
fun `getNewAuthRequest should call SDK and return a Result with correct data`() = runBlocking {
val email = "test@gmail.com"