Skip to content

Commit 98cfa25

Browse files
committed
Add test on RustPushersService
1 parent 8439c10 commit 98cfa25

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/fixtures/fakes/FakeRustClient.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import org.matrix.rustcomponents.sdk.NoPointer
1717
import org.matrix.rustcomponents.sdk.NotificationClient
1818
import org.matrix.rustcomponents.sdk.NotificationProcessSetup
1919
import org.matrix.rustcomponents.sdk.NotificationSettings
20+
import org.matrix.rustcomponents.sdk.PusherIdentifiers
21+
import org.matrix.rustcomponents.sdk.PusherKind
2022
import org.matrix.rustcomponents.sdk.RoomDirectorySearch
2123
import org.matrix.rustcomponents.sdk.Session
2224
import org.matrix.rustcomponents.sdk.SyncServiceBuilder
@@ -41,4 +43,14 @@ class FakeRustClient(
4143
override suspend fun restoreSession(session: Session) = Unit
4244
override fun syncService(): SyncServiceBuilder = FakeRustSyncServiceBuilder()
4345
override fun roomDirectorySearch(): RoomDirectorySearch = FakeRoomDirectorySearch()
46+
override suspend fun setPusher(
47+
identifiers: PusherIdentifiers,
48+
kind: PusherKind,
49+
appDisplayName: String,
50+
deviceDisplayName: String,
51+
profileTag: String?,
52+
lang: String,
53+
) = Unit
54+
55+
override suspend fun deletePusher(identifiers: PusherIdentifiers) = Unit
4456
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2024 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only
5+
* Please see LICENSE in the repository root for full details.
6+
*/
7+
8+
package io.element.android.libraries.matrix.impl.pushers
9+
10+
import io.element.android.libraries.matrix.api.pusher.SetHttpPusherData
11+
import io.element.android.libraries.matrix.api.pusher.UnsetHttpPusherData
12+
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustClient
13+
import io.element.android.tests.testutils.testCoroutineDispatchers
14+
import kotlinx.coroutines.test.runTest
15+
import org.junit.Test
16+
17+
class RustPushersServiceTest {
18+
@Test
19+
fun `setPusher should invoke the client method`() = runTest {
20+
val sut = RustPushersService(
21+
client = FakeRustClient(),
22+
dispatchers = testCoroutineDispatchers()
23+
)
24+
sut.setHttpPusher(
25+
setHttpPusherData = aSetHttpPusherData()
26+
).getOrThrow()
27+
}
28+
29+
@Test
30+
fun `unsetPusher should invoke the client method`() = runTest {
31+
val sut = RustPushersService(
32+
client = FakeRustClient(),
33+
dispatchers = testCoroutineDispatchers()
34+
)
35+
sut.unsetHttpPusher(
36+
unsetHttpPusherData = aUnsetHttpPusherData(),
37+
).getOrThrow()
38+
}
39+
}
40+
41+
private fun aSetHttpPusherData(
42+
pushKey: String = "pushKey",
43+
appId: String = "appId",
44+
url: String = "url",
45+
defaultPayload: String = "defaultPayload",
46+
appDisplayName: String = "appDisplayName",
47+
deviceDisplayName: String = "deviceDisplayName",
48+
profileTag: String = "profileTag",
49+
lang: String = "lang",
50+
) = SetHttpPusherData(
51+
pushKey = pushKey,
52+
appId = appId,
53+
url = url,
54+
defaultPayload = defaultPayload,
55+
appDisplayName = appDisplayName,
56+
deviceDisplayName = deviceDisplayName,
57+
profileTag = profileTag,
58+
lang = lang
59+
)
60+
61+
private fun aUnsetHttpPusherData(
62+
pushKey: String = "pushKey",
63+
appId: String = "appId",
64+
) = UnsetHttpPusherData(
65+
pushKey = pushKey,
66+
appId = appId,
67+
)

0 commit comments

Comments
 (0)