Compare commits

..

No commits in common. "667e9c1a5d849d94cf0fdbeb24a8aa5c00056dab" and "c25e8889a45946cb33e29cd563a42e42f30d90c6" have entirely different histories.

3 changed files with 75 additions and 63 deletions

View File

@ -93,9 +93,6 @@ class LoginActivity : AppCompatActivity(), DIAware {
} }
private fun goToMain() { private fun goToMain() {
CoroutineScope(Dispatchers.Main).launch {
repository.updateApiVersion()
}
val intent = Intent(this, HomeActivity::class.java) val intent = Intent(this, HomeActivity::class.java)
startActivity(intent) startActivity(intent)
finish() finish()

View File

@ -41,7 +41,14 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
private var fetchedTags = false private var fetchedTags = false
init { init {
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
connectivityStatus.start() connectivityStatus.start()
if (appSettingsService.getBaseUrl() != "") {
runBlocking {
updateApiVersion()
reloadBadges()
}
}
} }
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> { suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
@ -377,6 +384,9 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
try { try {
val response = api.login() val response = api.login()
result = response.isSuccess == true result = response.isSuccess == true
if (result) {
updateApiVersion()
}
} catch (cause: Throwable) { } catch (cause: Throwable) {
Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.updateRemote") Napier.e(cause.stackTraceToString(), tag = "RepositoryImpl.updateRemote")
} }
@ -390,7 +400,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
api.refreshLoginInformation() api.refreshLoginInformation()
} }
suspend fun updateApiVersion() { private suspend fun updateApiVersion() {
val apiMajorVersion = appSettingsService.getApiVersion() val apiMajorVersion = appSettingsService.getApiVersion()
if (isNetworkAvailable()) { if (isNetworkAvailable()) {

View File

@ -24,7 +24,6 @@ class RepositoryTest() {
private val NUMBER_ARTICLES = 100 private val NUMBER_ARTICLES = 100
private val NUMBER_UNREAD = 50 private val NUMBER_UNREAD = 50
private val NUMBER_STARRED = 20 private val NUMBER_STARRED = 20
private lateinit var repository: Repository
@BeforeTest @BeforeTest
fun setup() { fun setup() {
@ -49,9 +48,10 @@ class RepositoryTest() {
@Test @Test
fun `Instantiate repository`() { fun `Instantiate repository`() {
initializeRepository() Repository(api, appSettingsService, connectivityStatus, db)
coVerify(exactly = 1) { api.version() } coVerify(exactly = 1) { api.version() }
coVerify(exactly = 1) { api.stats() }
} }
@Test @Test
@ -59,12 +59,25 @@ class RepositoryTest() {
every { appSettingsService.getApiVersion() } returns -1 every { appSettingsService.getApiVersion() } returns -1
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
initializeRepository() Repository(api, appSettingsService, connectivityStatus, db)
coVerify(exactly = 0) { api.version() } coVerify(exactly = 0) { api.version() }
coVerify(exactly = 0) { api.stats() } coVerify(exactly = 0) { api.stats() }
} }
@Test
fun `Instantiate repository with negative stats`() {
coEvery { api.stats() } returns SelfossModel.StatusAndData(success = true, data = SelfossModel.Stats(-100, -50, -20))
val repository = Repository(api, appSettingsService, connectivityStatus, db)
assertEquals(0, repository.badgeAll)
assertEquals(0, repository.badgeStarred)
assertEquals(0, repository.badgeUnread)
coVerify(exactly = 1) { api.version() }
coVerify(exactly = 1) { api.stats() }
}
@Test @Test
fun `Get api 4 date with api 1 version stored`() { fun `Get api 4 date with api 1 version stored`() {
every { appSettingsService.getApiVersion() } returns 1 every { appSettingsService.getApiVersion() } returns 1
@ -72,7 +85,7 @@ class RepositoryTest() {
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
every { appSettingsService.updateApiVersion(any()) } returns Unit every { appSettingsService.updateApiVersion(any()) } returns Unit
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -90,7 +103,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameters)) SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameters))
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -103,7 +116,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -118,7 +131,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.displayedItems = ItemType.ALL repository.displayedItems = ItemType.ALL
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -134,7 +147,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.displayedItems = ItemType.STARRED repository.displayedItems = ItemType.STARRED
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -150,7 +163,7 @@ class RepositoryTest() {
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -176,7 +189,7 @@ class RepositoryTest() {
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.tagFilter = SelfossModel.Tag("Test", "red", 3) repository.tagFilter = SelfossModel.Tag("Test", "red", 3)
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -203,7 +216,7 @@ class RepositoryTest() {
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.sourceFilter = SelfossModel.Source(1, "Test", listOf("tags"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png") repository.sourceFilter = SelfossModel.Source(1, "Test", listOf("tags"),"spouts\\rss\\fulltextrss", "", "b3aa8a664d08eb15d6ff1db2fa83e0d9.png")
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -219,7 +232,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.items = ArrayList(generateTestApiItem()) repository.items = ArrayList(generateTestApiItem())
runBlocking { runBlocking {
repository.getOlderItems() repository.getOlderItems()
@ -235,7 +248,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.items = ArrayList(generateTestApiItem()) repository.items = ArrayList(generateTestApiItem())
repository.displayedItems = ItemType.ALL repository.displayedItems = ItemType.ALL
runBlocking { runBlocking {
@ -252,7 +265,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = true, data = generateTestApiItem()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.displayedItems = ItemType.STARRED repository.displayedItems = ItemType.STARRED
repository.items = ArrayList(generateTestApiItem()) repository.items = ArrayList(generateTestApiItem())
runBlocking { runBlocking {
@ -268,7 +281,7 @@ class RepositoryTest() {
fun `Reload badges`() { fun `Reload badges`() {
var success = false var success = false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -287,7 +300,7 @@ class RepositoryTest() {
var success = false var success = false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -308,7 +321,7 @@ class RepositoryTest() {
var success = false var success = false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -329,7 +342,7 @@ class RepositoryTest() {
var success = false var success = false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -354,7 +367,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag>? = null var testTags: List<SelfossModel.Tag>? = null
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -377,7 +390,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -403,7 +416,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -426,7 +439,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -452,7 +465,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -477,7 +490,7 @@ class RepositoryTest() {
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -501,7 +514,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -526,7 +539,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -546,7 +559,7 @@ class RepositoryTest() {
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -568,7 +581,7 @@ class RepositoryTest() {
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -593,7 +606,7 @@ class RepositoryTest() {
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -615,7 +628,7 @@ class RepositoryTest() {
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -636,7 +649,7 @@ class RepositoryTest() {
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -659,7 +672,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -682,7 +695,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -705,7 +718,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources) coEvery { api.sources() } returns SelfossModel.StatusAndData(success = true, data = sources)
every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB every { db.sourcesQueries.sources().executeAsList() } returns sourcesDB
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -721,7 +734,7 @@ class RepositoryTest() {
coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns
SelfossModel.SuccessResponse(true) SelfossModel.SuccessResponse(true)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "") response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "")
@ -736,7 +749,7 @@ class RepositoryTest() {
coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns coEvery { api.createSourceForVersion(any(), any(), any(), any(), any(), any()) } returns
SelfossModel.SuccessResponse(false) SelfossModel.SuccessResponse(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "") response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "")
@ -752,7 +765,7 @@ class RepositoryTest() {
SelfossModel.SuccessResponse(true) SelfossModel.SuccessResponse(true)
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "") response = repository.createSource("test", "https://test.com/feed", "spouts\\rss\\fulltextrss", "Test, New", "")
@ -766,7 +779,7 @@ class RepositoryTest() {
fun `delete source`() { fun `delete source`() {
coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(true) coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(true)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.deleteSource(5) response = repository.deleteSource(5)
@ -780,7 +793,7 @@ class RepositoryTest() {
fun `delete source but response fails`() { fun `delete source but response fails`() {
coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(false) coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.deleteSource(5) response = repository.deleteSource(5)
@ -795,7 +808,7 @@ class RepositoryTest() {
coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(false) coEvery { api.deleteSource(any())} returns SelfossModel.SuccessResponse(false)
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.deleteSource(5) response = repository.deleteSource(5)
@ -809,7 +822,7 @@ class RepositoryTest() {
fun `update remote`() { fun `update remote`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "finished") coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "finished")
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -823,7 +836,7 @@ class RepositoryTest() {
fun `update remote but response fails`() { fun `update remote but response fails`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = false, data = "unallowed access") coEvery { api.update()} returns SelfossModel.StatusAndData(success = false, data = "unallowed access")
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -837,7 +850,7 @@ class RepositoryTest() {
fun `update remote with unallowed access`() { fun `update remote with unallowed access`() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "unallowed access") coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "unallowed access")
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -852,7 +865,7 @@ class RepositoryTest() {
coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "undocumented...") coEvery { api.update()} returns SelfossModel.StatusAndData(success = true, data = "undocumented...")
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -866,7 +879,7 @@ class RepositoryTest() {
fun login() { fun login() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.login() response = repository.login()
@ -880,7 +893,7 @@ class RepositoryTest() {
fun `login but response fails`() { fun `login but response fails`() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = false) coEvery { api.login() } returns SelfossModel.SuccessResponse(success = false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.login() response = repository.login()
@ -895,7 +908,7 @@ class RepositoryTest() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true)
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
var response = false var response = false
runBlocking { runBlocking {
response = repository.login() response = repository.login()
@ -910,7 +923,7 @@ class RepositoryTest() {
coEvery { api.refreshLoginInformation() } returns Unit coEvery { api.refreshLoginInformation() } returns Unit
coEvery { appSettingsService.refreshLoginInformation(any(), any(), any()) } returns Unit coEvery { appSettingsService.refreshLoginInformation(any(), any(), any()) } returns Unit
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.refreshLoginInformation("https://test.com/selfoss/", "login", "password") repository.refreshLoginInformation("https://test.com/selfoss/", "login", "password")
coVerify(exactly = 1) { api.refreshLoginInformation() } coVerify(exactly = 1) { api.refreshLoginInformation() }
@ -930,7 +943,7 @@ class RepositoryTest() {
SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)),
) )
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
repository.sourceFilter = SelfossModel.Source( repository.sourceFilter = SelfossModel.Source(
1, 1,
@ -953,7 +966,7 @@ class RepositoryTest() {
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
SelfossModel.StatusAndData(success = false, data = generateTestApiItem()) SelfossModel.StatusAndData(success = false, data = generateTestApiItem())
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
repository.sourceFilter = SelfossModel.Source( repository.sourceFilter = SelfossModel.Source(
1, 1,
@ -977,7 +990,7 @@ class RepositoryTest() {
SelfossModel.StatusAndData(success = false, data = generateTestApiItem()) SelfossModel.StatusAndData(success = false, data = generateTestApiItem())
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
initializeRepository() val repository = Repository(api, appSettingsService, connectivityStatus, db)
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
repository.sourceFilter = SelfossModel.Source( repository.sourceFilter = SelfossModel.Source(
1, 1,
@ -994,14 +1007,6 @@ class RepositoryTest() {
coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) } coVerify(exactly = 0) { api.getItems(any(), 0, null, null, null, null, 200) }
} }
fun initializeRepository() {
repository = Repository(api, appSettingsService, connectivityStatus, db)
runBlocking {
repository.updateApiVersion()
}
}
} }
fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> { fun generateTestDBItems(item : FakeItemParameters = FakeItemParameters()) : List<ITEM> {