Add missing tests on DefaultUnifiedPushGatewayResolver
This commit is contained in:
parent
e2cb0173a6
commit
4c8af0a66c
1 changed files with 34 additions and 0 deletions
|
|
@ -14,7 +14,11 @@ import io.element.android.libraries.pushproviders.unifiedpush.network.DiscoveryU
|
||||||
import io.element.android.tests.testutils.testCoroutineDispatchers
|
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||||
import kotlinx.coroutines.test.TestScope
|
import kotlinx.coroutines.test.TestScope
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import retrofit2.HttpException
|
||||||
|
import retrofit2.Response
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
|
||||||
internal val matrixDiscoveryResponse = {
|
internal val matrixDiscoveryResponse = {
|
||||||
DiscoveryResponse(
|
DiscoveryResponse(
|
||||||
|
|
@ -98,6 +102,36 @@ class DefaultUnifiedPushGatewayResolverTest {
|
||||||
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.Error("http://custom.url/_matrix/push/v1/notify"))
|
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.Error("http://custom.url/_matrix/push/v1/notify"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when a custom url is not found (404), NoMatrixGateway is returned`() = runTest {
|
||||||
|
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||||
|
discoveryResponse = {
|
||||||
|
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_NOT_FOUND, "".toResponseBody()))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createDefaultUnifiedPushGatewayResolver(
|
||||||
|
unifiedPushApiFactory = unifiedPushApiFactory
|
||||||
|
)
|
||||||
|
val result = sut.getGateway("http://custom.url")
|
||||||
|
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||||
|
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.NoMatrixGateway)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when a custom url is forbidden (403), Error is returned`() = runTest {
|
||||||
|
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||||
|
discoveryResponse = {
|
||||||
|
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_FORBIDDEN, "".toResponseBody()))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createDefaultUnifiedPushGatewayResolver(
|
||||||
|
unifiedPushApiFactory = unifiedPushApiFactory
|
||||||
|
)
|
||||||
|
val result = sut.getGateway("http://custom.url")
|
||||||
|
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||||
|
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.Error("http://custom.url/_matrix/push/v1/notify"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when a custom url is invalid, ErrorInvalidUrl is returned`() = runTest {
|
fun `when a custom url is invalid, ErrorInvalidUrl is returned`() = runTest {
|
||||||
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue