Skip to content

Commit 594d66f

Browse files
committed
Add missing unit test on DefaultPushService
1 parent 017664f commit 594d66f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/DefaultPushServiceTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
package io.element.android.libraries.push.impl
99

10+
import app.cash.turbine.test
1011
import com.google.common.truth.Truth.assertThat
1112
import io.element.android.libraries.matrix.api.MatrixClient
1213
import io.element.android.libraries.matrix.api.core.SessionId
14+
import io.element.android.libraries.matrix.test.AN_EVENT_ID
1315
import io.element.android.libraries.matrix.test.AN_EXCEPTION
16+
import io.element.android.libraries.matrix.test.A_ROOM_ID
1417
import io.element.android.libraries.matrix.test.A_SESSION_ID
1518
import io.element.android.libraries.matrix.test.FakeMatrixClient
1619
import io.element.android.libraries.push.api.GetCurrentPushProvider
20+
import io.element.android.libraries.push.api.history.PushHistoryItem
1721
import io.element.android.libraries.push.impl.push.FakeMutableBatteryOptimizationStore
1822
import io.element.android.libraries.push.impl.push.MutableBatteryOptimizationStore
1923
import io.element.android.libraries.push.impl.store.InMemoryPushDataStore
@@ -297,6 +301,41 @@ class DefaultPushServiceTest {
297301
resetResult.assertions().isCalledOnce()
298302
}
299303

304+
@Test
305+
fun `resetPushHistory invokes the store method`() = runTest {
306+
val resetResult = lambdaRecorder<Unit> { }
307+
val defaultPushService = createDefaultPushService(
308+
pushDataStore = InMemoryPushDataStore(
309+
resetResult = resetResult
310+
),
311+
)
312+
defaultPushService.resetPushHistory()
313+
resetResult.assertions().isCalledOnce()
314+
}
315+
316+
@Test
317+
fun `getPushHistoryItemsFlow invokes the store method`() = runTest {
318+
val store = InMemoryPushDataStore()
319+
val aPushHistoryItem = PushHistoryItem(
320+
pushDate = 0L,
321+
formattedDate = "formattedDate",
322+
providerInfo = "providerInfo",
323+
eventId = AN_EVENT_ID,
324+
roomId = A_ROOM_ID,
325+
sessionId = A_SESSION_ID,
326+
hasBeenResolved = false,
327+
comment = null,
328+
)
329+
val defaultPushService = createDefaultPushService(
330+
pushDataStore = store,
331+
)
332+
defaultPushService.getPushHistoryItemsFlow().test {
333+
assertThat(awaitItem().isEmpty()).isTrue()
334+
store.emitPushHistoryItems(listOf(aPushHistoryItem))
335+
assertThat(awaitItem().first()).isEqualTo(aPushHistoryItem)
336+
}
337+
}
338+
300339
private fun createDefaultPushService(
301340
testPush: TestPush = FakeTestPush(),
302341
userPushStoreFactory: UserPushStoreFactory = FakeUserPushStoreFactory(),

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/store/InMemoryPushDataStore.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class InMemoryPushDataStore(
3131
return mutablePushHistoryItemsFlow.asStateFlow()
3232
}
3333

34+
suspend fun emitPushHistoryItems(items: List<PushHistoryItem>) {
35+
mutablePushHistoryItemsFlow.emit(items)
36+
}
37+
3438
override suspend fun reset() {
3539
resetResult()
3640
}

0 commit comments

Comments
 (0)