diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustClient.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustClient.kt index 935537a27f..740d354821 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustClient.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustClient.kt @@ -17,6 +17,8 @@ import org.matrix.rustcomponents.sdk.NoPointer import org.matrix.rustcomponents.sdk.NotificationClient import org.matrix.rustcomponents.sdk.NotificationProcessSetup import org.matrix.rustcomponents.sdk.NotificationSettings +import org.matrix.rustcomponents.sdk.PusherIdentifiers +import org.matrix.rustcomponents.sdk.PusherKind import org.matrix.rustcomponents.sdk.RoomDirectorySearch import org.matrix.rustcomponents.sdk.Session import org.matrix.rustcomponents.sdk.SyncServiceBuilder @@ -41,4 +43,14 @@ class FakeRustClient( override suspend fun restoreSession(session: Session) = Unit override fun syncService(): SyncServiceBuilder = FakeRustSyncServiceBuilder() override fun roomDirectorySearch(): RoomDirectorySearch = FakeRoomDirectorySearch() + override suspend fun setPusher( + identifiers: PusherIdentifiers, + kind: PusherKind, + appDisplayName: String, + deviceDisplayName: String, + profileTag: String?, + lang: String, + ) = Unit + + override suspend fun deletePusher(identifiers: PusherIdentifiers) = Unit } diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/pushers/RustPushersServiceTest.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/pushers/RustPushersServiceTest.kt new file mode 100644 index 0000000000..34821b935a --- /dev/null +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/pushers/RustPushersServiceTest.kt @@ -0,0 +1,67 @@ +/* + * 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.pushers + +import io.element.android.libraries.matrix.api.pusher.SetHttpPusherData +import io.element.android.libraries.matrix.api.pusher.UnsetHttpPusherData +import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustClient +import io.element.android.tests.testutils.testCoroutineDispatchers +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class RustPushersServiceTest { + @Test + fun `setPusher should invoke the client method`() = runTest { + val sut = RustPushersService( + client = FakeRustClient(), + dispatchers = testCoroutineDispatchers() + ) + sut.setHttpPusher( + setHttpPusherData = aSetHttpPusherData() + ).getOrThrow() + } + + @Test + fun `unsetPusher should invoke the client method`() = runTest { + val sut = RustPushersService( + client = FakeRustClient(), + dispatchers = testCoroutineDispatchers() + ) + sut.unsetHttpPusher( + unsetHttpPusherData = aUnsetHttpPusherData(), + ).getOrThrow() + } +} + +private fun aSetHttpPusherData( + pushKey: String = "pushKey", + appId: String = "appId", + url: String = "url", + defaultPayload: String = "defaultPayload", + appDisplayName: String = "appDisplayName", + deviceDisplayName: String = "deviceDisplayName", + profileTag: String = "profileTag", + lang: String = "lang", +) = SetHttpPusherData( + pushKey = pushKey, + appId = appId, + url = url, + defaultPayload = defaultPayload, + appDisplayName = appDisplayName, + deviceDisplayName = deviceDisplayName, + profileTag = profileTag, + lang = lang +) + +private fun aUnsetHttpPusherData( + pushKey: String = "pushKey", + appId: String = "appId", +) = UnsetHttpPusherData( + pushKey = pushKey, + appId = appId, +)