Add test on RustNotificationSettingsService
This commit is contained in:
parent
08b63943b8
commit
f057d041c1
3 changed files with 73 additions and 1 deletions
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 New Vector Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Please see LICENSE in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.matrix.impl.fixtures.factories
|
||||||
|
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomNotificationMode
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomNotificationSettings
|
||||||
|
|
||||||
|
fun aRustRoomNotificationSettings(
|
||||||
|
mode: RoomNotificationMode = RoomNotificationMode.ALL_MESSAGES,
|
||||||
|
isDefault: Boolean = true,
|
||||||
|
) = RoomNotificationSettings(
|
||||||
|
mode = mode,
|
||||||
|
isDefault = isDefault
|
||||||
|
)
|
||||||
|
|
@ -7,14 +7,25 @@
|
||||||
|
|
||||||
package io.element.android.libraries.matrix.impl.fixtures.fakes
|
package io.element.android.libraries.matrix.impl.fixtures.fakes
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustRoomNotificationSettings
|
||||||
import org.matrix.rustcomponents.sdk.NoPointer
|
import org.matrix.rustcomponents.sdk.NoPointer
|
||||||
import org.matrix.rustcomponents.sdk.NotificationSettings
|
import org.matrix.rustcomponents.sdk.NotificationSettings
|
||||||
import org.matrix.rustcomponents.sdk.NotificationSettingsDelegate
|
import org.matrix.rustcomponents.sdk.NotificationSettingsDelegate
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomNotificationSettings
|
||||||
|
|
||||||
class FakeRustNotificationSettings : NotificationSettings(NoPointer) {
|
class FakeRustNotificationSettings(
|
||||||
|
private val roomNotificationSettings: RoomNotificationSettings = aRustRoomNotificationSettings(),
|
||||||
|
) : NotificationSettings(NoPointer) {
|
||||||
private var delegate: NotificationSettingsDelegate? = null
|
private var delegate: NotificationSettingsDelegate? = null
|
||||||
|
|
||||||
override fun setDelegate(delegate: NotificationSettingsDelegate?) {
|
override fun setDelegate(delegate: NotificationSettingsDelegate?) {
|
||||||
this.delegate = delegate
|
this.delegate = delegate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun getRoomNotificationSettings(
|
||||||
|
roomId: String,
|
||||||
|
isEncrypted: Boolean,
|
||||||
|
isOneToOne: Boolean,
|
||||||
|
): RoomNotificationSettings = roomNotificationSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2024 New Vector Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Please see LICENSE in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.matrix.impl.notificationsettings
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
||||||
|
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustClient
|
||||||
|
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustNotificationSettings
|
||||||
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
|
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||||
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.rustcomponents.sdk.NotificationSettings
|
||||||
|
|
||||||
|
class RustNotificationSettingsServiceTest {
|
||||||
|
@Test
|
||||||
|
fun test() = runTest {
|
||||||
|
val sut = createRustNotificationSettingsService()
|
||||||
|
val result = sut.getRoomNotificationSettings(
|
||||||
|
roomId = A_ROOM_ID,
|
||||||
|
isEncrypted = true,
|
||||||
|
isOneToOne = true,
|
||||||
|
).getOrNull()!!
|
||||||
|
assertThat(result.mode).isEqualTo(RoomNotificationMode.ALL_MESSAGES)
|
||||||
|
assertThat(result.isDefault).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TestScope.createRustNotificationSettingsService(
|
||||||
|
notificationSettings: NotificationSettings = FakeRustNotificationSettings(),
|
||||||
|
) = RustNotificationSettingsService(
|
||||||
|
client = FakeRustClient(
|
||||||
|
notificationSettings = notificationSettings,
|
||||||
|
),
|
||||||
|
dispatchers = testCoroutineDispatchers(),
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue