Compare commits

..

2 Commits

Author SHA1 Message Date
667e9c1a5d Adjust tests to changes in the repository 2022-10-21 22:56:35 +02:00
53b1d1f8b2 Rework repository initialization 2022-10-21 22:42:32 +02:00
3 changed files with 63 additions and 75 deletions

View File

@ -93,6 +93,9 @@ 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,14 +41,7 @@ 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> {
@ -384,9 +377,6 @@ 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")
} }
@ -400,7 +390,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
api.refreshLoginInformation() api.refreshLoginInformation()
} }
private suspend fun updateApiVersion() { suspend fun updateApiVersion() {
val apiMajorVersion = appSettingsService.getApiVersion() val apiMajorVersion = appSettingsService.getApiVersion()
if (isNetworkAvailable()) { if (isNetworkAvailable()) {

View File

@ -24,6 +24,7 @@ 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() {
@ -48,10 +49,9 @@ class RepositoryTest() {
@Test @Test
fun `Instantiate repository`() { fun `Instantiate repository`() {
Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
coVerify(exactly = 1) { api.version() } coVerify(exactly = 1) { api.version() }
coVerify(exactly = 1) { api.stats() }
} }
@Test @Test
@ -59,25 +59,12 @@ class RepositoryTest() {
every { appSettingsService.getApiVersion() } returns -1 every { appSettingsService.getApiVersion() } returns -1
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
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
@ -85,7 +72,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -103,7 +90,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))
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -116,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()) SelfossModel.StatusAndData(success = true, data = generateTestApiItem())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -131,7 +118,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())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.displayedItems = ItemType.ALL repository.displayedItems = ItemType.ALL
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -147,7 +134,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())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.displayedItems = ItemType.STARRED repository.displayedItems = ItemType.STARRED
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -163,7 +150,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
} }
@ -189,7 +176,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.tagFilter = SelfossModel.Tag("Test", "red", 3) repository.tagFilter = SelfossModel.Tag("Test", "red", 3)
runBlocking { runBlocking {
repository.getNewerItems() repository.getNewerItems()
@ -216,7 +203,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
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()
@ -232,7 +219,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())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.items = ArrayList(generateTestApiItem()) repository.items = ArrayList(generateTestApiItem())
runBlocking { runBlocking {
repository.getOlderItems() repository.getOlderItems()
@ -248,7 +235,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())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.items = ArrayList(generateTestApiItem()) repository.items = ArrayList(generateTestApiItem())
repository.displayedItems = ItemType.ALL repository.displayedItems = ItemType.ALL
runBlocking { runBlocking {
@ -265,7 +252,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())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.displayedItems = ItemType.STARRED repository.displayedItems = ItemType.STARRED
repository.items = ArrayList(generateTestApiItem()) repository.items = ArrayList(generateTestApiItem())
runBlocking { runBlocking {
@ -281,7 +268,7 @@ class RepositoryTest() {
fun `Reload badges`() { fun `Reload badges`() {
var success = false var success = false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -300,7 +287,7 @@ class RepositoryTest() {
var success = false var success = false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -321,7 +308,7 @@ class RepositoryTest() {
var success = false var success = false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -342,7 +329,7 @@ class RepositoryTest() {
var success = false var success = false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
runBlocking { runBlocking {
success = repository.reloadBadges() success = repository.reloadBadges()
} }
@ -367,7 +354,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag>? = null var testTags: List<SelfossModel.Tag>? = null
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -390,7 +377,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -416,7 +403,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -439,7 +426,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -465,7 +452,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -490,7 +477,7 @@ class RepositoryTest() {
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
every { appSettingsService.isUpdateSourcesEnabled() } returns true every { appSettingsService.isUpdateSourcesEnabled() } returns true
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -514,7 +501,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns true every { appSettingsService.isItemCachingEnabled() } returns true
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -539,7 +526,7 @@ class RepositoryTest() {
every { appSettingsService.isUpdateSourcesEnabled() } returns false every { appSettingsService.isUpdateSourcesEnabled() } returns false
every { appSettingsService.isItemCachingEnabled() } returns false every { appSettingsService.isItemCachingEnabled() } returns false
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testTags: List<SelfossModel.Tag> = emptyList() var testTags: List<SelfossModel.Tag> = emptyList()
runBlocking { runBlocking {
testTags = repository.getTags() testTags = repository.getTags()
@ -559,7 +546,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -581,7 +568,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -606,7 +593,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -628,7 +615,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -649,7 +636,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -672,7 +659,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -695,7 +682,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -718,7 +705,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var testSources: List<SelfossModel.Source>? = null var testSources: List<SelfossModel.Source>? = null
runBlocking { runBlocking {
testSources = repository.getSources() testSources = repository.getSources()
@ -734,7 +721,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
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", "")
@ -749,7 +736,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
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", "")
@ -765,7 +752,7 @@ class RepositoryTest() {
SelfossModel.SuccessResponse(true) SelfossModel.SuccessResponse(true)
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false) every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
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", "")
@ -779,7 +766,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.deleteSource(5) response = repository.deleteSource(5)
@ -793,7 +780,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.deleteSource(5) response = repository.deleteSource(5)
@ -808,7 +795,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.deleteSource(5) response = repository.deleteSource(5)
@ -822,7 +809,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")
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -836,7 +823,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")
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -850,7 +837,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")
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -865,7 +852,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.updateRemote() response = repository.updateRemote()
@ -879,7 +866,7 @@ class RepositoryTest() {
fun login() { fun login() {
coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true) coEvery { api.login() } returns SelfossModel.SuccessResponse(success = true)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.login() response = repository.login()
@ -893,7 +880,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.login() response = repository.login()
@ -908,7 +895,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
var response = false var response = false
runBlocking { runBlocking {
response = repository.login() response = repository.login()
@ -923,7 +910,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
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
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() }
@ -943,7 +930,7 @@ class RepositoryTest() {
SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)), SelfossModel.StatusAndData(success = true, data = generateTestApiItem(itemParameter1)),
) )
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
repository.sourceFilter = SelfossModel.Source( repository.sourceFilter = SelfossModel.Source(
1, 1,
@ -966,7 +953,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())
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
repository.sourceFilter = SelfossModel.Source( repository.sourceFilter = SelfossModel.Source(
1, 1,
@ -990,7 +977,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)
val repository = Repository(api, appSettingsService, connectivityStatus, db) initializeRepository()
repository.tagFilter = SelfossModel.Tag("Tag", "read", 0) repository.tagFilter = SelfossModel.Tag("Tag", "read", 0)
repository.sourceFilter = SelfossModel.Source( repository.sourceFilter = SelfossModel.Source(
1, 1,
@ -1007,6 +994,14 @@ 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> {