Check for tasks.org accounts via caldav

pull/3420/head
Alex Baker 9 months ago
parent fb6af08917
commit 5427305e09

@ -1,12 +1,14 @@
package org.tasks.billing
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.runBlocking
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.tasks.LocalBroadcastManager
import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavAccount
import org.tasks.injection.InjectingTestCase
import org.tasks.preferences.Preferences
import javax.inject.Inject
@ -21,6 +23,24 @@ class InventoryTest : InjectingTestCase() {
lateinit var inventory: Inventory
@Test
fun hasTasksAccount() = runBlocking {
caldavDao.insert(CaldavAccount(accountType = CaldavAccount.TYPE_TASKS, url = "https://caldav.tasks.org/calendars/"))
initInventory()
inventory.updateTasksAccount()
assertTrue(inventory.hasTasksAccount)
}
@Test
fun hasTasksAccountWithCaldav() = runBlocking {
caldavDao.insert(CaldavAccount(accountType = CaldavAccount.TYPE_CALDAV, url = "https://caldav.tasks.org/calendars/"))
initInventory()
inventory.updateTasksAccount()
assertTrue(inventory.hasTasksAccount)
}
@Test
fun monthlyIsPro() {
withPurchases(monthly01)
@ -69,13 +89,17 @@ class InventoryTest : InjectingTestCase() {
}
.map(::Purchase)
preferences.setPurchases(asPurchases)
initInventory()
}
private fun initInventory() {
runOnMainSync {
inventory = Inventory(
context,
preferences,
signatureVerifier,
localBroadcastManager,
caldavDao
context,
preferences,
signatureVerifier,
localBroadcastManager,
caldavDao
)
}
}

@ -8,6 +8,7 @@ import org.tasks.BuildConfig
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavAccount.Companion.TYPE_CALDAV
import org.tasks.data.entity.CaldavAccount.Companion.TYPE_TASKS
import org.tasks.data.isTasksSubscription
import org.tasks.extensions.Context.openUri
@ -66,7 +67,7 @@ class Inventory @Inject constructor(
private set
suspend fun updateTasksAccount() {
hasTasksAccount = caldavDao.getAccounts(TYPE_TASKS).any {
hasTasksAccount = caldavDao.getAccounts(TYPE_TASKS, TYPE_CALDAV).any {
it.isTasksSubscription(context)
}
}

Loading…
Cancel
Save