refactor: simplify ICS calendar API to return only duty shifts
All checks were successful
CI / lint-and-test (push) Successful in 24s
All checks were successful
CI / lint-and-test (push) Successful in 24s
- Removed the ability to specify multiple event types in the ICS calendar generation API, ensuring it only returns duty shifts. - Updated the associated test to reflect the change in behavior, confirming that unknown query parameters are ignored. - Revised documentation to clarify the API's focus on duty shifts only, enhancing clarity for users.
This commit is contained in:
@@ -336,10 +336,10 @@ def test_calendar_ical_200_returns_only_that_users_duties(
|
||||
@patch("duty_teller.api.app.build_personal_ics")
|
||||
@patch("duty_teller.api.app.get_duties_for_user")
|
||||
@patch("duty_teller.api.app.get_user_by_calendar_token")
|
||||
def test_calendar_ical_events_all_returns_all_event_types(
|
||||
def test_calendar_ical_ignores_unknown_query_params(
|
||||
mock_get_user, mock_get_duties, mock_build_ics, client
|
||||
):
|
||||
"""GET /api/calendar/ical/{token}.ics?events=all returns ICS with duty, unavailable, vacation."""
|
||||
"""Unknown query params (e.g. events=all) are ignored; response is duty-only."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
mock_user = SimpleNamespace(id=1, full_name="User A")
|
||||
@@ -351,39 +351,15 @@ def test_calendar_ical_events_all_returns_all_event_types(
|
||||
end_at="2026-06-15T18:00:00Z",
|
||||
event_type="duty",
|
||||
)
|
||||
unavailable = SimpleNamespace(
|
||||
id=11,
|
||||
user_id=1,
|
||||
start_at="2026-06-16T09:00:00Z",
|
||||
end_at="2026-06-16T18:00:00Z",
|
||||
event_type="unavailable",
|
||||
)
|
||||
vacation = SimpleNamespace(
|
||||
id=12,
|
||||
user_id=1,
|
||||
start_at="2026-06-17T09:00:00Z",
|
||||
end_at="2026-06-17T18:00:00Z",
|
||||
event_type="vacation",
|
||||
)
|
||||
mock_get_duties.return_value = [
|
||||
(duty, "User A"),
|
||||
(unavailable, "User A"),
|
||||
(vacation, "User A"),
|
||||
]
|
||||
mock_build_ics.return_value = b"BEGIN:VCALENDAR\r\nVEVENT\r\nEND:VCALENDAR"
|
||||
token = "y" * 43
|
||||
mock_get_duties.return_value = [(duty, "User A")]
|
||||
mock_build_ics.return_value = b"BEGIN:VCALENDAR\r\nEND:VCALENDAR"
|
||||
token = "z" * 43
|
||||
|
||||
r = client.get(f"/api/calendar/ical/{token}.ics", params={"events": "all"})
|
||||
assert r.status_code == 200
|
||||
assert r.headers.get("content-type", "").startswith("text/calendar")
|
||||
mock_get_duties.assert_called_once_with(
|
||||
ANY, 1, from_date=ANY, to_date=ANY, event_types=None
|
||||
ANY, 1, from_date=ANY, to_date=ANY, event_types=["duty"]
|
||||
)
|
||||
duties_arg = mock_build_ics.call_args[0][0]
|
||||
assert len(duties_arg) == 3
|
||||
assert duties_arg[0][0].event_type == "duty"
|
||||
assert duties_arg[1][0].event_type == "unavailable"
|
||||
assert duties_arg[2][0].event_type == "vacation"
|
||||
|
||||
|
||||
# --- /api/calendar-events ---
|
||||
|
||||
Reference in New Issue
Block a user