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 package org.tasks.billing
import dagger.hilt.android.testing.HiltAndroidTest import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.runBlocking
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
import org.tasks.LocalBroadcastManager import org.tasks.LocalBroadcastManager
import org.tasks.data.dao.CaldavDao import org.tasks.data.dao.CaldavDao
import org.tasks.data.entity.CaldavAccount
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import javax.inject.Inject import javax.inject.Inject
@ -21,6 +23,24 @@ class InventoryTest : InjectingTestCase() {
lateinit var inventory: Inventory 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 @Test
fun monthlyIsPro() { fun monthlyIsPro() {
withPurchases(monthly01) withPurchases(monthly01)
@ -69,6 +89,10 @@ class InventoryTest : InjectingTestCase() {
} }
.map(::Purchase) .map(::Purchase)
preferences.setPurchases(asPurchases) preferences.setPurchases(asPurchases)
initInventory()
}
private fun initInventory() {
runOnMainSync { runOnMainSync {
inventory = Inventory( inventory = Inventory(
context, context,

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

Loading…
Cancel
Save