Introduce PushHistoryService to store data about the received push (#4573)
* Introduce PushHistoryService to store data about the received push Add a push database. * Update screenshots * Improve preview. * Update screenshots * Add missing test. * Add test for PushHistoryView * Fix configuration issue. Was: w: /libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenterTest.kt:35:27 Cannot access class 'PushProvider' in the expression type. While it may work, this case indicates a configuration mistake and can lead to avoidable compilation errors, so it may be forbidden soon. Check your module classpath for missing or conflicting dependencies. --------- Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
parent
a0b619007a
commit
a1d8322738
60 changed files with 1656 additions and 214 deletions
|
|
@ -8,5 +8,12 @@
|
|||
package io.element.android.libraries.pushproviders.api
|
||||
|
||||
interface PushHandler {
|
||||
suspend fun handle(pushData: PushData)
|
||||
suspend fun handle(
|
||||
pushData: PushData,
|
||||
providerInfo: String,
|
||||
)
|
||||
|
||||
suspend fun handleInvalid(
|
||||
providerInfo: String,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,14 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
|||
val pushData = pushParser.parse(message.data)
|
||||
if (pushData == null) {
|
||||
Timber.tag(loggerTag.value).w("Invalid data received from Firebase")
|
||||
pushHandler.handleInvalid(
|
||||
providerInfo = FirebaseConfig.NAME,
|
||||
)
|
||||
} else {
|
||||
pushHandler.handle(pushData)
|
||||
pushHandler.handle(
|
||||
pushData = pushData,
|
||||
providerInfo = FirebaseConfig.NAME,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import io.element.android.tests.testutils.lambda.value
|
|||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.advanceUntilIdle
|
||||
import kotlinx.coroutines.test.runCurrent
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -31,16 +32,18 @@ import org.robolectric.RobolectricTestRunner
|
|||
class VectorFirebaseMessagingServiceTest {
|
||||
@Test
|
||||
fun `test receiving invalid data`() = runTest {
|
||||
val lambda = lambdaRecorder<PushData, Unit>(ensureNeverCalled = true) { }
|
||||
val lambda = lambdaRecorder<String, Unit> {}
|
||||
val vectorFirebaseMessagingService = createVectorFirebaseMessagingService(
|
||||
pushHandler = FakePushHandler(handleResult = lambda)
|
||||
pushHandler = FakePushHandler(handleInvalidResult = lambda)
|
||||
)
|
||||
vectorFirebaseMessagingService.onMessageReceived(RemoteMessage(Bundle()))
|
||||
runCurrent()
|
||||
lambda.assertions().isCalledOnce()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test receiving valid data`() = runTest {
|
||||
val lambda = lambdaRecorder<PushData, Unit> { }
|
||||
val lambda = lambdaRecorder<PushData, String, Unit> { _, _ -> }
|
||||
val vectorFirebaseMessagingService = createVectorFirebaseMessagingService(
|
||||
pushHandler = FakePushHandler(handleResult = lambda)
|
||||
)
|
||||
|
|
@ -56,7 +59,10 @@ class VectorFirebaseMessagingServiceTest {
|
|||
advanceUntilIdle()
|
||||
lambda.assertions()
|
||||
.isCalledOnce()
|
||||
.with(value(PushData(AN_EVENT_ID, A_ROOM_ID, null, A_SECRET)))
|
||||
.with(
|
||||
value(PushData(AN_EVENT_ID, A_ROOM_ID, null, A_SECRET)),
|
||||
value(FirebaseConfig.NAME)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -51,8 +51,14 @@ class VectorUnifiedPushMessagingReceiver : MessagingReceiver() {
|
|||
val pushData = pushParser.parse(message, instance)
|
||||
if (pushData == null) {
|
||||
Timber.tag(loggerTag.value).w("Invalid data received from UnifiedPush")
|
||||
pushHandler.handleInvalid(
|
||||
providerInfo = "${UnifiedPushConfig.NAME} - $instance",
|
||||
)
|
||||
} else {
|
||||
pushHandler.handle(pushData)
|
||||
pushHandler.handle(
|
||||
pushData = pushData,
|
||||
providerInfo = "${UnifiedPushConfig.NAME} - $instance",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ class VectorUnifiedPushMessagingReceiverTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `onMessage valid invoke the push handler`() = runTest {
|
||||
fun `onMessage valid invokes the push handler`() = runTest {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
val pushHandlerResult = lambdaRecorder<PushData, Unit> {}
|
||||
val pushHandlerResult = lambdaRecorder<PushData, String, Unit> { _, _ -> }
|
||||
val vectorUnifiedPushMessagingReceiver = createVectorUnifiedPushMessagingReceiver(
|
||||
pushHandler = FakePushHandler(
|
||||
handleResult = pushHandlerResult
|
||||
|
|
@ -80,23 +80,25 @@ class VectorUnifiedPushMessagingReceiverTest {
|
|||
unread = 1,
|
||||
clientSecret = A_SECRET
|
||||
)
|
||||
),
|
||||
value(
|
||||
UnifiedPushConfig.NAME + " - " + A_SECRET
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `onMessage invalid does not invoke the push handler`() = runTest {
|
||||
fun `onMessage invalid invokes the push handler invalid method`() = runTest {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
val pushHandlerResult = lambdaRecorder<PushData, Unit> {}
|
||||
val handleInvalidResult = lambdaRecorder<String, Unit> { }
|
||||
val vectorUnifiedPushMessagingReceiver = createVectorUnifiedPushMessagingReceiver(
|
||||
pushHandler = FakePushHandler(
|
||||
handleResult = pushHandlerResult
|
||||
handleInvalidResult = handleInvalidResult,
|
||||
),
|
||||
)
|
||||
vectorUnifiedPushMessagingReceiver.onMessage(context, "".toByteArray(), A_SECRET)
|
||||
advanceUntilIdle()
|
||||
pushHandlerResult.assertions()
|
||||
.isNeverCalled()
|
||||
handleInvalidResult.assertions().isCalledOnce()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue