Ignore geofence triggers for hidden tasks

pull/996/head
Alex Baker 4 years ago
parent cc632a4271
commit bbd9a24bc7

@ -4,6 +4,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
@ -160,6 +161,68 @@ class LocationDaoTest : InjectingTestCase() {
}
}
@Test
fun ignoreArrivalForHiddenTask() {
Freeze.freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
with(ID, 1),
with(DUE_TIME, newDateTime().plusMinutes(15)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true)))
assertTrue(locationDao.getArrivalGeofences(place.uid, now()).isEmpty())
}
}
@Test
fun ignoreDepartureForHiddenTask() {
Freeze.freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
with(ID, 1),
with(DUE_TIME, newDateTime().plusMinutes(15)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
locationDao.insert(newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true)))
assertTrue(locationDao.getDepartureGeofences(place.uid, now()).isEmpty())
}
}
@Test
fun getArrivalWithElapsedHideUntil() {
Freeze.freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
with(ID, 1),
with(DUE_TIME, newDateTime().minusMinutes(15)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(ARRIVAL, true))
geofence.id = locationDao.insert(geofence)
assertEquals(listOf(geofence), locationDao.getArrivalGeofences(place.uid, now()))
}
}
@Test
fun getDepartureWithElapsedHideUntil() {
Freeze.freezeAt(now()).thawAfter {
val place = newPlace()
locationDao.insert(place)
taskDao.createNew(newTask(
with(ID, 1),
with(DUE_TIME, newDateTime().minusMinutes(15)),
with(HIDE_TYPE, Task.HIDE_UNTIL_DUE_TIME)))
val geofence = newGeofence(with(TASK, 1), with(PLACE, place.uid), with(DEPARTURE, true))
geofence.id = locationDao.insert(geofence)
assertEquals(listOf(geofence), locationDao.getDepartureGeofences(place.uid, now()))
}
}
override fun inject(component: TestComponent) = component.inject(this)
}

@ -43,13 +43,15 @@ public interface LocationDao {
@Query(
"SELECT geofences.* FROM geofences"
+ " INNER JOIN tasks ON tasks._id = geofences.task"
+ " WHERE place = :place AND arrival = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now")
+ " WHERE place = :place AND arrival = 1 AND tasks.completed = 0"
+ " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now")
List<Geofence> getArrivalGeofences(String place, long now);
@Query(
"SELECT geofences.* FROM geofences"
+ " INNER JOIN tasks ON tasks._id = geofences.task"
+ " WHERE place = :place AND departure = 1 AND tasks.completed = 0 AND tasks.deleted = 0 AND tasks.snoozeTime < :now")
+ " WHERE place = :place AND departure = 1 AND tasks.completed = 0"
+ " AND tasks.deleted = 0 AND tasks.snoozeTime < :now AND tasks.hideUntil < :now")
List<Geofence> getDepartureGeofences(String place, long now);
@Query(

Loading…
Cancel
Save