feat: [NETWORK] mocks can throw errors (#133)

* feat: [NETWORK] mocks can throw errors

* added into android

* added on ktor

---------

Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
Florent CHAMPIGNY 2025-08-21 16:44:07 +02:00 committed by GitHub
parent a50169189e
commit 3cb5abd33f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 640 additions and 339 deletions

View file

@ -19,13 +19,24 @@ fun toRemote(mock: MockNetworkDomainModel): MockNetworkResponseDataModel = MockN
urlPattern = mock.expectation.urlPattern,
method = mock.expectation.method,
),
response = MockNetworkResponseDataModel.Response(
httpCode = mock.response.httpCode,
body = mock.response.body,
mediaType = mock.response.mediaType,
delay = mock.response.delay,
headers = mock.response.headers,
),
response = when(val r = mock.response) {
is MockNetworkDomainModel.Response.Body -> MockNetworkResponseDataModel.Response(
httpCode = r.httpCode,
body = r.body,
mediaType = r.mediaType,
delay = r.delay,
headers = r.headers,
errorException = null
)
is MockNetworkDomainModel.Response.Exception -> MockNetworkResponseDataModel.Response(
httpCode = null,
body = null,
mediaType = null,
delay = r.delay,
headers = null,
errorException = r.classPath
)
}
)
@OptIn(ExperimentalUuidApi::class)

View file

@ -15,10 +15,11 @@ data class MockNetworkResponseDataModel(
@Serializable
data class Response(
val httpCode: Int,
val body: String,
val mediaType: String,
val delay: Long,
val headers: Map<String, String>,
val httpCode: Int?,
val body: String?,
val mediaType: String?,
val delay: Long?,
val headers: Map<String, String>?,
val errorException: String?,
)
}