-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matt Ramotar <[email protected]>
- Loading branch information
1 parent
4df4b37
commit c0be786
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...on/trails/xplat/lib/repositories/post/impl/store/bookkeeper/PostBookkeepingRemoverTest.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.trails.xplat.lib.repositories.post.impl.store.bookkeeper | ||
|
||
import dev.mokkery.MockMode | ||
import dev.mokkery.mock | ||
import dev.mokkery.verify | ||
import dev.mokkery.verifyNoMoreCalls | ||
import kotlinx.coroutines.test.runTest | ||
import org.mobilenativefoundation.trails.xplat.lib.models.post.Post | ||
import org.mobilenativefoundation.trails.xplat.lib.repositories.post.impl.store.db.PostBookkeepingDAO | ||
import kotlin.test.Test | ||
|
||
class PostBookkeepingRemoverTest { | ||
private val bookkeepingDAO = mock<PostBookkeepingDAO>(MockMode.autoUnit) | ||
private val bookkeepingRemover = RealPostBookkeepingRemover(bookkeepingDAO) | ||
|
||
@Test | ||
fun removeFailedUpdates_givenValidDAOAndFailedUpdatesAndDeletes_whenCalledWithMultipleKeys_thenShouldClearFailedUpdatesOnly() = | ||
runTest { | ||
// Given | ||
val key1 = Post.Key(1) | ||
val key2 = Post.Key(2) | ||
val key3 = Post.Key(3) | ||
|
||
// When | ||
bookkeepingRemover.removeFailedUpdates(listOf(key1, key2, key3)) | ||
|
||
// Then | ||
verify { bookkeepingDAO.clearFailedUpdate(key1.id) } | ||
verify { bookkeepingDAO.clearFailedUpdate(key2.id) } | ||
verify { bookkeepingDAO.clearFailedUpdate(key3.id) } | ||
verifyNoMoreCalls(bookkeepingDAO) | ||
} | ||
|
||
@Test | ||
fun removeFailedDeletes_givenValidDAOAndFailedUpdatesAndDeletes_whenCalledWithMultipleKeys_thenShouldClearFailedDeletesOnly() = | ||
runTest { | ||
// Given | ||
val key1 = Post.Key(1) | ||
val key2 = Post.Key(2) | ||
val key3 = Post.Key(3) | ||
|
||
// When | ||
bookkeepingRemover.removeFailedDeletes(listOf(key1, key2, key3)) | ||
|
||
// Then | ||
verify { bookkeepingDAO.clearFailedDelete(key1.id) } | ||
verify { bookkeepingDAO.clearFailedDelete(key2.id) } | ||
verify { bookkeepingDAO.clearFailedDelete(key3.id) } | ||
verifyNoMoreCalls(bookkeepingDAO) | ||
} | ||
|
||
@Test | ||
fun removeAllFailedDeletes_givenValidDAOAndFailedUpdatesAndDeletes_whenCalled_thenShouldClearAllFailedDeletes() = | ||
runTest { | ||
// When | ||
bookkeepingRemover.removeAllFailedDeletes() | ||
|
||
// Then | ||
verify { bookkeepingDAO.clearAllFailedDeletes() } | ||
verifyNoMoreCalls(bookkeepingDAO) | ||
} | ||
|
||
@Test | ||
fun removeAllFailedUpdates_givenValidDAOAndFailedUpdatesAndDeletes_whenCalled_thenShouldClearAllFailedUpdates() = | ||
runTest { | ||
// When | ||
bookkeepingRemover.removeAllFailedUpdates() | ||
|
||
// Then | ||
verify { bookkeepingDAO.clearAllFailedUpdates() } | ||
verifyNoMoreCalls(bookkeepingDAO) | ||
} | ||
|
||
@Test | ||
fun removeFailedDelete_givenValidDAOAndFailedUpdatesAndDeletes_whenCalledWithSingleKey_thenShouldRemoveFailedDeletesForThatKey() = | ||
runTest { | ||
// Given | ||
val key1 = Post.Key(1) | ||
|
||
// When | ||
bookkeepingRemover.removeFailedDelete(key1) | ||
|
||
// Then | ||
verify { bookkeepingDAO.clearFailedDelete(key1.id) } | ||
verifyNoMoreCalls(bookkeepingDAO) | ||
} | ||
|
||
@Test | ||
fun removeFailedUpdate_givenValidDAOAndFailedUpdatesAndDeletes_whenCalledWithSingleKey_thenShouldRemoveFailedUpdatesForThatKey() = | ||
runTest { | ||
// Given | ||
val key1 = Post.Key(1) | ||
|
||
// When | ||
bookkeepingRemover.removeFailedUpdate(key1) | ||
|
||
// Then | ||
verify { bookkeepingDAO.clearFailedUpdate(key1.id) } | ||
verifyNoMoreCalls(bookkeepingDAO) | ||
} | ||
} |