Fix tests

pull/2146/head
Alex Baker 3 years ago
parent c2222657ec
commit 120eb4dd30

@ -224,7 +224,7 @@ class CaldavManualSortTaskAdapterTest : InjectingTestCase() {
private fun checkOrder(dateTime: DateTime, index: Int) = checkOrder(dateTime.toAppleEpoch(), index) private fun checkOrder(dateTime: DateTime, index: Int) = checkOrder(dateTime.toAppleEpoch(), index)
private fun checkOrder(order: Long?, index: Int) = runBlocking { private fun checkOrder(order: Long?, index: Int) = runBlocking {
val sortOrder = caldavDao.getTask(adapter.getTask(index).id)!!.order val sortOrder = taskDao.fetch(adapter.getTask(index).id)!!.order
if (order == null) { if (order == null) {
assertNull(sortOrder) assertNull(sortOrder)
} else { } else {

@ -202,14 +202,6 @@ class CaldavTaskAdapterTest : InjectingTestCase() {
caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.parent) caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.parent)
} }
caldavTask.id = caldavDao.insert(caldavTask) caldavTask.id = caldavDao.insert(caldavTask)
t.caldavTask = caldavTask.toSubset() t.caldavTask = caldavTask
}
private fun CaldavTask.toSubset(): SubsetCaldav {
val result = SubsetCaldav()
result.cd_id = id
result.cd_calendar = calendar
result.cd_remote_parent = remoteParent
return result
} }
} }

@ -19,12 +19,11 @@ import org.tasks.data.TaskContainer
import org.tasks.data.TaskListQuery.getQuery import org.tasks.data.TaskListQuery.getQuery
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.makers.GoogleTaskListMaker.REMOTE_ID import org.tasks.makers.CaldavCalendarMaker
import org.tasks.makers.GoogleTaskListMaker.newGoogleTaskList import org.tasks.makers.CaldavCalendarMaker.newCaldavCalendar
import org.tasks.makers.GoogleTaskMaker import org.tasks.makers.CaldavTaskMaker.CALENDAR
import org.tasks.makers.GoogleTaskMaker.LIST import org.tasks.makers.CaldavTaskMaker.TASK
import org.tasks.makers.GoogleTaskMaker.TASK import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.GoogleTaskMaker.newGoogleTask
import org.tasks.makers.TaskMaker.PARENT import org.tasks.makers.TaskMaker.PARENT
import org.tasks.makers.TaskMaker.newTask import org.tasks.makers.TaskMaker.newTask
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
@ -41,7 +40,7 @@ class GoogleTaskManualSortAdapterTest : InjectingTestCase() {
private lateinit var adapter: GoogleTaskManualSortAdapter private lateinit var adapter: GoogleTaskManualSortAdapter
private val tasks = ArrayList<TaskContainer>() private val tasks = ArrayList<TaskContainer>()
private val filter = GtasksFilter(newGoogleTaskList(with(REMOTE_ID, "1234"))) private val filter = GtasksFilter(newCaldavCalendar(with(CaldavCalendarMaker.UUID, "1234")))
private val dataSource = object : TaskAdapterDataSource { private val dataSource = object : TaskAdapterDataSource {
override fun getItem(position: Int) = tasks[position] override fun getItem(position: Int) = tasks[position]
@ -427,22 +426,22 @@ class GoogleTaskManualSortAdapterTest : InjectingTestCase() {
} }
private fun checkOrder(order: Long, index: Int, parent: Long = 0) = runBlocking { private fun checkOrder(order: Long, index: Int, parent: Long = 0) = runBlocking {
val googleTask = googleTaskDao.getByTaskId(adapter.getTask(index).id)!! val googleTask = taskDao.fetch(adapter.getTask(index).id)!!
assertEquals(order, googleTask.order) assertEquals(order, googleTask.order)
assertEquals(parent, googleTask.parent) assertEquals(parent, googleTask.parent)
} }
private fun addTask(vararg properties: PropertyValue<in Task?, *>): Long = runBlocking { private fun addTask(vararg properties: PropertyValue<in Task?, *>): Long = runBlocking {
val task = newTask(*properties) val task = newTask(*properties)
val parent = task.parent
task.parent = 0
taskDao.createNew(task) taskDao.createNew(task)
googleTaskDao.insertAndShift( googleTaskDao.insertAndShift(
newGoogleTask( task,
with(TASK, task.id), newCaldavTask(
with(LIST, "1234"), with(TASK, task.id),
with(GoogleTaskMaker.PARENT, parent)), with(CALENDAR, "1234"),
false) ),
false
)
task.id task.id
} }
} }

