mirror of https://github.com/tasks/tasks
Remove AfterSaveWork
parent
457b89c092
commit
db889d233a
@ -1,50 +1,68 @@
|
||||
package com.todoroo.astrid.repeats
|
||||
|
||||
import com.natpryce.makeiteasy.MakeItEasy.with
|
||||
import com.todoroo.andlib.utility.DateUtilities.now
|
||||
import com.todoroo.astrid.data.Task
|
||||
import com.todoroo.astrid.service.TaskCompleter
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import dagger.hilt.android.testing.UninstallModules
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.tasks.data.TaskDao
|
||||
import org.tasks.injection.InjectingTestCase
|
||||
import org.tasks.injection.ProductionModule
|
||||
import org.tasks.makers.TaskMaker.COMPLETION_TIME
|
||||
import org.tasks.makers.TaskMaker.PARENT
|
||||
import org.tasks.makers.TaskMaker.RECUR
|
||||
import org.tasks.makers.TaskMaker.newTask
|
||||
import org.tasks.time.DateTime
|
||||
import javax.inject.Inject
|
||||
|
||||
@UninstallModules(ProductionModule::class)
|
||||
@HiltAndroidTest
|
||||
class RepeatWithSubtasksTests : InjectingTestCase() {
|
||||
@Inject lateinit var taskDao: TaskDao
|
||||
@Inject lateinit var repeat: RepeatTaskHelper
|
||||
@Inject lateinit var taskCompleter: TaskCompleter
|
||||
|
||||
@Test
|
||||
fun uncompleteGrandchildren() = runBlocking {
|
||||
val grandparent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY")))
|
||||
val parent = taskDao.createNew(newTask(with(PARENT, grandparent)))
|
||||
val child = taskDao.createNew(newTask(
|
||||
with(PARENT, parent),
|
||||
with(COMPLETION_TIME, DateTime())
|
||||
))
|
||||
val grandparent = taskDao.createNew(
|
||||
Task(
|
||||
recurrence = "RRULE:FREQ=DAILY"
|
||||
)
|
||||
)
|
||||
val parent = taskDao.createNew(
|
||||
Task(
|
||||
parent = grandparent
|
||||
)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = now(),
|
||||
)
|
||||
)
|
||||
|
||||
repeat.handleRepeat(taskDao.fetch(grandparent)!!)
|
||||
assertTrue(taskDao.fetch(child)!!.isCompleted)
|
||||
|
||||
taskCompleter.setComplete(grandparent)
|
||||
|
||||
assertFalse(taskDao.fetch(child)!!.isCompleted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun uncompleteGoogleTaskChildren() = runBlocking {
|
||||
val parent = taskDao.createNew(newTask(with(RECUR, "RRULE:FREQ=DAILY")))
|
||||
val child = taskDao.createNew(newTask(
|
||||
with(PARENT, parent),
|
||||
with(COMPLETION_TIME, DateTime())
|
||||
))
|
||||
val parent = taskDao.createNew(
|
||||
Task(
|
||||
recurrence = "RRULE:FREQ=DAILY"
|
||||
)
|
||||
)
|
||||
val child = taskDao.createNew(
|
||||
Task(
|
||||
parent = parent,
|
||||
completionDate = now(),
|
||||
)
|
||||
)
|
||||
|
||||
assertTrue(taskDao.fetch(child)!!.isCompleted)
|
||||
|
||||
repeat.handleRepeat(taskDao.fetch(parent)!!)
|
||||
taskCompleter.setComplete(parent)
|
||||
|
||||
assertFalse(taskDao.fetch(child)!!.isCompleted)
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
package org.tasks.jobs
|
||||
|
||||
import android.content.Context
|
||||
import androidx.hilt.work.HiltWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.todoroo.astrid.gcal.GCalHelper
|
||||
import com.todoroo.astrid.repeats.RepeatTaskHelper
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.data.CaldavDao
|
||||
import org.tasks.data.TaskDao
|
||||
import org.tasks.injection.BaseWorker
|
||||
|
||||
@HiltWorker
|
||||
class AfterSaveWork @AssistedInject constructor(
|
||||
@Assisted context: Context,
|
||||
@Assisted workerParams: WorkerParameters,
|
||||
firebase: Firebase,
|
||||
private val repeatTaskHelper: RepeatTaskHelper,
|
||||
private val taskDao: TaskDao,
|
||||
private val caldavDao: CaldavDao,
|
||||
private val gCalHelper: GCalHelper
|
||||
) : BaseWorker(context, workerParams, firebase) {
|
||||
|
||||
override suspend fun run(): Result {
|
||||
val taskId = inputData.getLong(EXTRA_ID, -1)
|
||||
val task = taskDao.fetch(taskId) ?: return Result.failure()
|
||||
if (inputData.getBoolean(EXTRA_SUPPRESS_COMPLETION_SNACKBAR, false)) {
|
||||
task.suppressRefresh()
|
||||
}
|
||||
gCalHelper.updateEvent(task)
|
||||
|
||||
if (caldavDao.getAccountForTask(taskId)?.isSuppressRepeatingTasks != true) {
|
||||
repeatTaskHelper.handleRepeat(task)
|
||||
}
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_ID = "extra_id"
|
||||
const val EXTRA_SUPPRESS_COMPLETION_SNACKBAR = "extra_suppress_snackbar"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue