Add test on RustCheckCodeSender
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
<string name="screen_qr_code_login_error_cancelled_title">"Sign in request cancelled"</string>
|
||||
<string name="screen_qr_code_login_error_declined_subtitle">"The sign in was declined on the other device."</string>
|
||||
<string name="screen_qr_code_login_error_declined_title">"Sign in declined"</string>
|
||||
<string name="screen_qr_code_login_error_device_already_signed_in_subtitle">"You don’t need to do anything else."</string>
|
||||
<string name="screen_qr_code_login_error_device_already_signed_in_title">"Your other device is already signed in"</string>
|
||||
<string name="screen_qr_code_login_error_expired_subtitle">"Sign in expired. Please try again."</string>
|
||||
<string name="screen_qr_code_login_error_expired_title">"The sign in was not completed in time"</string>
|
||||
<string name="screen_qr_code_login_error_linking_not_suported_subtitle">"Your other device does not support signing in to %s with a QR code.
|
||||
|
||||
@@ -60,6 +60,8 @@
|
||||
<string name="screen_qr_code_login_error_cancelled_title">"Sign in request cancelled"</string>
|
||||
<string name="screen_qr_code_login_error_declined_subtitle">"The sign in was declined on the other device."</string>
|
||||
<string name="screen_qr_code_login_error_declined_title">"Sign in declined"</string>
|
||||
<string name="screen_qr_code_login_error_device_already_signed_in_subtitle">"You don’t need to do anything else."</string>
|
||||
<string name="screen_qr_code_login_error_device_already_signed_in_title">"Your other device is already signed in"</string>
|
||||
<string name="screen_qr_code_login_error_expired_subtitle">"Sign in expired. Please try again."</string>
|
||||
<string name="screen_qr_code_login_error_expired_title">"The sign in was not completed in time"</string>
|
||||
<string name="screen_qr_code_login_error_linking_not_suported_subtitle">"Your other device does not support signing in to %s with a QR code.
|
||||
|
||||
@@ -7,7 +7,14 @@
|
||||
|
||||
package io.element.android.libraries.matrix.impl.fixtures.fakes
|
||||
|
||||
import io.element.android.tests.testutils.lambda.lambdaError
|
||||
import org.matrix.rustcomponents.sdk.CheckCodeSender
|
||||
import org.matrix.rustcomponents.sdk.NoHandle
|
||||
|
||||
class FakeFfiCheckCodeSender : CheckCodeSender(NoHandle)
|
||||
class FakeFfiCheckCodeSender(
|
||||
private val sendResult: (UByte) -> Unit = { _ -> lambdaError() }
|
||||
) : CheckCodeSender(NoHandle) {
|
||||
override suspend fun send(code: UByte) {
|
||||
sendResult(code)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl.linknewdevice
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiCheckCodeSender
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import io.element.android.tests.testutils.lambda.value
|
||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
class RustCheckCodeSenderTest {
|
||||
@Test
|
||||
fun `send invokes the Ffi object`() = runTest {
|
||||
val sendResult = lambdaRecorder<UByte, Unit> { }
|
||||
val sut = RustCheckCodeSender(
|
||||
inner = FakeFfiCheckCodeSender(
|
||||
sendResult = sendResult,
|
||||
),
|
||||
sessionDispatcher = StandardTestDispatcher(testScheduler),
|
||||
)
|
||||
sut.send(1.toUByte())
|
||||
sendResult.assertions().isCalledOnce().with(value(1.toUByte()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validate always returns true for now`() = runTest {
|
||||
val sut = RustCheckCodeSender(
|
||||
inner = FakeFfiCheckCodeSender(),
|
||||
sessionDispatcher = StandardTestDispatcher(testScheduler),
|
||||
)
|
||||
val result = sut.validate(1.toUByte())
|
||||
assertThat(result).isTrue()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user