Remove recipe from local db when deleted

This commit is contained in:
Kirill Kamakin
2022-12-16 20:24:40 +01:00
parent 28fa19c988
commit 226097d096
9 changed files with 31 additions and 37 deletions

View File

@@ -70,19 +70,25 @@ class RecipeRepoTest : BaseUnitTest() {
@Test
fun `when remove favorite recipe expect correct sequence`() = runTest {
coEvery { dataSource.getFavoriteRecipes() } returns listOf("porridge")
subject.updateIsRecipeFavorite("cake", false)
coVerify {
dataSource.updateIsRecipeFavorite(eq("cake"), eq(false))
remoteMediator.onFavoritesChange()
dataSource.getFavoriteRecipes()
storage.updateFavoriteRecipes(eq(listOf("porridge")))
pagingSourceFactory.invalidate()
}
}
@Test
fun `when add favorite recipe expect correct sequence`() = runTest {
coEvery { dataSource.getFavoriteRecipes() } returns listOf("porridge", "cake")
subject.updateIsRecipeFavorite("porridge", true)
coVerify {
dataSource.updateIsRecipeFavorite(eq("porridge"), eq(true))
remoteMediator.onFavoritesChange()
dataSource.getFavoriteRecipes()
storage.updateFavoriteRecipes(eq(listOf("porridge", "cake")))
pagingSourceFactory.invalidate()
}
}
@@ -92,7 +98,7 @@ class RecipeRepoTest : BaseUnitTest() {
dataSource.updateIsRecipeFavorite(any(), any())
} throws Unauthorized(IOException())
subject.updateIsRecipeFavorite("porridge", true)
coVerify(inverse = true) { remoteMediator.onFavoritesChange() }
coVerify(inverse = true) { dataSource.getFavoriteRecipes() }
}
@Test

View File

@@ -144,27 +144,6 @@ class RecipesRemoteMediatorTest : BaseUnitTest() {
coVerify { storage.refreshAll(TEST_RECIPE_SUMMARY_ENTITIES) }
}
@Test
fun `when favorites change expect network call`() = runTest {
coEvery { dataSource.getFavoriteRecipes() } returns listOf("cake", "porridge")
subject.onFavoritesChange()
coVerify { dataSource.getFavoriteRecipes() }
}
@Test
fun `when favorites change expect storage update`() = runTest {
coEvery { dataSource.getFavoriteRecipes() } returns listOf("cake", "porridge")
subject.onFavoritesChange()
coVerify { storage.updateFavoriteRecipes(eq(listOf("cake", "porridge"))) }
}
@Test
fun `when favorites change expect factory invalidation`() = runTest {
coEvery { dataSource.getFavoriteRecipes() } returns listOf("cake", "porridge")
subject.onFavoritesChange()
coVerify { pagingSourceFactory.invalidate() }
}
@Test
fun `when recipe update requested but favorite fails expect non-zero updates`() = runTest {
coEvery { dataSource.getFavoriteRecipes() } throws Unauthorized(IOException())