From 9b23435bdc5431709f252a48ff7bc8440de18f05 Mon Sep 17 00:00:00 2001 From: mramotar Date: Sun, 7 Jan 2024 15:20:55 -0500 Subject: [PATCH] Cover custom error Signed-off-by: mramotar --- .../store/store5/FetcherResponseTests.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt index af3704eec..70f1545f7 100644 --- a/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt +++ b/store/src/commonTest/kotlin/org/mobilenativefoundation/store/store5/FetcherResponseTests.kt @@ -211,6 +211,32 @@ class FetcherResponseTests { ) } + @Test + fun givenAFetcherThatEmitsCustomErrorWhenStreamingThenCustomErrorShouldBeEmitted() = testScope.runTest { + data class TestCustomError(val errorMessage: String) + val customError = TestCustomError("Test custom error") + + val store = StoreBuilder.from( + fetcher = Fetcher.ofResultFlow { _: Int -> + flowOf( + FetcherResult.Error.Custom(customError) + ) + } + ).buildWithTestScope() + + assertEmitsExactly( + store.stream(StoreReadRequest.fresh(1)), + listOf( + StoreReadResponse.Loading(origin = StoreReadResponseOrigin.Fetcher()), + StoreReadResponse.Error.Custom( + error = customError, + origin = StoreReadResponseOrigin.Fetcher() + ) + ) + ) + } + + private fun StoreBuilder.buildWithTestScope() = scope(testScope).build() }