Browse Source

Add test on RustPushersService

pull/3501/head
Benoit Marty 4 weeks ago
parent
commit
98cfa25d5b
  1. 12
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustClient.kt
  2. 67
      libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/pushers/RustPushersServiceTest.kt

12
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 @@ -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( @@ -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
}

67
libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/pushers/RustPushersServiceTest.kt

@ -0,0 +1,67 @@ @@ -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,
)
Loading…
Cancel
Save