Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Date for opening_hours:signed #5903

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

kmpoppe
Copy link
Collaborator

@kmpoppe kmpoppe commented Sep 16, 2024

Resolves #4273, ref #4276.

Is this, what we were looking for?

If the answer is that opening_hours:signed=no (either from quest/opening_hours or quest/opening_hours_signed) we add check_date:opening_hours:signed.

If the answer is that opening_hours:signed=yes (either from quest/opening_hours or quest/opening_hours_signed), that means opening_hours:signed is removed and opening_hours=* are set, we remove check_date:opening_hours:signed and try to set check_date:opening_hours to the last edit timestamp so that the apply check for opening_hours works.

quest/opening_hours_signed checks for this info being older than a year OR the element being last edited over a year.

quest/opening_hours now either filters for opening_hours:signed != no OR (opening_hours:signed = no AND check_date:opening_hours:signed older than 1 year)

Testing with applicable objects, the behaviour seems to be programmatically correct, yet, I am unable to formulate the Tests correctly, I might need help in understading how these work. I have thrown away my changes in the tests and will work on them again later -> WIP PR.

Also, please provide feedback on the setting/removing/interpretation of the various check dates.

@kmpoppe kmpoppe marked this pull request as draft September 16, 2024 11:58
Tests for opening_hours quest
@westnordost
Copy link
Member

westnordost commented Sep 17, 2024

Thank you! Will look over this PR soon. Added tests would help (me) a big deal, because good tests are also good documentation of the behavior.

The tests are nothing special, just normal (Java-like) unit tests. If you are confused about OsmElementQuestType::answerAppliedTo, that's just a convenience function for the tests, to get the changes that are made as a Set of StringMapEntryChanges for easy comparison with assertEquals in the tests.

@kmpoppe
Copy link
Collaborator Author

kmpoppe commented Sep 18, 2024

Thanks for the info!

After throwing away my prior changes and re-doing them (thinking about them, being actually more awake than before) the tests I added/changed now (0d3626f and ea10d1f) work as expected.

@kmpoppe kmpoppe marked this pull request as ready for review September 18, 2024 03:23
Copy link
Member

@westnordost westnordost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should also be documented by the tests how the quest(s) behave with current tagging, e.g.

shop=kiosk
opening_hours:signed=no
check_date:opening_hours=2022-02-02

In other words, taking care of the "migration path" from the old tagging to new tagging.

@kmpoppe
Copy link
Collaborator Author

kmpoppe commented Sep 21, 2024

Currently AFK from my programming machine for a week, I shall check your comments then.

@kmpoppe
Copy link
Collaborator Author

kmpoppe commented Oct 2, 2024

will add tests as requested in a few.

@kmpoppe
Copy link
Collaborator Author

kmpoppe commented Oct 2, 2024

Tests added.

CheckOpeningSigned now checks for both check_dates (or older 1 year), that why for second test mentioned (in my eyes) correctly asserts true not false because it's older than a year and has no check_dates at all.

When setting opening_hours:signed=no and it's check_date, remove check_date for opening_hours as it's no longer relevant even if existing opening_hours don't get deleted
Copy link
Member

@westnordost westnordost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for

  • that check_date:opening_hours is removed when answering NoOpeningHoursSign
  • that check_date:opening_hours:signed is removed when answering with anything else
    are missing in AddOpeningHoursTest

When you add new behavior to tested code, always also test this new behavior (not only modify the tests so that they run through green again). If the tests are not kept up-to-date with the implementation, the tests don't make sense.

Also, the new tests you added are puzzling to me.

AddOpeningHours quest should NEVER be applicable while opening_hours:signed=no, because when it is not signed, it should never be asked. Instead, we have CheckOpeningHoursSigned which is asked in its place. When the user answered that it is signed now, only then AddOpeningHours should be asked again.

Instead of this desired behavior, the tests seem to test that the quest is being asked also for places with unsigned opening hours as long as it was checked more than one year ago.

Comment on lines +72 to +81
@Test fun `is applicable if the opening hours not signed and only check date for OH exists`() {
assertTrue(questType.isApplicableTo(node(
tags = mapOf(
"name" to "rundumdieuhr kiosk",
"opening_hours:signed" to "no",
"check_date:opening_hours" to "2021-03-01"
),
timestamp = "2000-11-11".toCheckDate()?.toEpochMilli()
)))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't test what you want it to test. You want it to test that it takes the older of the two of check_date:opening_hours and check_date:opening_hours:signed, but to test this, timestamp would need to be "now" (i.e. the default). Otherwise the quest would anyway be applicable because the last edit date is 24 years old.

Suggested change
@Test fun `is applicable if the opening hours not signed and only check date for OH exists`() {
assertTrue(questType.isApplicableTo(node(
tags = mapOf(
"name" to "rundumdieuhr kiosk",
"opening_hours:signed" to "no",
"check_date:opening_hours" to "2021-03-01"
),
timestamp = "2000-11-11".toCheckDate()?.toEpochMilli()
)))
}
@Test fun `is applicable if the opening hours not signed and only check date for OH exists`() {
assertTrue(questType.isApplicableTo(node(
tags = mapOf(
"name" to "rundumdieuhr kiosk",
"opening_hours:signed" to "no",
"check_date:opening_hours" to "2021-03-01"
)
)))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening hours check date is updated when marked as not signed
2 participants