mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
send AM or PM instead of trying to parse morning or afternoon
This commit is contained in:
parent
f8b9d82200
commit
208113ae6d
2 changed files with 28 additions and 1 deletions
|
|
@ -5,9 +5,16 @@ from domain.abri.models import SlotCode
|
|||
|
||||
_MIDDAY = time(12, 0)
|
||||
|
||||
# HubSpot's confirmed-time field carries these half-day labels, not clock times.
|
||||
_LABEL_SLOTS: dict[str, SlotCode] = {"morning": "AM", "afternoon": "PM"}
|
||||
|
||||
|
||||
def slot_for_confirmed_time(confirmed_time: Optional[str]) -> SlotCode:
|
||||
if confirmed_time is None or confirmed_time.strip() == "":
|
||||
return "AD"
|
||||
parsed = datetime.strptime(confirmed_time.strip(), "%H:%M").time()
|
||||
normalised = confirmed_time.strip()
|
||||
label_slot = _LABEL_SLOTS.get(normalised.lower())
|
||||
if label_slot is not None:
|
||||
return label_slot
|
||||
parsed = datetime.strptime(normalised, "%H:%M").time()
|
||||
return "AM" if parsed < _MIDDAY else "PM"
|
||||
|
|
|
|||
|
|
@ -38,6 +38,26 @@ def test_a_confirmed_time_at_or_after_midday_books_the_afternoon_slot(
|
|||
assert slot == "PM"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("confirmed_time", ["morning", "Morning", " MORNING "])
|
||||
def test_hubspots_morning_label_books_the_morning_slot(confirmed_time: str) -> None:
|
||||
# Act
|
||||
slot = slot_for_confirmed_time(confirmed_time)
|
||||
|
||||
# Assert
|
||||
assert slot == "AM"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("confirmed_time", ["afternoon", "Afternoon", " AFTERNOON "])
|
||||
def test_hubspots_afternoon_label_books_the_afternoon_slot(
|
||||
confirmed_time: str,
|
||||
) -> None:
|
||||
# Act
|
||||
slot = slot_for_confirmed_time(confirmed_time)
|
||||
|
||||
# Assert
|
||||
assert slot == "PM"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("confirmed_time", ["half nine", "25:00", "9.30am"])
|
||||
def test_an_unparseable_confirmed_time_fails_loudly_rather_than_booking_all_day(
|
||||
confirmed_time: str,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue