Merge pull request #2901 from element-hq/feature/bma/fixUnregisteringPusherLocalError

Fix unregistering pusher local error
This commit is contained in:
Benoit Marty 2024-05-23 14:38:07 +02:00 committed by GitHub
commit 85c8a26f8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 17 deletions

View file

@ -23,6 +23,7 @@ import io.element.android.libraries.di.ApplicationContext
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.pushproviders.api.PusherSubscriber
import org.unifiedpush.android.connector.UnifiedPush
import timber.log.Timber
import javax.inject.Inject
interface UnregisterUnifiedPushUseCase {
@ -39,7 +40,11 @@ class DefaultUnregisterUnifiedPushUseCase @Inject constructor(
val endpoint = unifiedPushStore.getEndpoint(clientSecret)
val gateway = unifiedPushStore.getPushGateway(clientSecret)
if (endpoint == null || gateway == null) {
return Result.failure(IllegalStateException("No endpoint or gateway found for client secret"))
Timber.w("No endpoint or gateway found for client secret")
// Ensure we don't have any remaining data, but ignore this error
unifiedPushStore.storeUpEndpoint(clientSecret, null)
unifiedPushStore.storePushGateway(clientSecret, null)
return Result.success(Unit)
}
return pusherSubscriber.unregisterPusher(matrixClient, endpoint, gateway)
.onSuccess {

View file

@ -64,29 +64,49 @@ class DefaultUnregisterUnifiedPushUseCaseTest {
}
@Test
fun `test un registration error - no endpoint`() = runTest {
fun `test un registration error - no endpoint - will not unregister but return success`() = runTest {
val matrixClient = FakeMatrixClient()
val storeUpEndpointResult = lambdaRecorder { _: String, _: String? -> }
val storePushGatewayResult = lambdaRecorder { _: String, _: String? -> }
val useCase = createDefaultUnregisterUnifiedPushUseCase(
unifiedPushStore = FakeUnifiedPushStore(
getEndpointResult = { null },
getPushGatewayResult = { "aGateway" },
storeUpEndpointResult = storeUpEndpointResult,
storePushGatewayResult = storePushGatewayResult,
),
)
val result = useCase.execute(matrixClient, A_SECRET)
assertThat(result.isFailure).isTrue()
assertThat(result.isSuccess).isTrue()
storeUpEndpointResult.assertions()
.isCalledOnce()
.with(value(A_SECRET), value(null))
storePushGatewayResult.assertions()
.isCalledOnce()
.with(value(A_SECRET), value(null))
}
@Test
fun `test un registration error - no gateway`() = runTest {
fun `test un registration error - no gateway - will not unregister but return success`() = runTest {
val matrixClient = FakeMatrixClient()
val storeUpEndpointResult = lambdaRecorder { _: String, _: String? -> }
val storePushGatewayResult = lambdaRecorder { _: String, _: String? -> }
val useCase = createDefaultUnregisterUnifiedPushUseCase(
unifiedPushStore = FakeUnifiedPushStore(
getEndpointResult = { "aEndpoint" },
getPushGatewayResult = { null },
storeUpEndpointResult = storeUpEndpointResult,
storePushGatewayResult = storePushGatewayResult,
),
)
val result = useCase.execute(matrixClient, A_SECRET)
assertThat(result.isFailure).isTrue()
assertThat(result.isSuccess).isTrue()
storeUpEndpointResult.assertions()
.isCalledOnce()
.with(value(A_SECRET), value(null))
storePushGatewayResult.assertions()
.isCalledOnce()
.with(value(A_SECRET), value(null))
}
@Test