@ -16,10 +16,10 @@ import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskListDao import org.tasks.data.GoogleTaskListDao
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.makers.GtaskListMaker.ID import org.tasks.makers.CaldavCalendarMaker.ID
import org.tasks.makers.GtaskListMaker.NAME import org.tasks.makers.CaldavCalendarMaker.NAME
import org.tasks.makers.GtaskListMaker.REMOTE_ID import org.tasks.makers.CaldavCalendarMaker.UUID
import org.tasks.makers.GtaskListMaker.newGtaskList import org.tasks.makers.CaldavCalendarMaker.newCaldavCalendar
import org.tasks.makers.RemoteGtaskListMaker import org.tasks.makers.RemoteGtaskListMaker
import org.tasks.makers.RemoteGtaskListMaker.newRemoteList import org.tasks.makers.RemoteGtaskListMaker.newRemoteList
import javax.inject.Inject import javax.inject.Inject
@ -46,13 +46,13 @@ class GtasksListServiceTest : InjectingTestCase() {
newRemoteList( newRemoteList(
with(RemoteGtaskListMaker.REMOTE_ID, "1"), with(RemoteGtaskListMaker.NAME, "Default"))) with(RemoteGtaskListMaker.REMOTE_ID, "1"), with(RemoteGtaskListMaker.NAME, "Default")))
assertEquals( assertEquals(
newGtaskList(with(ID, 1L), with(REMOTE_ID, "1"), with(NAME, "Default")), newCaldavCalendar(with(ID, 1L), with(UUID, "1"), with(NAME, "Default")),
googleTaskListDao.getById(1L)) googleTaskListDao.getById(1L))
} }
@Test @Test
fun testGetListByRemoteId() = runBlocking { fun testGetListByRemoteId() = runBlocking {
val list = newGtaskList(with(REMOTE_ID, "1")) val list = newCaldavCalendar(with(UUID, "1"))
list.id = googleTaskListDao.insertOrReplace(list) list.id = googleTaskListDao.insertOrReplace(list)
assertEquals(list, googleTaskListDao.getByRemoteId("1")) assertEquals(list, googleTaskListDao.getByRemoteId("1"))
} }
@ -64,18 +64,19 @@ class GtasksListServiceTest : InjectingTestCase() {
@Test @Test
fun testDeleteMissingList() = runBlocking { fun testDeleteMissingList() = runBlocking {
googleTaskListDao.insertOrReplace(newGtaskList(with(ID, 1L), with(REMOTE_ID, "1"))) googleTaskListDao.insertOrReplace(newCaldavCalendar(with(ID, 1L), with(UUID, "1")))
val taskList = newRemoteList(with(RemoteGtaskListMaker.REMOTE_ID, "2")) val taskList = newRemoteList(with(RemoteGtaskListMaker.REMOTE_ID, "2"))
setLists(taskList) setLists(taskList)
assertEquals( assertEquals(
listOf(newGtaskList(with(ID, 2L), with(REMOTE_ID, "2"))), listOf(newCaldavCalendar(with(ID, 2L), with(UUID, "2"), with(NAME, "Default"))),
googleTaskListDao.getLists("account")) googleTaskListDao.getLists("account"))
} }
@Test @Test
fun testUpdateListName() = runBlocking { fun testUpdateListName() = runBlocking {
googleTaskListDao.insertOrReplace( googleTaskListDao.insertOrReplace(
newGtaskList(with(ID, 1L), with(REMOTE_ID, "1"), with(NAME, "oldName"))) newCaldavCalendar(with(ID, 1L), with(UUID, "1"), with(NAME, "oldName"))
)
setLists( setLists(
newRemoteList( newRemoteList(
with(RemoteGtaskListMaker.REMOTE_ID, "1"), with(RemoteGtaskListMaker.NAME, "newName"))) with(RemoteGtaskListMaker.REMOTE_ID, "1"), with(RemoteGtaskListMaker.NAME, "newName")))

@ -1,80 +0,0 @@
/*
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.gtasks
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test
import org.tasks.data.GoogleTaskDao
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class GtasksMetadataServiceTest : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var googleTaskDao: GoogleTaskDao
private var task: Task? = null
private var metadata: GoogleTask? = null
@Test
fun testMetadataFound() = runBlocking {
givenTask(taskWithMetadata(null))
whenSearchForMetadata()
thenExpectMetadataFound()
}
@Test
fun testMetadataDoesntExist() = runBlocking {
givenTask(taskWithoutMetadata())
whenSearchForMetadata()
thenExpectNoMetadataFound()
}
private fun thenExpectNoMetadataFound() {
assertNull(metadata)
}
private fun thenExpectMetadataFound() {
assertNotNull(metadata)
}
// --- helpers
private suspend fun whenSearchForMetadata() {
metadata = googleTaskDao.getByTaskId(task!!.id)
}
private suspend fun taskWithMetadata(id: String?): Task {
val task = Task()
task.title = "cats"
taskDao.createNew(task)
val metadata = GoogleTask(task.id, "")
if (id != null) {
metadata.remoteId = id
}
metadata.task = task.id
googleTaskDao.insert(metadata)
return task
}
private fun givenTask(taskToTest: Task) {
task = taskToTest
}
private suspend fun taskWithoutMetadata(): Task {
val task = Task()
task.title = "dogs"
taskDao.createNew(task)
return task
}
}

@ -12,9 +12,6 @@ import org.tasks.data.GoogleTaskDao
import org.tasks.data.TaskDao import org.tasks.data.TaskDao
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.makers.GoogleTaskMaker
import org.tasks.makers.GoogleTaskMaker.TASK
import org.tasks.makers.GoogleTaskMaker.newGoogleTask
import org.tasks.makers.TaskMaker.COMPLETION_TIME import org.tasks.makers.TaskMaker.COMPLETION_TIME
import org.tasks.makers.TaskMaker.PARENT import org.tasks.makers.TaskMaker.PARENT
import org.tasks.makers.TaskMaker.RECUR import org.tasks.makers.TaskMaker.RECUR
@ -96,42 +93,6 @@ class TaskDeleterTest : InjectingTestCase() {
assertTrue(taskDao.fetch(child)!!.isDeleted) assertTrue(taskDao.fetch(child)!!.isDeleted)
} }
@Test
fun dontClearCompletedGoogleTaskWithRecurringParent() = runBlocking {
val parent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY;INTERVAL=1")))
val child = taskDao.createNew(newTask(with(COMPLETION_TIME, DateTime())))
googleTaskDao.insert(newGoogleTask(with(TASK, child), with(GoogleTaskMaker.PARENT, parent)))
clearCompleted()
assertFalse(taskDao.fetch(child)!!.isDeleted)
}
@Test
fun clearCompletedGoogleTaskWithNonRecurringParent() = runBlocking {
val parent = taskDao.createNew(newTask())
val child = taskDao.createNew(newTask(with(COMPLETION_TIME, DateTime())))
googleTaskDao.insert(newGoogleTask(with(TASK, child), with(GoogleTaskMaker.PARENT, parent)))
clearCompleted()
assertTrue(taskDao.fetch(child)!!.isDeleted)
}
@Test
fun clearCompletedGoogleTaskWithCompletedRecurringParent() = runBlocking {
val parent = taskDao.createNew(newTask(
with(RECUR, "RRULE:FREQ=DAILY;INTERVAL=1"),
with(COMPLETION_TIME, DateTime())
))
val child = taskDao.createNew(newTask(with(COMPLETION_TIME, DateTime())))
googleTaskDao.insert(newGoogleTask(with(TASK, child), with(GoogleTaskMaker.PARENT, parent)))
clearCompleted()
assertTrue(taskDao.fetch(child)!!.isDeleted)
}
private suspend fun clearCompleted() = private suspend fun clearCompleted() =
taskDeleter.clearCompleted(getMyTasksFilter(context.resources)) taskDeleter.clearCompleted(getMyTasksFilter(context.resources))
} }

@ -9,28 +9,29 @@ import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test import org.junit.Test
import org.tasks.data.CaldavAccount.Companion.TYPE_CALDAV
import org.tasks.data.CaldavAccount.Companion.TYPE_GOOGLE_TASKS
import org.tasks.data.CaldavCalendar import org.tasks.data.CaldavCalendar
import org.tasks.data.CaldavDao import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskDao import org.tasks.data.GoogleTaskDao
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.jobs.WorkManager import org.tasks.jobs.WorkManager
import org.tasks.makers.CaldavCalendarMaker.UUID import org.tasks.makers.CaldavAccountMaker
import org.tasks.makers.CaldavAccountMaker.ACCOUNT_TYPE
import org.tasks.makers.CaldavAccountMaker.newCaldavAccount
import org.tasks.makers.CaldavCalendarMaker
import org.tasks.makers.CaldavCalendarMaker.ACCOUNT
import org.tasks.makers.CaldavCalendarMaker.newCaldavCalendar import org.tasks.makers.CaldavCalendarMaker.newCaldavCalendar
import org.tasks.makers.CaldavTaskMaker
import org.tasks.makers.CaldavTaskMaker.CALENDAR import org.tasks.makers.CaldavTaskMaker.CALENDAR
import org.tasks.makers.CaldavTaskMaker.REMOTE_ID import org.tasks.makers.CaldavTaskMaker.REMOTE_ID
import org.tasks.makers.CaldavTaskMaker.REMOTE_PARENT import org.tasks.makers.CaldavTaskMaker.REMOTE_PARENT
import org.tasks.makers.CaldavTaskMaker.TASK
import org.tasks.makers.CaldavTaskMaker.newCaldavTask import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.GoogleTaskMaker.LIST
import org.tasks.makers.GoogleTaskMaker.PARENT
import org.tasks.makers.GoogleTaskMaker.TASK
import org.tasks.makers.GoogleTaskMaker.newGoogleTask
import org.tasks.makers.GtaskListMaker
import org.tasks.makers.GtaskListMaker.newGtaskList
import org.tasks.makers.TaskMaker
import org.tasks.makers.TaskMaker.ID import org.tasks.makers.TaskMaker.ID
import org.tasks.makers.TaskMaker.PARENT
import org.tasks.makers.TaskMaker.newTask import org.tasks.makers.TaskMaker.newTask
import javax.inject.Inject import javax.inject.Inject
@ -44,18 +45,28 @@ class TaskMoverTest : InjectingTestCase() {
@Inject lateinit var caldavDao: CaldavDao @Inject lateinit var caldavDao: CaldavDao
@Inject lateinit var taskMover: TaskMover @Inject lateinit var taskMover: TaskMover
@Before
fun setup() {
runBlocking {
caldavDao.insert(newCaldavCalendar(with(CaldavCalendarMaker.UUID, "1"), with(ACCOUNT, "account1")))
caldavDao.insert(newCaldavCalendar(with(CaldavCalendarMaker.UUID, "2"), with(ACCOUNT, "account2")))
}
}
@Test @Test
fun moveBetweenGoogleTaskLists() = runBlocking { fun moveBetweenGoogleTaskLists() = runBlocking {
setAccountType("account1", TYPE_GOOGLE_TASKS)
setAccountType("account2", TYPE_GOOGLE_TASKS)
createTasks(1) createTasks(1)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1) moveToGoogleTasks("2", 1)
assertEquals("2", googleTaskDao.getByTaskId(1)!!.calendar) assertEquals("2", googleTaskDao.getByTaskId(1)?.calendar)
} }
@Test @Test
fun deleteGoogleTaskAfterMove() = runBlocking { fun deleteGoogleTaskAfterMove() = runBlocking {
createTasks(1) createTasks(1)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1) moveToGoogleTasks("2", 1)
val deleted = googleTaskDao.getDeletedByTaskId(1) val deleted = googleTaskDao.getDeletedByTaskId(1)
assertEquals(1, deleted.size.toLong()) assertEquals(1, deleted.size.toLong())
@ -65,24 +76,25 @@ class TaskMoverTest : InjectingTestCase() {
@Test @Test
fun moveChildrenBetweenGoogleTaskLists() = runBlocking { fun moveChildrenBetweenGoogleTaskLists() = runBlocking {
createTasks(1, 2) setAccountType("account1", TYPE_GOOGLE_TASKS)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) setAccountType("account2", TYPE_GOOGLE_TASKS)
googleTaskDao.insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(PARENT, 1L))) createTasks(1)
createSubtask(2, 1)
googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
googleTaskDao.insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1) moveToGoogleTasks("2", 1)
val deleted = googleTaskDao.getDeletedByTaskId(2) val deleted = googleTaskDao.getDeletedByTaskId(2)
assertEquals(1, deleted.size.toLong()) assertEquals(1, deleted.size.toLong())
assertEquals(2, deleted[0].task) assertEquals(2, deleted[0].task)
assertTrue(deleted[0].deleted > 0) assertTrue(deleted[0].deleted > 0)
val task = googleTaskDao.getByTaskId(2)!! assertEquals(1L, taskDao.fetch(2)?.parent)
assertEquals(1, task.parent) assertEquals("2", googleTaskDao.getByTaskId(2)?.calendar)
assertEquals("2", task.calendar)
} }
@Test @Test
fun moveBetweenCaldavList() = runBlocking { fun moveBetweenCaldavList() = runBlocking {
createTasks(1) createTasks(1)
caldavDao.insert(newCaldavCalendar(with(UUID, "1"))) caldavDao.insert(newCaldavTask(with(TASK, 1L), with(CALENDAR, "1")))
caldavDao.insert(newCaldavTask(with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1")))
moveToCaldavList("2", 1) moveToCaldavList("2", 1)
assertEquals("2", caldavDao.getTask(1)!!.calendar) assertEquals("2", caldavDao.getTask(1)!!.calendar)
} }
@ -90,8 +102,7 @@ class TaskMoverTest : InjectingTestCase() {
@Test @Test
fun deleteCaldavTaskAfterMove() = runBlocking { fun deleteCaldavTaskAfterMove() = runBlocking {
createTasks(1) createTasks(1)
caldavDao.insert(newCaldavCalendar(with(UUID, "1"))) caldavDao.insert(newCaldavTask(with(TASK, 1L), with(CALENDAR, "1")))
caldavDao.insert(newCaldavTask(with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1")))
moveToCaldavList("2", 1) moveToCaldavList("2", 1)
val deleted = caldavDao.getMoved("1") val deleted = caldavDao.getMoved("1")
assertEquals(1, deleted.size.toLong()) assertEquals(1, deleted.size.toLong())
@ -104,18 +115,17 @@ class TaskMoverTest : InjectingTestCase() {
createTasks(1) createTasks(1)
createSubtask(2, 1) createSubtask(2, 1)
createSubtask(3, 2) createSubtask(3, 2)
caldavDao.insert(newCaldavCalendar(with(UUID, "1")))
caldavDao.insert( caldavDao.insert(
listOf( listOf(
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")), with(TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")),
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 2L), with(TASK, 2L),
with(CALENDAR, "1"), with(CALENDAR, "1"),
with(REMOTE_ID, "b"), with(REMOTE_ID, "b"),
with(REMOTE_PARENT, "a")), with(REMOTE_PARENT, "a")),
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 3L), with(TASK, 3L),
with(CALENDAR, "1"), with(CALENDAR, "1"),
with(REMOTE_PARENT, "b")))) with(REMOTE_PARENT, "b"))))
moveToCaldavList("2", 1) moveToCaldavList("2", 1)
@ -128,13 +138,16 @@ class TaskMoverTest : InjectingTestCase() {
@Test @Test
fun moveGoogleTaskChildrenToCaldav() = runBlocking { fun moveGoogleTaskChildrenToCaldav() = runBlocking {
createTasks(1, 2) setAccountType("account1", TYPE_GOOGLE_TASKS)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) setAccountType("account2", TYPE_CALDAV)
googleTaskDao.insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(PARENT, 1L))) createTasks(1)
createSubtask(2, 1)
googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
googleTaskDao.insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "1")))
moveToCaldavList("1", 1) moveToCaldavList("1", 1)
val task = caldavDao.getTask(2) val task = caldavDao.getTask(2)
assertEquals("1", task!!.calendar) assertEquals("1", task!!.calendar)
assertEquals(1, taskDao.fetch(2)!!.parent) assertEquals(1L, taskDao.fetch(2)?.parent)
} }
@Test @Test
@ -143,8 +156,7 @@ class TaskMoverTest : InjectingTestCase() {
createSubtask(2, 1) createSubtask(2, 1)
createSubtask(3, 2) createSubtask(3, 2)
moveToGoogleTasks("1", 1) moveToGoogleTasks("1", 1)
assertEquals(1, googleTaskDao.getByTaskId(3)!!.parent) assertEquals(1L, taskDao.fetch(3)?.parent)
assertEquals(0, taskDao.fetch(3)!!.parent)
} }
@Test @Test
@ -152,7 +164,7 @@ class TaskMoverTest : InjectingTestCase() {
createTasks(1) createTasks(1)
createSubtask(2, 1) createSubtask(2, 1)
moveToGoogleTasks("1", 2) moveToGoogleTasks("1", 2)
assertEquals(0, taskDao.fetch(2)!!.parent) assertEquals(0L, taskDao.fetch(2)?.parent)
} }
@Test @Test
@ -171,43 +183,43 @@ class TaskMoverTest : InjectingTestCase() {
caldavDao.insert( caldavDao.insert(
listOf( listOf(
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")), with(TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")),
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 2L), with(TASK, 2L),
with(CALENDAR, "1"), with(CALENDAR, "1"),
with(REMOTE_ID, "b"), with(REMOTE_ID, "b"),
with(REMOTE_PARENT, "a")), with(REMOTE_PARENT, "a")),
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 3L), with(TASK, 3L),
with(CALENDAR, "1"), with(CALENDAR, "1"),
with(REMOTE_PARENT, "b")))) with(REMOTE_PARENT, "b"))))
moveToGoogleTasks("1", 1) moveToGoogleTasks("1", 1)
val task = googleTaskDao.getByTaskId(3L)!! val task = taskDao.fetch(3L)
assertEquals(1, task.parent) assertEquals(1L, task?.parent)
} }
@Test @Test
fun moveGoogleTaskChildWithoutParent() = runBlocking { fun moveGoogleTaskChildWithoutParent() = runBlocking {
createTasks(1, 2) setAccountType("account2", TYPE_GOOGLE_TASKS)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) createTasks(1)
googleTaskDao.insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(PARENT, 1L))) createSubtask(2, 1)
googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
googleTaskDao.insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "1")))
moveToGoogleTasks("2", 2) moveToGoogleTasks("2", 2)
val task = googleTaskDao.getByTaskId(2)!! assertEquals(0L, taskDao.fetch(2)?.parent)
assertEquals(0L, task.parent) assertEquals("2", googleTaskDao.getByTaskId(2)?.calendar)
assertEquals("2", task.calendar)
} }
@Test @Test
fun moveCaldavChildWithoutParent() = runBlocking { fun moveCaldavChildWithoutParent() = runBlocking {
createTasks(1) createTasks(1)
createSubtask(2, 1) createSubtask(2, 1)
caldavDao.insert(newCaldavCalendar(with(UUID, "1")))
caldavDao.insert( caldavDao.insert(
listOf( listOf(
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")), with(TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")),
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 2L), with(TASK, 2L),
with(CALENDAR, "1"), with(CALENDAR, "1"),
with(REMOTE_PARENT, "a")))) with(REMOTE_PARENT, "a"))))
moveToCaldavList("2", 2) moveToCaldavList("2", 2)
@ -218,17 +230,19 @@ class TaskMoverTest : InjectingTestCase() {
@Test @Test
fun moveGoogleTaskToCaldav() = runBlocking { fun moveGoogleTaskToCaldav() = runBlocking {
createTasks(1) createTasks(1)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
moveToCaldavList("2", 1) moveToCaldavList("2", 1)
assertEquals("2", caldavDao.getTask(1)!!.calendar) assertEquals("2", caldavDao.getTask(1)!!.calendar)
} }
@Test @Test
fun moveCaldavToGoogleTask() = runBlocking { fun moveCaldavToGoogleTask() = runBlocking {
setAccountType("account1", TYPE_CALDAV)
setAccountType("account2", TYPE_GOOGLE_TASKS)
createTasks(1) createTasks(1)
caldavDao.insert(newCaldavTask(with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1"))) caldavDao.insert(newCaldavTask(with(TASK, 1L), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1) moveToGoogleTasks("2", 1)
assertEquals("2", googleTaskDao.getByTaskId(1L)!!.calendar) assertEquals("2", googleTaskDao.getByTaskId(1L)?.calendar)
} }
@Test @Test
@ -237,14 +251,15 @@ class TaskMoverTest : InjectingTestCase() {
createSubtask(2, 1) createSubtask(2, 1)
createSubtask(3, 2) createSubtask(3, 2)
moveToCaldavList("1", 1) moveToCaldavList("1", 1)
assertEquals("1", caldavDao.getTask(3)!!.calendar) assertEquals("1", caldavDao.getTask(3)?.calendar)
assertEquals(2, taskDao.fetch(3)!!.parent) assertEquals(2L, taskDao.fetch(3)?.parent)
} }
@Test @Test
fun moveToSameGoogleTaskListIsNoop() = runBlocking { fun moveToSameGoogleTaskListIsNoop() = runBlocking {
setAccountType("account1", TYPE_GOOGLE_TASKS)
createTasks(1) createTasks(1)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
moveToGoogleTasks("1", 1) moveToGoogleTasks("1", 1)
assertTrue(googleTaskDao.getDeletedByTaskId(1).isEmpty()) assertTrue(googleTaskDao.getDeletedByTaskId(1).isEmpty())
assertEquals(1, googleTaskDao.getAllByTaskId(1).size.toLong()) assertEquals(1, googleTaskDao.getAllByTaskId(1).size.toLong())
@ -253,7 +268,7 @@ class TaskMoverTest : InjectingTestCase() {
@Test @Test
fun moveToSameCaldavListIsNoop() = runBlocking { fun moveToSameCaldavListIsNoop() = runBlocking {
createTasks(1) createTasks(1)
caldavDao.insert(newCaldavTask(with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1"))) caldavDao.insert(newCaldavTask(with(TASK, 1L), with(CALENDAR, "1")))
moveToCaldavList("1", 1) moveToCaldavList("1", 1)
assertTrue(caldavDao.getMoved("1").isEmpty()) assertTrue(caldavDao.getMoved("1").isEmpty())
assertEquals(1, caldavDao.getTasks(1).size.toLong()) assertEquals(1, caldavDao.getTasks(1).size.toLong())
@ -261,9 +276,10 @@ class TaskMoverTest : InjectingTestCase() {
@Test @Test
fun dontDuplicateWhenParentAndChildGoogleTaskMoved() = runBlocking { fun dontDuplicateWhenParentAndChildGoogleTaskMoved() = runBlocking {
createTasks(1, 2) createTasks(1)
googleTaskDao.insert(newGoogleTask(with(TASK, 1), with(LIST, "1"))) createSubtask(2, 1)
googleTaskDao.insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(PARENT, 1L))) googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
googleTaskDao.insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1, 2) moveToGoogleTasks("2", 1, 2)
assertEquals(1, googleTaskDao.getAllByTaskId(2).filter { it.deleted == 0L }.size) assertEquals(1, googleTaskDao.getAllByTaskId(2).filter { it.deleted == 0L }.size)
} }
@ -272,13 +288,12 @@ class TaskMoverTest : InjectingTestCase() {
fun dontDuplicateWhenParentAndChildCaldavMoved() = runBlocking { fun dontDuplicateWhenParentAndChildCaldavMoved() = runBlocking {
createTasks(1) createTasks(1)
createSubtask(2, 1) createSubtask(2, 1)
caldavDao.insert(newCaldavCalendar(with(UUID, "1")))
caldavDao.insert( caldavDao.insert(
listOf( listOf(
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")), with(TASK, 1L), with(CALENDAR, "1"), with(REMOTE_ID, "a")),
newCaldavTask( newCaldavTask(
with(CaldavTaskMaker.TASK, 2L), with(TASK, 2L),
with(CALENDAR, "1"), with(CALENDAR, "1"),
with(REMOTE_PARENT, "a")))) with(REMOTE_PARENT, "a"))))
moveToCaldavList("2", 1, 2) moveToCaldavList("2", 1, 2)
@ -292,14 +307,18 @@ class TaskMoverTest : InjectingTestCase() {
} }
private suspend fun createSubtask(id: Long, parent: Long) { private suspend fun createSubtask(id: Long, parent: Long) {
taskDao.createNew(newTask(with(ID, id), with(TaskMaker.PARENT, parent))) taskDao.createNew(newTask(with(ID, id), with(PARENT, parent)))
} }
private suspend fun moveToGoogleTasks(list: String, vararg tasks: Long) { private suspend fun moveToGoogleTasks(list: String, vararg tasks: Long) {
taskMover.move(tasks.toList(), GtasksFilter(newGtaskList(with(GtaskListMaker.REMOTE_ID, list)))) taskMover.move(tasks.toList(), GtasksFilter(newCaldavCalendar(with(CaldavCalendarMaker.UUID, list))))
} }
private suspend fun moveToCaldavList(calendar: String, vararg tasks: Long) { private suspend fun moveToCaldavList(calendar: String, vararg tasks: Long) {
taskMover.move(tasks.toList(), CaldavFilter(CaldavCalendar(name = "", uuid = calendar))) taskMover.move(tasks.toList(), CaldavFilter(CaldavCalendar(name = "", uuid = calendar)))
} }
private suspend fun setAccountType(account: String, type: Int) {
caldavDao.insert(newCaldavAccount(with(CaldavAccountMaker.UUID, account), with(ACCOUNT_TYPE, type)))
}
} }

@ -105,7 +105,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
caldavDao.shiftDown("calendar", 0, created.toAppleEpoch()) caldavDao.shiftDown("calendar", 0, created.toAppleEpoch())
assertNull(caldavDao.getTasks(tasks[0].id)[0].order) assertNull(taskDao.fetch(tasks[0].id)!!.order)
} }
@Test @Test
@ -116,7 +116,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
caldavDao.shiftDown("calendar", 0, created.toAppleEpoch()) caldavDao.shiftDown("calendar", 0, created.toAppleEpoch())
assertNull(caldavDao.getTasks(tasks[0].id)[0].order) assertNull(taskDao.fetch(tasks[0].id)!!.order)
} }
@Test @Test
@ -134,10 +134,11 @@ class CaldavDaoShiftTests : InjectingTestCase() {
} }
private suspend fun checkOrder(dateTime: DateTime?, task: TaskContainer) { private suspend fun checkOrder(dateTime: DateTime?, task: TaskContainer) {
val order = taskDao.fetch(task.id)!!.order
if (dateTime == null) { if (dateTime == null) {
assertNull(caldavDao.getTask(task.id)!!.order) assertNull(order)
} else { } else {
assertEquals(dateTime.toAppleEpoch(), caldavDao.getTask(task.id)!!.order) assertEquals(dateTime.toAppleEpoch(), order)
} }
} }
@ -153,14 +154,6 @@ class CaldavDaoShiftTests : InjectingTestCase() {
caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.parent) caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.parent)
} }
caldavTask.id = caldavDao.insert(caldavTask) caldavTask.id = caldavDao.insert(caldavTask)
t.caldavTask = caldavTask.toSubset() t.caldavTask = caldavTask
}
private fun CaldavTask.toSubset(): SubsetCaldav {
val result = SubsetCaldav()
result.cd_id = id
result.cd_calendar = calendar
result.cd_remote_parent = remoteParent
return result
} }
} }

@ -99,7 +99,7 @@ class CaldavDaoTests : InjectingTestCase() {
private suspend fun checkOrder(dateTime: DateTime, task: Long) = checkOrder(dateTime.toAppleEpoch(), task) private suspend fun checkOrder(dateTime: DateTime, task: Long) = checkOrder(dateTime.toAppleEpoch(), task)
private suspend fun checkOrder(order: Long?, task: Long) { private suspend fun checkOrder(order: Long?, task: Long) {
val sortOrder = caldavDao.getTask(task)!!.order val sortOrder = taskDao.fetch(task)!!.order
if (order == null) { if (order == null) {
assertNull(sortOrder) assertNull(sortOrder)
} else { } else {

@ -9,15 +9,17 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.tasks.data.CaldavAccount.Companion.TYPE_GOOGLE_TASKS
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.makers.GoogleTaskMaker.LIST import org.tasks.makers.CaldavAccountMaker.ACCOUNT_TYPE
import org.tasks.makers.GoogleTaskMaker.PARENT import org.tasks.makers.CaldavAccountMaker.newCaldavAccount
import org.tasks.makers.GoogleTaskMaker.REMOTE_ID import org.tasks.makers.CaldavCalendarMaker.newCaldavCalendar
import org.tasks.makers.GoogleTaskMaker.REMOTE_PARENT import org.tasks.makers.CaldavTaskMaker.CALENDAR
import org.tasks.makers.GoogleTaskMaker.TASK import org.tasks.makers.CaldavTaskMaker.REMOTE_ID
import org.tasks.makers.GoogleTaskMaker.newGoogleTask import org.tasks.makers.CaldavTaskMaker.REMOTE_PARENT
import org.tasks.makers.GtaskListMaker.newGtaskList import org.tasks.makers.CaldavTaskMaker.TASK
import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.TaskMaker.newTask import org.tasks.makers.TaskMaker.newTask
import javax.inject.Inject import javax.inject.Inject
@ -27,133 +29,135 @@ class GoogleTaskDaoTests : InjectingTestCase() {
@Inject lateinit var googleTaskListDao: GoogleTaskListDao @Inject lateinit var googleTaskListDao: GoogleTaskListDao
@Inject lateinit var googleTaskDao: GoogleTaskDao @Inject lateinit var googleTaskDao: GoogleTaskDao
@Inject lateinit var taskDao: TaskDao @Inject lateinit var taskDao: TaskDao
@Inject lateinit var caldavDao: CaldavDao
@Before @Before
override fun setUp() { override fun setUp() {
super.setUp() super.setUp()
runBlocking { runBlocking {
googleTaskListDao.insert(newGtaskList()) caldavDao.insert(newCaldavAccount(with(ACCOUNT_TYPE, TYPE_GOOGLE_TASKS)))
caldavDao.insert(newCaldavCalendar())
} }
} }
@Test @Test
fun insertAtTopOfEmptyList() = runBlocking { fun insertAtTopOfEmptyList() = runBlocking {
insertTop(newGoogleTask(with(REMOTE_ID, "1234"))) insertTop(newCaldavTask(with(REMOTE_ID, "1234")))
val tasks = googleTaskDao.getByLocalOrder("1") val tasks = googleTaskDao.getByLocalOrder("calendar")
assertEquals(1, tasks.size.toLong()) assertEquals(1, tasks.size.toLong())
val task = tasks[0] val task = tasks[0]
assertEquals("1234", task.remoteId) assertEquals("1234", googleTaskDao.getByTaskId(task.id)?.remoteId)
assertEquals(0, task.order) assertEquals(0L, task.order)
} }
@Test @Test
fun insertAtBottomOfEmptyList() = runBlocking { fun insertAtBottomOfEmptyList() = runBlocking {
insertBottom(newGoogleTask(with(REMOTE_ID, "1234"))) insertBottom(newCaldavTask(with(REMOTE_ID, "1234")))
val tasks = googleTaskDao.getByLocalOrder("1") val tasks = googleTaskDao.getByLocalOrder("calendar")
assertEquals(1, tasks.size.toLong()) assertEquals(1, tasks.size.toLong())
val task = tasks[0] val task = tasks[0]
assertEquals("1234", task.remoteId) assertEquals("1234", googleTaskDao.getByTaskId(task.id)?.remoteId)
assertEquals(0, task.order) assertEquals(0L, task.order)
} }
@Test @Test
fun getPreviousIsNullForTopTask() = runBlocking { fun getPreviousIsNullForTopTask() = runBlocking {
insert(newGoogleTask()) insert(newCaldavTask())
assertNull(googleTaskDao.getPrevious("1", 0, 0)) assertNull(googleTaskDao.getPrevious("1", 0, 0))
} }
@Test @Test
fun getPrevious() = runBlocking { fun getPrevious() = runBlocking {
insertTop(newGoogleTask()) insertTop(newCaldavTask())
insertTop(newGoogleTask(with(REMOTE_ID, "1234"))) insertTop(newCaldavTask(with(REMOTE_ID, "1234")))
assertEquals("1234", googleTaskDao.getPrevious("1", 0, 1)) assertEquals("1234", googleTaskDao.getPrevious("calendar", 0, 1))
} }
@Test @Test
fun insertAtTopOfList() = runBlocking { fun insertAtTopOfList() = runBlocking {
insertTop(newGoogleTask(with(REMOTE_ID, "1234"))) insertTop(newCaldavTask(with(REMOTE_ID, "1234")))
insertTop(newGoogleTask(with(REMOTE_ID, "5678"))) insertTop(newCaldavTask(with(REMOTE_ID, "5678")))
val tasks = googleTaskDao.getByLocalOrder("1") val tasks = googleTaskDao.getByLocalOrder("calendar")
assertEquals(2, tasks.size.toLong()) assertEquals(2, tasks.size.toLong())
val top = tasks[0] val top = tasks[0]
assertEquals("5678", top.remoteId) assertEquals("5678", googleTaskDao.getByTaskId(top.id)?.remoteId)
assertEquals(0, top.order) assertEquals(0L, top.order)
} }
@Test @Test
fun insertAtTopOfListShiftsExisting() = runBlocking { fun insertAtTopOfListShiftsExisting() = runBlocking {
insertTop(newGoogleTask(with(REMOTE_ID, "1234"))) insertTop(newCaldavTask(with(REMOTE_ID, "1234")))
insertTop(newGoogleTask(with(REMOTE_ID, "5678"))) insertTop(newCaldavTask(with(REMOTE_ID, "5678")))
val tasks = googleTaskDao.getByLocalOrder("1") val tasks = googleTaskDao.getByLocalOrder("calendar")
assertEquals(2, tasks.size.toLong()) assertEquals(2, tasks.size.toLong())
val bottom = tasks[1] val bottom = tasks[1]
assertEquals("1234", bottom.remoteId) assertEquals("1234", googleTaskDao.getByTaskId(bottom.id)?.remoteId)
assertEquals(1, bottom.order) assertEquals(1L, bottom.order)
} }
@Test @Test
fun getTaskFromRemoteId() = runBlocking { fun getTaskFromRemoteId() = runBlocking {
insert(newGoogleTask(with(REMOTE_ID, "1234"))) insert(newCaldavTask(with(REMOTE_ID, "1234")))
assertEquals(1L, googleTaskDao.getTask("1234")) assertEquals(1L, googleTaskDao.getTask("1234"))
} }
@Test @Test
fun getRemoteIdForTask() = runBlocking { fun getRemoteIdForTask() = runBlocking {
insert(newGoogleTask(with(REMOTE_ID, "1234"))) insert(newCaldavTask(with(REMOTE_ID, "1234")))
assertEquals("1234", googleTaskDao.getRemoteId(1L)) assertEquals("1234", googleTaskDao.getRemoteId(1L))
} }
@Test @Test
fun moveDownInList() = runBlocking { fun moveDownInList() = runBlocking {
insert(newGoogleTask(with(REMOTE_ID, "1"))) insert(newCaldavTask(with(REMOTE_ID, "1")))
insert(newGoogleTask(with(REMOTE_ID, "2"))) insert(newCaldavTask(with(REMOTE_ID, "2")))
insert(newGoogleTask(with(REMOTE_ID, "3"))) insert(newCaldavTask(with(REMOTE_ID, "3")))
val two = getByRemoteId("2") val two = getByRemoteId("2")
googleTaskDao.move(two, 0, 0) googleTaskDao.move(taskDao.fetch(two.task)!!, "calendar", 0, 0)
assertEquals(0, googleTaskDao.getByRemoteId("2")!!.order) assertEquals(0L, getOrder("2"))
assertEquals(1, googleTaskDao.getByRemoteId("1")!!.order) assertEquals(1L, getOrder("1"))
assertEquals(2, googleTaskDao.getByRemoteId("3")!!.order) assertEquals(2L, getOrder("3"))
} }
@Test @Test
fun moveUpInList() = runBlocking { fun moveUpInList() = runBlocking {
insert(newGoogleTask(with(REMOTE_ID, "1"))) insert(newCaldavTask(with(REMOTE_ID, "1")))
insert(newGoogleTask(with(REMOTE_ID, "2"))) insert(newCaldavTask(with(REMOTE_ID, "2")))
insert(newGoogleTask(with(REMOTE_ID, "3"))) insert(newCaldavTask(with(REMOTE_ID, "3")))
val one = getByRemoteId("1") val one = getByRemoteId("1")
googleTaskDao.move(one, 0, 1) googleTaskDao.move(taskDao.fetch(one.task)!!, "calendar", 0, 1)
assertEquals(0, googleTaskDao.getByRemoteId("2")!!.order) assertEquals(0L, getOrder("2"))
assertEquals(1, googleTaskDao.getByRemoteId("1")!!.order) assertEquals(1L, getOrder("1"))
assertEquals(2, googleTaskDao.getByRemoteId("3")!!.order) assertEquals(2L, getOrder("3"))
} }
@Test @Test
fun moveToTop() = runBlocking { fun moveToTop() = runBlocking {
insert(newGoogleTask(with(REMOTE_ID, "1"))) insert(newCaldavTask(with(REMOTE_ID, "1")))
insert(newGoogleTask(with(REMOTE_ID, "2"))) insert(newCaldavTask(with(REMOTE_ID, "2")))
insert(newGoogleTask(with(REMOTE_ID, "3"))) insert(newCaldavTask(with(REMOTE_ID, "3")))
val three = getByRemoteId("3") val three = getByRemoteId("3")
googleTaskDao.move(three, 0, 0) googleTaskDao.move(taskDao.fetch(three.task)!!, "calendar", 0, 0)
assertEquals(0, googleTaskDao.getByRemoteId("3")!!.order) assertEquals(0L, getOrder("3"))
assertEquals(1, googleTaskDao.getByRemoteId("1")!!.order) assertEquals(1L, getOrder("1"))
assertEquals(2, googleTaskDao.getByRemoteId("2")!!.order) assertEquals(2L, getOrder("2"))
} }
@Test @Test
fun moveToBottom() = runBlocking { fun moveToBottom() = runBlocking {
insert(newGoogleTask(with(REMOTE_ID, "1"))) insert(newCaldavTask(with(REMOTE_ID, "1")))
insert(newGoogleTask(with(REMOTE_ID, "2"))) insert(newCaldavTask(with(REMOTE_ID, "2")))
insert(newGoogleTask(with(REMOTE_ID, "3"))) insert(newCaldavTask(with(REMOTE_ID, "3")))
val one = getByRemoteId("1") val one = getByRemoteId("1")
googleTaskDao.move(one, 0, 2) googleTaskDao.move(taskDao.fetch(one.task)!!, "calendar", 0, 2)
assertEquals(0, googleTaskDao.getByRemoteId("2")!!.order) assertEquals(0L, getOrder("2"))
assertEquals(1, googleTaskDao.getByRemoteId("3")!!.order) assertEquals(1L, getOrder("3"))
assertEquals(2, googleTaskDao.getByRemoteId("1")!!.order) assertEquals(2L, getOrder("1"))
} }
@Test @Test
fun dontAllowEmptyParent() = runBlocking { fun dontAllowEmptyParent() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "1234"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "1234")))
googleTaskDao.updatePosition("1234", "", "0") googleTaskDao.updatePosition("1234", "", "0")
@ -162,7 +166,7 @@ class GoogleTaskDaoTests : InjectingTestCase() {
@Test @Test
fun updatePositionWithNullParent() = runBlocking { fun updatePositionWithNullParent() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "1234"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "1234")))
googleTaskDao.updatePosition("1234", null, "0") googleTaskDao.updatePosition("1234", null, "0")
@ -171,7 +175,7 @@ class GoogleTaskDaoTests : InjectingTestCase() {
@Test @Test
fun updatePosition() = runBlocking { fun updatePosition() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "1234"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "1234")))
googleTaskDao.updatePosition("1234", "abcd", "0") googleTaskDao.updatePosition("1234", "abcd", "0")
@ -180,86 +184,84 @@ class GoogleTaskDaoTests : InjectingTestCase() {
@Test @Test
fun updateParents() = runBlocking { fun updateParents() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "123"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "123")))
insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(REMOTE_PARENT, "123"))) insert(newCaldavTask(with(TASK, 2), with(REMOTE_PARENT, "123")))
googleTaskDao.updateParents() caldavDao.updateParents()
assertEquals(1, googleTaskDao.getByTaskId(2)!!.parent) assertEquals(1, taskDao.fetch(2)!!.parent)
} }
@Test @Test
fun updateParentsByList() = runBlocking { fun updateParentsByList() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "123"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "123")))
insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(REMOTE_PARENT, "123"))) insert(newCaldavTask(with(TASK, 2), with(REMOTE_PARENT, "123")))
googleTaskDao.updateParents("1") caldavDao.updateParents("calendar")
assertEquals(1, googleTaskDao.getByTaskId(2)!!.parent) assertEquals(1, taskDao.fetch(2)!!.parent)
} }
@Test @Test
fun updateParentsMustMatchList() = runBlocking { fun updateParentsMustMatchList() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "123"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "123")))
insert(newGoogleTask(with(TASK, 2), with(LIST, "2"), with(REMOTE_PARENT, "123"))) insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "2"), with(REMOTE_PARENT, "123")))
googleTaskDao.updateParents() caldavDao.updateParents()
assertEquals(0, googleTaskDao.getByTaskId(2)!!.parent) assertEquals(0, taskDao.fetch(2)!!.parent)
} }
@Test @Test
fun updateParentsByListMustMatchList() = runBlocking { fun updateParentsByListMustMatchList() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, "123"))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "123")))
insert(newGoogleTask(with(TASK, 2), with(LIST, "2"), with(REMOTE_PARENT, "123"))) insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "2"), with(REMOTE_PARENT, "123")))
googleTaskDao.updateParents("2") caldavDao.updateParents("2")
assertEquals(0, googleTaskDao.getByTaskId(2)!!.parent) assertEquals(0, taskDao.fetch(2)!!.parent)
} }
@Test @Test
fun ignoreEmptyStringWhenUpdatingParents() = runBlocking { fun ignoreEmptyStringWhenUpdatingParents() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, ""))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "")))
insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(REMOTE_ID, ""), with(REMOTE_PARENT, ""))) insert(newCaldavTask(with(TASK, 2), with(REMOTE_ID, ""), with(REMOTE_PARENT, "")))
googleTaskDao.updateParents() caldavDao.updateParents()
assertEquals(0, googleTaskDao.getByTaskId(2)!!.parent) assertEquals(0, taskDao.fetch(2)!!.parent)
} }
@Test @Test
fun ignoreEmptyStringWhenUpdatingParentsForList() = runBlocking { fun ignoreEmptyStringWhenUpdatingParentsForList() = runBlocking {
insert(newGoogleTask(with(TASK, 1), with(LIST, "1"), with(REMOTE_ID, ""))) insert(newCaldavTask(with(TASK, 1), with(REMOTE_ID, "")))
insert(newGoogleTask(with(TASK, 2), with(LIST, "1"), with(REMOTE_ID, ""), with(REMOTE_PARENT, ""))) insert(newCaldavTask(with(TASK, 2), with(REMOTE_ID, ""), with(REMOTE_PARENT, "")))
googleTaskDao.updateParents("1") caldavDao.updateParents("1")
assertEquals(0, googleTaskDao.getByTaskId(2)!!.parent) assertEquals(0, taskDao.fetch(2)!!.parent)
} }
private suspend fun insertTop(googleTask: GoogleTask) { private suspend fun getOrder(remoteId: String): Long? {
return taskDao.fetch(googleTaskDao.getByRemoteId(remoteId)!!.task)?.order
}
private suspend fun insertTop(googleTask: CaldavTask) {
insert(googleTask, true) insert(googleTask, true)
} }
private suspend fun insertBottom(googleTask: GoogleTask) { private suspend fun insertBottom(googleTask: CaldavTask) {
insert(googleTask, false) insert(googleTask, false)
} }
private suspend fun insert(googleTask: GoogleTask, top: Boolean = false) { private suspend fun insert(googleTask: CaldavTask, top: Boolean = false) {
val task = newTask() val task = newTask()
taskDao.createNew(task) taskDao.createNew(task)
googleTask.task = task.id googleTask.task = task.id
googleTaskDao.insertAndShift(googleTask, top) googleTaskDao.insertAndShift(task, googleTask, top)
} }
private suspend fun getByRemoteId(remoteId: String): SubsetGoogleTask { private suspend fun getByRemoteId(remoteId: String): CaldavTask {
val googleTask = googleTaskDao.getByRemoteId(remoteId)!! return googleTaskDao.getByRemoteId(remoteId)!!
val result = SubsetGoogleTask()
result.gt_id = googleTask.id
result.gt_list_id = googleTask.calendar
result.gt_order = googleTask.order
result.gt_parent = googleTask.parent
return result
} }
} }

@ -1,6 +1,5 @@
package org.tasks.data package org.tasks.data
import com.natpryce.makeiteasy.MakeItEasy.with
import dagger.hilt.android.testing.HiltAndroidTest import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules import dagger.hilt.android.testing.UninstallModules
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -8,9 +7,6 @@ import org.junit.Assert.*
import org.junit.Test import org.junit.Test
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.makers.GoogleTaskListMaker.ACCOUNT
import org.tasks.makers.GoogleTaskListMaker.REMOTE_ID
import org.tasks.makers.GoogleTaskListMaker.newGoogleTaskList
import javax.inject.Inject import javax.inject.Inject
@UninstallModules(ProductionModule::class) @UninstallModules(ProductionModule::class)
@ -29,28 +25,4 @@ class GoogleTaskListDaoTest : InjectingTestCase() {
assertTrue(googleTaskListDao.getGoogleTaskFilters(account.username!!).isEmpty()) assertTrue(googleTaskListDao.getGoogleTaskFilters(account.username!!).isEmpty())
} }
@Test
fun findListWithNullAccount() = runBlocking {
val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, null as String?))
list.id = googleTaskListDao.insert(list)
assertEquals(list, googleTaskListDao.findExistingList("1234"))
}
@Test
fun findListWithEmptyAccount() = runBlocking {
val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, ""))
list.id = googleTaskListDao.insert(list)
assertEquals(list, googleTaskListDao.findExistingList("1234"))
}
@Test
fun ignoreListWithAccount() = runBlocking {
val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, "user@gmail.com"))
googleTaskListDao.insert(list)
assertNull(googleTaskListDao.findExistingList("1234"))
}
} }

@ -14,32 +14,39 @@ import org.junit.Test
import org.tasks.R import org.tasks.R
import org.tasks.injection.InjectingTestCase import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule import org.tasks.injection.ProductionModule
import org.tasks.makers.GoogleTaskListMaker.REMOTE_ID import org.tasks.makers.CaldavAccountMaker.newCaldavAccount
import org.tasks.makers.GoogleTaskListMaker.newGoogleTaskList import org.tasks.makers.CaldavCalendarMaker.UUID
import org.tasks.makers.GoogleTaskMaker.LIST import org.tasks.makers.CaldavCalendarMaker.newCaldavCalendar
import org.tasks.makers.GoogleTaskMaker.ORDER import org.tasks.makers.CaldavTaskMaker.CALENDAR
import org.tasks.makers.GoogleTaskMaker.PARENT import org.tasks.makers.CaldavTaskMaker.TASK
import org.tasks.makers.GoogleTaskMaker.TASK import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.GoogleTaskMaker.newGoogleTask
import org.tasks.makers.TaskMaker import org.tasks.makers.TaskMaker
import org.tasks.makers.TaskMaker.ID import org.tasks.makers.TaskMaker.ID
import org.tasks.makers.TaskMaker.UUID import org.tasks.makers.TaskMaker.ORDER
import org.tasks.makers.TaskMaker.PARENT
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import javax.inject.Inject import javax.inject.Inject
@UninstallModules(ProductionModule::class) @UninstallModules(ProductionModule::class)
@HiltAndroidTest @HiltAndroidTest
class ManualGoogleTaskQueryTest : InjectingTestCase() { class ManualGoogleTaskQueryTest : InjectingTestCase() {
@Inject lateinit var caldavDao: CaldavDao
@Inject lateinit var googleTaskDao: GoogleTaskDao @Inject lateinit var googleTaskDao: GoogleTaskDao
@Inject lateinit var taskDao: TaskDao @Inject lateinit var taskDao: TaskDao
@Inject lateinit var preferences: Preferences @Inject lateinit var preferences: Preferences
private val filter: GtasksFilter = GtasksFilter(newGoogleTaskList(with(REMOTE_ID, "1234"))) private lateinit var filter: GtasksFilter
@Before @Before
override fun setUp() { override fun setUp() {
super.setUp() super.setUp()
preferences.clear() preferences.clear()
preferences.setBoolean(R.string.p_manual_sort, true) preferences.setBoolean(R.string.p_manual_sort, true)
val calendar = newCaldavCalendar(with(UUID, "1234"))
runBlocking {
caldavDao.insert(newCaldavAccount())
caldavDao.insert(calendar)
}
filter = GtasksFilter(calendar)
} }
@Test @Test
@ -100,8 +107,13 @@ class ManualGoogleTaskQueryTest : InjectingTestCase() {
} }
private suspend fun newTask(id: Long, order: Long, parent: Long = 0) { private suspend fun newTask(id: Long, order: Long, parent: Long = 0) {
taskDao.insert(TaskMaker.newTask(with(ID, id), with(UUID, UUIDHelper.newUUID()))) taskDao.insert(TaskMaker.newTask(
googleTaskDao.insert(newGoogleTask(with(LIST, filter.list.uuid), with(TASK, id), with(PARENT, parent), with(ORDER, order))) with(ID, id),
with(TaskMaker.UUID, UUIDHelper.newUUID()),
with(ORDER, order),
with(PARENT, parent),
))
googleTaskDao.insert(newCaldavTask(with(CALENDAR, filter.list.uuid), with(TASK, id)))
} }
private suspend fun query(): List<TaskContainer> = taskDao.fetchTasks { private suspend fun query(): List<TaskContainer> = taskDao.fetchTasks {

@ -22,7 +22,6 @@ import org.tasks.injection.ProductionModule
import org.tasks.makers.CaldavTaskMaker import org.tasks.makers.CaldavTaskMaker
import org.tasks.makers.CaldavTaskMaker.CALENDAR import org.tasks.makers.CaldavTaskMaker.CALENDAR
import org.tasks.makers.CaldavTaskMaker.REMOTE_ID import org.tasks.makers.CaldavTaskMaker.REMOTE_ID
import org.tasks.makers.CaldavTaskMaker.REMOTE_ORDER
import org.tasks.makers.CaldavTaskMaker.newCaldavTask import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.TagDataMaker.NAME import org.tasks.makers.TagDataMaker.NAME
import org.tasks.makers.TagDataMaker.newTagData import org.tasks.makers.TagDataMaker.newTagData
@ -31,6 +30,7 @@ import org.tasks.makers.TagMaker.TASK
import org.tasks.makers.TagMaker.newTag import org.tasks.makers.TagMaker.newTag
import org.tasks.makers.TaskMaker import org.tasks.makers.TaskMaker
import org.tasks.makers.TaskMaker.COLLAPSED import org.tasks.makers.TaskMaker.COLLAPSED
import org.tasks.makers.TaskMaker.ORDER
import org.tasks.makers.TaskMaker.newTask import org.tasks.makers.TaskMaker.newTask
import org.tasks.time.DateTime import org.tasks.time.DateTime
import java.util.* import java.util.*
@ -129,20 +129,18 @@ class OpenTasksPropertiesTests : OpenTasksTest() {
synchronizer.sync() synchronizer.sync()
assertEquals( val task = caldavDao.getTaskByRemoteId(list.uuid!!, "3076145036806467726")!!.task
633734058L, assertEquals(633734058L, taskDao.fetch(task)?.order)
caldavDao.getTaskByRemoteId(list.uuid!!, "3076145036806467726")?.order
)
} }
@Test @Test
fun pushOrder() = runBlocking { fun pushOrder() = runBlocking {
val (listId, list) = openTaskDao.insertList() val (listId, list) = openTaskDao.insertList()
val task = newTask().apply { taskDao.createNew(this) } val task = newTask(with(ORDER, 5678L))
taskDao.createNew(task)
caldavDao.insert(newCaldavTask( caldavDao.insert(newCaldavTask(
with(CALENDAR, list.uuid), with(CALENDAR, list.uuid),
with(REMOTE_ID, "1234"), with(REMOTE_ID, "1234"),
with(REMOTE_ORDER, 5678L),
with(CaldavTaskMaker.TASK, task.id) with(CaldavTaskMaker.TASK, task.id)
)) ))

@ -238,7 +238,6 @@ class TasksJsonImporter @Inject constructor(
?.let { taskAttachmentDao.insert(it) } ?.let { taskAttachmentDao.insert(it) }
backup.caldavTasks?.forEach { caldavTask -> backup.caldavTasks?.forEach { caldavTask ->
caldavTask.task = taskId caldavTask.task = taskId
caldavTask.order?.let { task.order = it }
caldavDao.insert(caldavTask) caldavDao.insert(caldavTask)
} }
backup.vtodo?.let { backup.vtodo?.let {

@ -105,7 +105,9 @@ ORDER BY CASE cda_account_type
?.takeIf { task.creationDate.toAppleEpoch() <= it } ?.takeIf { task.creationDate.toAppleEpoch() <= it }
?.plus(1) ?.plus(1)
} }
return insert(caldavTask) val id = insert(caldavTask)
update(task)
return id
} }
@Query(""" @Query("""
@ -139,6 +141,9 @@ WHERE cd_calendar = :calendar
@Update @Update
abstract suspend fun update(caldavTask: CaldavTask) abstract suspend fun update(caldavTask: CaldavTask)
@Update
abstract suspend fun update(task: Task)
@Update @Update
abstract suspend fun updateTasks(tasks: Iterable<Task>) abstract suspend fun updateTasks(tasks: Iterable<Task>)
@ -266,7 +271,7 @@ FROM caldav_lists
tasks.hideUntil < :now AND tasks.hideUntil < :now AND
cd_deleted = 0 cd_deleted = 0
LEFT JOIN principal_access ON caldav_lists.cdl_id = principal_access.list LEFT JOIN principal_access ON caldav_lists.cdl_id = principal_access.list
INNER JOIN caldav_accounts ON caldav_accounts.cda_uuid = caldav_lists.cdl_account LEFT JOIN caldav_accounts ON caldav_accounts.cda_uuid = caldav_lists.cdl_account
WHERE caldav_lists.cdl_account = :uuid WHERE caldav_lists.cdl_account = :uuid
AND caldav_accounts.cda_account_type != $TYPE_GOOGLE_TASKS AND caldav_accounts.cda_account_type != $TYPE_GOOGLE_TASKS
GROUP BY caldav_lists.cdl_uuid GROUP BY caldav_lists.cdl_uuid
@ -278,7 +283,10 @@ GROUP BY caldav_lists.cdl_uuid
+ " INNER JOIN caldav_tasks ON caldav_tasks.cd_task = tasks._id" + " INNER JOIN caldav_tasks ON caldav_tasks.cd_task = tasks._id"
+ " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent" + " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent"
+ " AND p.cd_calendar = caldav_tasks.cd_calendar" + " AND p.cd_calendar = caldav_tasks.cd_calendar"
+ " AND p.cd_deleted = 0), 0)" + " AND p.cd_deleted = 0"
+ " AND caldav_tasks.cd_remote_parent IS NOT NULL"
+ " AND caldav_tasks.cd_remote_parent != ''"
+ "), 0)"
+ "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0)") + "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0)")
abstract suspend fun updateParents() abstract suspend fun updateParents()
@ -289,7 +297,10 @@ GROUP BY caldav_lists.cdl_uuid
+ " AND caldav_tasks.cd_calendar = :calendar" + " AND caldav_tasks.cd_calendar = :calendar"
+ " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent" + " WHERE p.cd_remote_id = caldav_tasks.cd_remote_parent"
+ " AND p.cd_calendar = caldav_tasks.cd_calendar" + " AND p.cd_calendar = caldav_tasks.cd_calendar"
+ " AND caldav_tasks.cd_deleted = 0), 0)" + " AND p.cd_deleted = 0"
+ " AND caldav_tasks.cd_remote_parent IS NOT NULL"
+ " AND caldav_tasks.cd_remote_parent != ''"
+ "), 0)"
+ "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0 AND cd_calendar = :calendar)") + "WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task WHERE cd_deleted = 0 AND cd_calendar = :calendar)")
abstract suspend fun updateParents(calendar: String) abstract suspend fun updateParents(calendar: String)

@ -54,11 +54,6 @@ class CaldavTask {
@ColumnInfo(name = "gt_remote_order") @ColumnInfo(name = "gt_remote_order")
var remoteOrder: Long = 0 var remoteOrder: Long = 0
@Transient
@Ignore
@Deprecated("For importing old backup files")
var order: Long? = null
constructor() constructor()
@Ignore @Ignore

@ -16,9 +16,9 @@ object TaskListQuery {
Task.ID.eq(field("${TaskListFragment.CALDAV_METADATA_JOIN}.cd_task")), Task.ID.eq(field("${TaskListFragment.CALDAV_METADATA_JOIN}.cd_task")),
field("${TaskListFragment.CALDAV_METADATA_JOIN}.cd_deleted").eq(0)) field("${TaskListFragment.CALDAV_METADATA_JOIN}.cd_deleted").eq(0))
val JOINS = """ val JOINS = """
${Join.inner(CaldavTask.TABLE.`as`(TaskListFragment.CALDAV_METADATA_JOIN), JOIN_CALDAV)} ${Join.left(CaldavTask.TABLE.`as`(TaskListFragment.CALDAV_METADATA_JOIN), JOIN_CALDAV)}
${Join.inner(CaldavCalendar.TABLE, field("${TaskListFragment.CALDAV_METADATA_JOIN}.cd_calendar").eq(CaldavCalendar.UUID))} ${Join.left(CaldavCalendar.TABLE, field("${TaskListFragment.CALDAV_METADATA_JOIN}.cd_calendar").eq(CaldavCalendar.UUID))}
${Join.inner(CaldavAccount.TABLE, CaldavCalendar.ACCOUNT.eq(CaldavAccount.UUID))} ${Join.left(CaldavAccount.TABLE, CaldavCalendar.ACCOUNT.eq(CaldavAccount.UUID))}
${Join.left(Geofence.TABLE, Geofence.TASK.eq(Task.ID))} ${Join.left(Geofence.TABLE, Geofence.TASK.eq(Task.ID))}
${Join.left(Place.TABLE, Place.UID.eq(Geofence.PLACE))} ${Join.left(Place.TABLE, Place.UID.eq(Geofence.PLACE))}
""".trimIndent() """.trimIndent()

@ -12,19 +12,18 @@ import net.fortuna.ical4j.model.property.Status
import org.junit.Assert.* import org.junit.Assert.*
import org.junit.Test import org.junit.Test
import org.tasks.date.DateTimeUtils.newDateTime import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.makers.CaldavTaskMaker.REMOTE_ORDER
import org.tasks.makers.CaldavTaskMaker.REMOTE_PARENT import org.tasks.makers.CaldavTaskMaker.REMOTE_PARENT
import org.tasks.makers.CaldavTaskMaker.newCaldavTask import org.tasks.makers.CaldavTaskMaker.newCaldavTask
import org.tasks.makers.TaskMaker import org.tasks.makers.TaskMaker
import org.tasks.makers.TaskMaker.COMPLETION_TIME import org.tasks.makers.TaskMaker.COMPLETION_TIME
import org.tasks.makers.TaskMaker.CREATION_TIME import org.tasks.makers.TaskMaker.CREATION_TIME
import org.tasks.makers.TaskMaker.newTask import org.tasks.makers.TaskMaker.newTask
import org.tasks.makers.iCalMaker
import org.tasks.makers.iCalMaker.COLLAPSED import org.tasks.makers.iCalMaker.COLLAPSED
import org.tasks.makers.iCalMaker.COMPLETED_AT import org.tasks.makers.iCalMaker.COMPLETED_AT
import org.tasks.makers.iCalMaker.CREATED_AT import org.tasks.makers.iCalMaker.CREATED_AT
import org.tasks.makers.iCalMaker.DESCRIPTION import org.tasks.makers.iCalMaker.DESCRIPTION
import org.tasks.makers.iCalMaker.DUE_DATE import org.tasks.makers.iCalMaker.DUE_DATE
import org.tasks.makers.iCalMaker.ORDER
import org.tasks.makers.iCalMaker.PARENT import org.tasks.makers.iCalMaker.PARENT
import org.tasks.makers.iCalMaker.PRIORITY import org.tasks.makers.iCalMaker.PRIORITY
import org.tasks.makers.iCalMaker.RRULE import org.tasks.makers.iCalMaker.RRULE
@ -567,9 +566,9 @@ class iCalendarMergeTest {
@Test @Test
fun remoteSetsOrder() = fun remoteSetsOrder() =
newCaldavTask() newTask()
.applyRemote( .applyRemote(
remote = newIcal(with(ORDER, 1234)), remote = newIcal(with(iCalMaker.ORDER, 1234)),
local = null local = null
) )
.let { .let {
@ -578,10 +577,10 @@ class iCalendarMergeTest {
@Test @Test
fun remoteRemovesOrder() = fun remoteRemovesOrder() =
newCaldavTask(with(REMOTE_ORDER, 1234)) newTask(with(TaskMaker.ORDER, 1234))
.applyRemote( .applyRemote(
remote = newIcal(), remote = newIcal(),
local = newIcal(with(ORDER, 1234)) local = newIcal(with(iCalMaker.ORDER, 1234))
) )
.let { .let {
assertNull(it.order) assertNull(it.order)
@ -589,10 +588,10 @@ class iCalendarMergeTest {
@Test @Test
fun localRemovesOrder() = fun localRemovesOrder() =
newCaldavTask() newTask()
.applyRemote( .applyRemote(
remote = newIcal(with(ORDER, 1234)), remote = newIcal(with(iCalMaker.ORDER, 1234)),
local = newIcal(with(ORDER, 1234)) local = newIcal(with(iCalMaker.ORDER, 1234))
) )
.let { .let {
assertNull(it.order) assertNull(it.order)
@ -600,10 +599,10 @@ class iCalendarMergeTest {
@Test @Test
fun localBeatsRemoteOrder() = fun localBeatsRemoteOrder() =
newCaldavTask(with(REMOTE_ORDER, 789)) newTask(with(TaskMaker.ORDER, 789L))
.applyRemote( .applyRemote(
remote = newIcal(with(ORDER, 456)), remote = newIcal(with(iCalMaker.ORDER, 456L)),
local = newIcal(with(ORDER, 123)) local = newIcal(with(iCalMaker.ORDER, 123))
) )
.let { .let {
assertEquals(789L, it.order) assertEquals(789L, it.order)

@ -0,0 +1,29 @@
package org.tasks.makers
import com.natpryce.makeiteasy.Instantiator
import com.natpryce.makeiteasy.Property
import com.natpryce.makeiteasy.Property.newProperty
import com.natpryce.makeiteasy.PropertyValue
import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavAccount.Companion.TYPE_CALDAV
import org.tasks.makers.Maker.make
object CaldavAccountMaker {
val ID: Property<CaldavAccount, Long> = newProperty()
val NAME: Property<CaldavAccount, String> = newProperty()
val UUID: Property<CaldavAccount, String> = newProperty()
val ACCOUNT_TYPE: Property<CaldavAccount, Int> = newProperty()
private val instantiator = Instantiator { lookup ->
CaldavAccount().apply {
id = lookup.valueOf(ID, 0L)
name = lookup.valueOf(NAME, null as String?)
uuid = lookup.valueOf(UUID, "account")
accountType = lookup.valueOf(ACCOUNT_TYPE, TYPE_CALDAV)
}
}
fun newCaldavAccount(vararg properties: PropertyValue<in CaldavAccount?, *>): CaldavAccount {
return make(instantiator, *properties)
}
}

@ -8,13 +8,17 @@ import org.tasks.data.CaldavCalendar
import org.tasks.makers.Maker.make import org.tasks.makers.Maker.make
object CaldavCalendarMaker { object CaldavCalendarMaker {
val ID: Property<CaldavCalendar, Long> = newProperty()
val ACCOUNT: Property<CaldavCalendar, String> = newProperty() val ACCOUNT: Property<CaldavCalendar, String> = newProperty()
val NAME: Property<CaldavCalendar, String> = newProperty()
val UUID: Property<CaldavCalendar, String> = newProperty() val UUID: Property<CaldavCalendar, String> = newProperty()
private val instantiator = Instantiator { lookup -> private val instantiator = Instantiator { lookup ->
CaldavCalendar( CaldavCalendar(
id = lookup.valueOf(ID, 0L),
name = lookup.valueOf(NAME, null as String?),
account = lookup.valueOf(ACCOUNT, "account"), account = lookup.valueOf(ACCOUNT, "account"),
uuid = lookup.valueOf(UUID, "uuid"), uuid = lookup.valueOf(UUID, "calendar"),
) )
} }

@ -12,15 +12,13 @@ object CaldavTaskMaker {
val TASK: Property<CaldavTask, Long> = newProperty() val TASK: Property<CaldavTask, Long> = newProperty()
val REMOTE_ID: Property<CaldavTask, String?> = newProperty() val REMOTE_ID: Property<CaldavTask, String?> = newProperty()
val REMOTE_PARENT: Property<CaldavTask, String?> = newProperty() val REMOTE_PARENT: Property<CaldavTask, String?> = newProperty()
val REMOTE_ORDER: Property<CaldavTask, Long?> = newProperty()
val ETAG: Property<CaldavTask, String?> = newProperty() val ETAG: Property<CaldavTask, String?> = newProperty()
val OBJECT: Property<CaldavTask, String?> = newProperty() val OBJECT: Property<CaldavTask, String?> = newProperty()
private val instantiator = Instantiator<CaldavTask> { private val instantiator = Instantiator {
val task = CaldavTask(it.valueOf(TASK, 1L), it.valueOf(CALENDAR, "calendar")) val task = CaldavTask(it.valueOf(TASK, 1L), it.valueOf(CALENDAR, "calendar"))
task.remoteId = it.valueOf(REMOTE_ID, task.remoteId) task.remoteId = it.valueOf(REMOTE_ID, task.remoteId)
task.remoteParent = it.valueOf(REMOTE_PARENT, null as String?) task.remoteParent = it.valueOf(REMOTE_PARENT, null as String?)
task.order = it.valueOf(REMOTE_ORDER, null as Long?)
task.etag = it.valueOf(ETAG, null as String?) task.etag = it.valueOf(ETAG, null as String?)
task.`object` = it.valueOf(OBJECT, task.remoteId?.let { id -> "$id.ics" }) task.`object` = it.valueOf(OBJECT, task.remoteId?.let { id -> "$id.ics" })
task task

@ -1,24 +0,0 @@
package org.tasks.makers
import com.natpryce.makeiteasy.Instantiator
import com.natpryce.makeiteasy.Property
import com.natpryce.makeiteasy.PropertyLookup
import com.natpryce.makeiteasy.PropertyValue
import org.tasks.data.GoogleTaskList
object GoogleTaskListMaker {
val REMOTE_ID: Property<GoogleTaskList, String> = Property.newProperty()
val ACCOUNT: Property<GoogleTaskList, String?> = Property.newProperty()
private val instantiator = Instantiator { lookup: PropertyLookup<GoogleTaskList> ->
val list = GoogleTaskList()
list.uuid = lookup.valueOf(REMOTE_ID, "1234")
list.account = lookup.valueOf(ACCOUNT, null as String?)
list.setColor(0)
list
}
fun newGoogleTaskList(vararg properties: PropertyValue<in GoogleTaskList?, *>): GoogleTaskList {
return Maker.make(instantiator, *properties)
}
}

@ -1,32 +0,0 @@
package org.tasks.makers
import com.natpryce.makeiteasy.Instantiator
import com.natpryce.makeiteasy.Property
import com.natpryce.makeiteasy.Property.newProperty
import com.natpryce.makeiteasy.PropertyValue
import com.todoroo.astrid.helper.UUIDHelper
import org.tasks.makers.Maker.make
object GoogleTaskMaker {
val LIST: Property<GoogleTask, String> = newProperty()
val ORDER: Property<GoogleTask, Long> = newProperty()
val REMOTE_ID: Property<GoogleTask, String> = newProperty()
val TASK: Property<GoogleTask, Long> = newProperty()
val PARENT: Property<GoogleTask, Long> = newProperty()
val REMOTE_PARENT: Property<GoogleTask, String?> = newProperty()
private val instantiator = Instantiator<GoogleTask> {
val task = GoogleTask()
task.calendar = it.valueOf(LIST, "1")
task.order = it.valueOf(ORDER, 0)
task.remoteId = it.valueOf(REMOTE_ID, UUIDHelper.newUUID())
task.task = it.valueOf(TASK, 1)
task.parent = it.valueOf(PARENT, 0L)
task.remoteParent = it.valueOf(REMOTE_PARENT, null as String?)
task
}
fun newGoogleTask(vararg properties: PropertyValue<in GoogleTask?, *>): GoogleTask {
return make(instantiator, *properties)
}
}

@ -1,36 +0,0 @@
package org.tasks.makers
import com.natpryce.makeiteasy.Instantiator
import com.natpryce.makeiteasy.Property
import com.natpryce.makeiteasy.Property.newProperty
import com.natpryce.makeiteasy.PropertyLookup
import com.natpryce.makeiteasy.PropertyValue
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
import org.tasks.data.GoogleTaskList
import org.tasks.makers.Maker.make
object GtaskListMaker {
val ID: Property<GoogleTaskList, Long> = newProperty()
val ACCOUNT: Property<GoogleTaskList, String> = newProperty()
val REMOTE_ID: Property<GoogleTaskList, String> = newProperty()
val LAST_SYNC: Property<GoogleTaskList, Long> = newProperty()
val NAME: Property<GoogleTaskList, String> = newProperty()
private val ORDER: Property<GoogleTaskList, Int> = newProperty()
private val COLOR: Property<GoogleTaskList, Int> = newProperty()
private val instantiator = Instantiator { lookup: PropertyLookup<GoogleTaskList> ->
val list = GoogleTaskList()
list.id = lookup.valueOf(ID, 0L)
list.account = lookup.valueOf(ACCOUNT, "account")
list.uuid = lookup.valueOf(REMOTE_ID, "1")
list.name = lookup.valueOf(NAME, "Default")
list.order = lookup.valueOf(ORDER, NO_ORDER)
list.lastSync = lookup.valueOf(LAST_SYNC, 0L)
list.setColor(lookup.valueOf(COLOR, 0))
list
}
fun newGtaskList(vararg properties: PropertyValue<in GoogleTaskList?, *>): GoogleTaskList {
return make(instantiator, *properties)
}
}

@ -34,6 +34,7 @@ object TaskMaker {
val UUID: Property<Task, String> = newProperty() val UUID: Property<Task, String> = newProperty()
val COLLAPSED: Property<Task, Boolean> = newProperty() val COLLAPSED: Property<Task, Boolean> = newProperty()
val DESCRIPTION: Property<Task, String?> = newProperty() val DESCRIPTION: Property<Task, String?> = newProperty()
val ORDER: Property<Task, Long> = newProperty()
private val instantiator = Instantiator { lookup: PropertyLookup<Task> -> private val instantiator = Instantiator { lookup: PropertyLookup<Task> ->
val task = Task() val task = Task()
@ -95,6 +96,7 @@ object TaskMaker {
task.creationDate = creationTime.millis task.creationDate = creationTime.millis
task.modificationDate = lookup.valueOf(MODIFICATION_TIME, creationTime).millis task.modificationDate = lookup.valueOf(MODIFICATION_TIME, creationTime).millis
task.parent = lookup.valueOf(PARENT, 0L) task.parent = lookup.valueOf(PARENT, 0L)
task.order = lookup.valueOf(ORDER, null as Long?)
task task
} }

Loading…
Cancel
Save