-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stream_givenConflicts_whenExceptionResolvingConflicts_thenShouldLog
Signed-off-by: matt-ramotar <[email protected]>
- Loading branch information
1 parent
41710eb
commit d0bfad6
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...est/kotlin/org/mobilenativefoundation/store/store5/mutable_store/RealMutableStoreTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.mobilenativefoundation.store.store5.mutable_store | ||
|
||
import app.cash.turbine.test | ||
import dev.mokkery.MockMode.autoUnit | ||
import dev.mokkery.answering.returns | ||
import dev.mokkery.every | ||
import dev.mokkery.everySuspend | ||
import dev.mokkery.matcher.any | ||
import dev.mokkery.matcher.eq | ||
import dev.mokkery.mock | ||
import dev.mokkery.verify | ||
import dev.mokkery.verify.VerifyMode | ||
import dev.mokkery.verify.VerifyMode.Companion.exactly | ||
import dev.mokkery.verifySuspend | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.TestScope | ||
import kotlinx.coroutines.test.runTest | ||
import org.mobilenativefoundation.store.store5.Bookkeeper | ||
import org.mobilenativefoundation.store.store5.Logger | ||
import org.mobilenativefoundation.store.store5.StoreReadRequest | ||
import org.mobilenativefoundation.store.store5.StoreReadResponse | ||
import org.mobilenativefoundation.store.store5.StoreReadResponseOrigin | ||
import org.mobilenativefoundation.store.store5.Updater | ||
import org.mobilenativefoundation.store.store5.UpdaterResult | ||
import org.mobilenativefoundation.store.store5.impl.RealMutableStore | ||
import org.mobilenativefoundation.store.store5.impl.RealStore | ||
import org.mobilenativefoundation.store.store5.test_utils.model.Note | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class RealMutableStoreTests { | ||
private val testScope = TestScope() | ||
|
||
private val delegate = mock<RealStore<String, Note, Note, Note>>(autoUnit) | ||
private val updater = mock<Updater<String, Note, Boolean>>(autoUnit) | ||
private val bookkeeper = mock<Bookkeeper<String>>(autoUnit) | ||
private val logger = mock<Logger>(autoUnit) | ||
|
||
|
||
private val mutableStore = RealMutableStore( | ||
delegate, | ||
updater, | ||
bookkeeper, | ||
logger | ||
) | ||
|
||
@Test | ||
fun stream_givenConflicts_whenExceptionResolvingConflicts_thenShouldLog() = testScope.runTest { | ||
// Given | ||
val latestNote = Note("id", "Title", "Content") | ||
val readResponse = StoreReadResponse.Data(latestNote, StoreReadResponseOrigin.Cache) | ||
val delegateFlow = flowOf(readResponse) | ||
val exception = Exception("Error updating network.") | ||
val readRequest = StoreReadRequest.fresh("id") | ||
|
||
every { | ||
delegate.stream(any()) | ||
} returns delegateFlow | ||
|
||
everySuspend { | ||
delegate.latestOrNull(any()) | ||
} returns latestNote | ||
|
||
everySuspend { | ||
bookkeeper.getLastFailedSync(any()) | ||
} returns 1L | ||
|
||
everySuspend { | ||
updater.post(any(), any()) | ||
} returns UpdaterResult.Error.Exception(exception) | ||
|
||
|
||
// When | ||
val stream = mutableStore.stream<Boolean>( | ||
readRequest | ||
) | ||
|
||
// Then | ||
|
||
stream.test { | ||
|
||
verifySuspend(exactly(1)) { | ||
updater.post(eq("id"), eq(latestNote)) | ||
} | ||
|
||
verify(exactly(1)) { | ||
logger.error(eq(exception.toString())) | ||
} | ||
|
||
verify(exactly(1)) { | ||
delegate.stream(eq(readRequest)) | ||
} | ||
|
||
assertEquals(readResponse, awaitItem()) | ||
|
||
awaitComplete() | ||
} | ||
|
||
} | ||
|
||
} |