REDI-96: repository MockEngine test + Compose robot UI test + serialization fix
NetworkCharacterRepositoryTest swaps a Ktor MockEngine into HttpClientFactory and covers success mapping (incl. request URL/page-param construction), 404 -> NOT_FOUND, 500 -> SERVER_ERROR, and malformed body -> SERIALIZATION. That last case exposed a real bug: Ktor wraps the kotlinx SerializationException in its own ContentConvertException, so safeCall mapped it to UNKNOWN; safeCall now scans the cause chain and maps it to SERIALIZATION. Adds an instrumented Compose UI test (CharacterListScreen) using the chaining CharacterListRobot: rendered items, empty/error states, and tap -> Action.
This commit is contained in:
@@ -75,8 +75,16 @@ suspend inline fun <reified T> safeCall(
|
||||
Result.Error(DataError.Network.SERIALIZATION)
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) throw e
|
||||
logNetworkError(e, "Unknown network failure")
|
||||
Result.Error(DataError.Network.UNKNOWN)
|
||||
// Ktor's ContentNegotiation wraps a kotlinx SerializationException (malformed/garbage body)
|
||||
// in its own ContentConvertException, so the catch above misses it. Scan the cause chain so a
|
||||
// bad payload still maps to SERIALIZATION instead of the generic UNKNOWN.
|
||||
if (generateSequence(e as Throwable) { it.cause }.any { it is SerializationException }) {
|
||||
logNetworkError(e, "Serialization failure (wrapped)")
|
||||
Result.Error(DataError.Network.SERIALIZATION)
|
||||
} else {
|
||||
logNetworkError(e, "Unknown network failure")
|
||||
Result.Error(DataError.Network.UNKNOWN)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user