Skip to content

Commit

Permalink
Update StreamWithoutSourceOfTruthTests to use Turbine
Browse files Browse the repository at this point in the history
Signed-off-by: matt-ramotar <matt.ramotar@uber.com>
  • Loading branch information
matt-ramotar committed Nov 17, 2024
1 parent 3f299b6 commit 69dfb6e
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mobilenativefoundation.store.store5

import app.cash.turbine.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.async
Expand All @@ -9,7 +10,6 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.mobilenativefoundation.store.store5.util.FakeFetcher
import org.mobilenativefoundation.store.store5.util.assertEmitsExactly
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -37,18 +37,22 @@ class StreamWithoutSourceOfTruthTests {
).take(3).toList()
}
delay(1_000) // make sure the async block starts first
assertEmitsExactly(
pipeline.stream(StoreReadRequest.fresh(3)),
listOf(
pipeline.stream(StoreReadRequest.fresh(3)).test {
assertEquals(
StoreReadResponse.Loading(
origin = StoreReadResponseOrigin.Fetcher(),
),
awaitItem()
)

assertEquals(
StoreReadResponse.Data(
value = "three-2",
origin = StoreReadResponseOrigin.Fetcher(),
),
),
)
awaitItem()
)
}

assertEquals(
listOf(
Expand Down Expand Up @@ -88,18 +92,22 @@ class StreamWithoutSourceOfTruthTests {
).take(3).toList()
}
delay(1_000) // make sure the async block starts first
assertEmitsExactly(
pipeline.stream(StoreReadRequest.fresh(3)),
listOf(
pipeline.stream(StoreReadRequest.fresh(3)).test {
assertEquals(
StoreReadResponse.Loading(
origin = StoreReadResponseOrigin.Fetcher(),
),
awaitItem()
)

assertEquals(
StoreReadResponse.Data(
value = "three-2",
origin = StoreReadResponseOrigin.Fetcher(),
),
),
)
awaitItem()
)
}

assertEquals(
listOf(
Expand Down

0 comments on commit 69dfb6e

Please sign in to comment.