mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
tell the user when a sync fails
The failure was only recorded as SyncStatus.Failed, which nothing shows, so a bad username or an unreachable server folded silently. It goes through the same toast the rest of the data layer uses, with the server's own message.
This commit is contained in:
@@ -21,6 +21,7 @@ import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class SyncManagerTest {
|
||||
@@ -28,6 +29,7 @@ class SyncManagerTest {
|
||||
private lateinit var sourceRepository: SourceRepository
|
||||
private lateinit var queueRepository: QueueRepository
|
||||
private lateinit var manager: SyncManager
|
||||
private val messages = CopyOnWriteArrayList<String>()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
@@ -39,7 +41,7 @@ class SyncManagerTest {
|
||||
.build()
|
||||
sourceRepository = SourceRepository(db, OkHttpClient(), fakeUserPreferences(), ArtworkStore(File(context.cacheDir, "art")))
|
||||
queueRepository = QueueRepository(db)
|
||||
manager = SyncManager(db, sourceRepository, queueRepository)
|
||||
manager = SyncManager(db, sourceRepository, queueRepository, showMessage = { messages += it })
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -48,6 +50,15 @@ class SyncManagerTest {
|
||||
db.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedSyncTellsTheUser() =
|
||||
runBlocking {
|
||||
manager.requestSync()
|
||||
withTimeout(10_000) { manager.status.first { it is SyncStatus.Failed } }
|
||||
|
||||
assertEquals(listOf("Sync failed: No server configured"), messages)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedSyncStillInvalidatesTheLibraryCache() =
|
||||
runBlocking {
|
||||
|
||||
Reference in New Issue
Block a user