From 4b5936f61762ca2d76cf402bca69d82f8821df4d Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sat, 21 Nov 2026 20:21:41 -0500 Subject: [PATCH] fix(zoom): format create_meeting start_time with seconds (yyyy-MM-ddTHH:mm:ss) - Normalize start_time_local in create_meeting to %Y-%m-%dT%H:%M:%S (converting aware datetimes to tz_name) so Zoom's Create Meeting API honors the requested time instead of falling back to now - Add test_pay_appointment_formats_start_time_with_seconds_for_zoom verifying outgoing Zoom payload - Verified with .venv/bin/pytest -v (85 passed) --- app/zoom.py | 17 ++++++++++++++++- tests/test_app.py | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/zoom.py b/app/zoom.py index 6de4a37..570581d 100644 --- a/app/zoom.py +++ b/app/zoom.py @@ -136,6 +136,21 @@ def create_meeting( duration_minutes: int = 60, ) -> dict: """Create a scheduled Zoom meeting on the account owner's calendar.""" + try: + local_tz = ZoneInfo(tz_name) + except ZoneInfoNotFoundError as exc: + raise ZoomAPIError(400, f"Invalid timezone: {tz_name}") from exc + + try: + parsed = datetime.fromisoformat(start_time_local) + except ValueError as exc: + raise ZoomAPIError(400, "Invalid date/time format. Expected YYYY-MM-DDTHH:MM") from exc + + # Zoom Create Meeting API requires seconds (yyyy-MM-ddTHH:mm:ss) when timezone is set; + # HTML datetime-local omits seconds (YYYY-MM-DDTHH:MM), causing Zoom to default to now. + local_dt = parsed.astimezone(local_tz) if parsed.tzinfo is not None else parsed + formatted_start = local_dt.strftime("%Y-%m-%dT%H:%M:%S") + try: resp = requests.post( "https://api.zoom.us/v2/users/me/meetings", @@ -146,7 +161,7 @@ def create_meeting( json={ "topic": topic, "type": 2, - "start_time": start_time_local, + "start_time": formatted_start, "duration": duration_minutes, "timezone": tz_name, "settings": { diff --git a/tests/test_app.py b/tests/test_app.py index 87fef06..aece7fb 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -697,6 +697,33 @@ def test_pay_appointment_forwards_duration_to_zoom(client, monkeypatch): assert captured_payloads[0]["duration"] == 45 +def test_pay_appointment_formats_start_time_with_seconds_for_zoom(client, monkeypatch): + test_client, _ = client + captured_payloads = [] + _mock_zoom_happy_path(monkeypatch, create_calls=captured_payloads) + + c_resp = test_client.post( + "/api/appointments", + json={ + "credentials": SAMPLE_CREDS, + "client_name": "Jorge Paez", + "start_time_local": "2026-11-22T16:00", + "timezone": "America/Bogota", + }, + ) + assert c_resp.status_code == 201 + sid = c_resp.get_json()["session_id"] + + p_resp = test_client.post( + f"/api/appointments/{sid}/pay", + json={"credentials": SAMPLE_CREDS}, + ) + assert p_resp.status_code == 200 + assert len(captured_payloads) == 1 + assert captured_payloads[0]["start_time"] == "2026-11-22T16:00:00" + assert captured_payloads[0]["timezone"] == "America/Bogota" + + def test_concurrent_pay_creates_only_one_zoom_meeting(tmp_path: Path, monkeypatch): db_file = tmp_path / "concurrent_pay.db" app = create_app({"TESTING": True, "DB_PATH": str(db_file), "RATELIMIT_ENABLED": False})