Skip to content

Commit

Permalink
on updating a key with check date, also update the general check date…
Browse files Browse the repository at this point in the history
… if there is one (fixes #5674)
  • Loading branch information
westnordost committed Jun 15, 2024
1 parent 79844ec commit 12ecd28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fun Tags.updateCheckDateForKey(key: String) {
fun Tags.setCheckDateForKey(key: String, date: LocalDate) {
removeCheckDatesForKey(key)
set("$SURVEY_MARK_KEY:$key", date.toCheckDateString())
if (hasCheckDate()) setCheckDate(date)
}

/** Return whether a check date is set for the given key */
Expand All @@ -75,8 +76,12 @@ fun Tags.removeCheckDatesForKey(key: String) {
/** Set/update solely the check date for the entire item to today, this also removes other less
* preferred check date keys for the entire item. */
fun Tags.updateCheckDate() {
setCheckDate(systemTimeNow().toLocalDate())
}

fun Tags.setCheckDate(date: LocalDate) {
removeCheckDates()
set(SURVEY_MARK_KEY, nowAsCheckDateString())
set(SURVEY_MARK_KEY, date.toCheckDateString())
}

/** Return whether any check dates are set */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ class ResurveyUtilsTest {
), changes)
}

@Test fun `updateWithCheckDate updates general check date`() {
val builder = Tags(mapOf("key" to "value", "survey:date" to "1999-01-01"))
builder.updateWithCheckDate("key", "value")
val changes = builder.create().changes

assertEquals(setOf(
StringMapEntryModify("key", "value", "value"),
StringMapEntryAdd("check_date:key", nowAsCheckDateString()),
StringMapEntryDelete("survey:date", "1999-01-01"),
StringMapEntryAdd("check_date", nowAsCheckDateString()),
), changes)
}


Check failure on line 100 in app/src/test/java/de/westnordost/streetcomplete/data/meta/ResurveyUtilsTest.kt

View workflow job for this annotation

GitHub Actions / Kotlin

Needless blank line(s)
@Test fun `updateWithCheckDate modifies old check date on modifying key`() {
val builder = Tags(mapOf(
"key" to "old value",
Expand Down

0 comments on commit 12ecd28

Please sign in to comment.