Browse Source

Create interface UnifiedPushGatewayResolver

pull/2899/head
Benoit Marty 4 months ago
parent
commit
738bb831fa
  1. 9
      libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt
  2. 20
      libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/DefaultUnifiedPushGatewayResolverTest.kt

9
libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt

@ -16,13 +16,20 @@ @@ -16,13 +16,20 @@
package io.element.android.libraries.pushproviders.unifiedpush
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.di.AppScope
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.net.URL
import javax.inject.Inject
class UnifiedPushGatewayResolver @Inject constructor(
interface UnifiedPushGatewayResolver {
suspend fun getGateway(endpoint: String): String
}
@ContributesBinding(AppScope::class)
class DefaultUnifiedPushGatewayResolver @Inject constructor(
private val unifiedPushApiFactory: UnifiedPushApiFactory,
private val coroutineDispatchers: CoroutineDispatchers,
) {

20
libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolverTest.kt → libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/DefaultUnifiedPushGatewayResolverTest.kt

@ -24,7 +24,7 @@ import kotlinx.coroutines.test.TestScope @@ -24,7 +24,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Test
class UnifiedPushGatewayResolverTest {
class DefaultUnifiedPushGatewayResolverTest {
private val matrixDiscoveryResponse = {
DiscoveryResponse(
unifiedpush = DiscoveryUnifiedPush(
@ -46,7 +46,7 @@ class UnifiedPushGatewayResolverTest { @@ -46,7 +46,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = matrixDiscoveryResponse
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("https://custom.url")
@ -59,7 +59,7 @@ class UnifiedPushGatewayResolverTest { @@ -59,7 +59,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = matrixDiscoveryResponse
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("https://custom.url:123")
@ -72,7 +72,7 @@ class UnifiedPushGatewayResolverTest { @@ -72,7 +72,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = matrixDiscoveryResponse
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("https://custom.url:123/some/path")
@ -85,7 +85,7 @@ class UnifiedPushGatewayResolverTest { @@ -85,7 +85,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = matrixDiscoveryResponse
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("http://custom.url:123/some/path")
@ -98,7 +98,7 @@ class UnifiedPushGatewayResolverTest { @@ -98,7 +98,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = { throw Exception() }
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("http://custom.url")
@ -111,7 +111,7 @@ class UnifiedPushGatewayResolverTest { @@ -111,7 +111,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = matrixDiscoveryResponse
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("invalid")
@ -124,7 +124,7 @@ class UnifiedPushGatewayResolverTest { @@ -124,7 +124,7 @@ class UnifiedPushGatewayResolverTest {
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = invalidDiscoveryResponse
)
val sut = createUnifiedPushGatewayResolver(
val sut = createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory
)
val result = sut.getGateway("https://custom.url")
@ -132,11 +132,11 @@ class UnifiedPushGatewayResolverTest { @@ -132,11 +132,11 @@ class UnifiedPushGatewayResolverTest {
assertThat(result).isEqualTo(UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL)
}
private fun TestScope.createUnifiedPushGatewayResolver(
private fun TestScope.createDefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory: UnifiedPushApiFactory = FakeUnifiedPushApiFactory(
discoveryResponse = { DiscoveryResponse() }
)
) = UnifiedPushGatewayResolver(
) = DefaultUnifiedPushGatewayResolver(
unifiedPushApiFactory = unifiedPushApiFactory,
coroutineDispatchers = testCoroutineDispatchers()
)
Loading…
Cancel
Save