mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Add test on RustCheckCodeSender
This commit is contained in:
+8
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -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