mirror of https://github.com/tasks/tasks
Add caldav subscription test
parent
11fdf0f825
commit
e2f253da98
@ -0,0 +1,47 @@
|
|||||||
|
package org.tasks.caldav
|
||||||
|
|
||||||
|
import com.todoroo.astrid.dao.TaskDao
|
||||||
|
import okhttp3.mockwebserver.MockResponse
|
||||||
|
import okhttp3.mockwebserver.MockWebServer
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
|
import org.tasks.R
|
||||||
|
import org.tasks.data.CaldavAccount
|
||||||
|
import org.tasks.data.CaldavDao
|
||||||
|
import org.tasks.injection.InjectingTestCase
|
||||||
|
import org.tasks.preferences.Preferences
|
||||||
|
import org.tasks.security.KeyStoreEncryption
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
abstract class CaldavTest : InjectingTestCase() {
|
||||||
|
@Inject lateinit var synchronizer: CaldavSynchronizer
|
||||||
|
@Inject lateinit var encryption: KeyStoreEncryption
|
||||||
|
@Inject lateinit var preferences: Preferences
|
||||||
|
@Inject lateinit var caldavDao: CaldavDao
|
||||||
|
@Inject lateinit var taskDao: TaskDao
|
||||||
|
protected val server = MockWebServer()
|
||||||
|
protected lateinit var account: CaldavAccount
|
||||||
|
|
||||||
|
@Before
|
||||||
|
override fun setUp() {
|
||||||
|
super.setUp()
|
||||||
|
|
||||||
|
preferences.setBoolean(R.string.p_debug_pro, true)
|
||||||
|
server.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun after() = server.shutdown()
|
||||||
|
|
||||||
|
protected fun enqueue(vararg responses: String) = responses.forEach {
|
||||||
|
server.enqueue(
|
||||||
|
MockResponse()
|
||||||
|
.setResponseCode(207)
|
||||||
|
.setHeader("Content-Type", "text/xml; charset=\"utf-8\"")
|
||||||
|
.setBody(it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun enqueueFailure(code: Int = 500) =
|
||||||
|
server.enqueue(MockResponse().setResponseCode(code))
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package org.tasks.caldav
|
||||||
|
|
||||||
|
import com.todoroo.astrid.helper.UUIDHelper
|
||||||
|
import dagger.hilt.android.testing.HiltAndroidTest
|
||||||
|
import dagger.hilt.android.testing.UninstallModules
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
import org.tasks.R
|
||||||
|
import org.tasks.data.CaldavAccount
|
||||||
|
import org.tasks.injection.ProductionModule
|
||||||
|
|
||||||
|
@UninstallModules(ProductionModule::class)
|
||||||
|
@HiltAndroidTest
|
||||||
|
class CaldavSubscriptionTest : CaldavTest() {
|
||||||
|
@Test
|
||||||
|
fun cantSyncWithoutPro() = runBlocking {
|
||||||
|
preferences.setBoolean(R.string.p_debug_pro, false)
|
||||||
|
account = CaldavAccount().apply {
|
||||||
|
uuid = UUIDHelper.newUUID()
|
||||||
|
id = caldavDao.insert(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronizer.sync(account)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
context.getString(R.string.requires_pro_subscription),
|
||||||
|
caldavDao.getAccountByUuid(account.uuid!!)?.error
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue