Adds testing for fallback api

This commit is contained in:
ericdecanini 2022-03-08 11:51:17 +01:00
parent 3b0a565822
commit bc3b8d0a16
3 changed files with 25 additions and 7 deletions

View File

@ -21,6 +21,7 @@ internal object NetworkConstants {
private const val URI_API_PREFIX_PATH = "_matrix/client"
const val URI_API_PREFIX_PATH_ = "$URI_API_PREFIX_PATH/"
const val URI_API_PREFIX_PATH_R0 = "$URI_API_PREFIX_PATH/r0/"
const val URI_API_PREFIX_PATH_V1 = "${URI_API_PREFIX_PATH}v1/"
const val URI_API_PREFIX_PATH_UNSTABLE = "$URI_API_PREFIX_PATH/unstable/"
// Media

View File

@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.session.space
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import timber.log.Timber
import javax.inject.Inject
internal interface ResolveSpaceInfoTask : Task<ResolveSpaceInfoTask.Params, SpacesResponse> {
@ -38,12 +39,17 @@ internal class DefaultResolveSpaceInfoTask @Inject constructor(
) : ResolveSpaceInfoTask {
override suspend fun execute(params: ResolveSpaceInfoTask.Params): SpacesResponse {
return executeRequest(globalErrorReceiver) {
spaceApi.getSpaceHierarchy(
spaceId = params.spaceId,
suggestedOnly = params.suggestedOnly,
limit = params.limit,
maxDepth = params.maxDepth,
from = params.from)
try {
throw RuntimeException("Test space task exception")
} catch (e: Throwable) {
Timber.i("Test fall back api")
spaceApi.getSpaceHierarchy(
spaceId = params.spaceId,
suggestedOnly = params.suggestedOnly,
limit = params.limit,
maxDepth = params.maxDepth,
from = params.from)
}
}
}
}

View File

@ -31,11 +31,22 @@ internal interface SpaceApi {
* @param from: Optional. Pagination token given to retrieve the next set of rooms.
* Note that if a pagination token is provided, then the parameters given for suggested_only and max_depth must be the same.
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_ + "rooms/{roomID}/hierarchy")
@GET(NetworkConstants.URI_API_PREFIX_PATH_V1 + "rooms/{roomID}/hierarchy")
suspend fun getSpaceHierarchy(
@Path("roomId") spaceId: String,
@Query("suggested_only") suggestedOnly: Boolean?,
@Query("limit") limit: Int?,
@Query("max_depth") maxDepth: Int?,
@Query("from") from: String?): SpacesResponse
/**
* Unstable version of [getSpaceHierarchy]
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc2946/rooms/{roomId}/hierarchy")
suspend fun getSpaceHierarchyUnstable(
@Path("roomId") spaceId: String,
@Query("suggested_only") suggestedOnly: Boolean?,
@Query("limit") limit: Int?,
@Query("max_depth") maxDepth: Int?,
@Query("from") from: String?): SpacesResponse
}