fix(CR-07): persist duration_minutes in SQLite and forward to Zoom create_meeting

- Add duration_minutes column (default 60) with ALTER TABLE guard in app/db.py

- Expose duration_minutes in AppointmentResponse (app/schemas.py) and pass it in app/__init__.py

- Add TDD test verifying non-60-minute duration (45m) is persisted and forwarded to Zoom
This commit is contained in:
kiskaadee committed 2026-11-21 17:14:06 -05:00
1 parent 71955d37b8
commit 37ef401bf7
4 files changed
+66 -2

No files matched your search

+2
View File
@@ -101,6 +101,7 @@ def create_app(test_config: dict | None = None) -> Flask:
start_time_local=body.start_time_local, start_time_local=body.start_time_local,
timezone_name=body.timezone, timezone_name=body.timezone,
amount_usd=body.amount_usd, amount_usd=body.amount_usd,
duration_minutes=body.duration_minutes,
db_path=db_path, db_path=db_path,
) )
return jsonify(AppointmentResponse.model_validate(row).model_dump()), 201 return jsonify(AppointmentResponse.model_validate(row).model_dump()), 201
@@ -139,6 +140,7 @@ def create_app(test_config: dict | None = None) -> Flask:
topic=f"Sesión con {row['client_name']}", topic=f"Sesión con {row['client_name']}",
start_time_local=row["start_time_local"], start_time_local=row["start_time_local"],
tz_name=row["timezone"], tz_name=row["timezone"],
duration_minutes=row["duration_minutes"],
) )
updated = db.mark_appointment_confirmed( updated = db.mark_appointment_confirmed(
session_id=row["session_id"], session_id=row["session_id"],
+10 -2
View File
@@ -39,6 +39,7 @@ def init_db(db_path: Path | None = None) -> None:
client_name TEXT NOT NULL, client_name TEXT NOT NULL,
start_time_local TEXT NOT NULL, start_time_local TEXT NOT NULL,
timezone TEXT NOT NULL, timezone TEXT NOT NULL,
duration_minutes INTEGER NOT NULL DEFAULT 60,
amount_usd REAL NOT NULL, amount_usd REAL NOT NULL,
status TEXT NOT NULL CHECK (status IN ('payment_pending', 'confirmed')), status TEXT NOT NULL CHECK (status IN ('payment_pending', 'confirmed')),
zoom_meeting_id TEXT, zoom_meeting_id TEXT,
@@ -49,6 +50,11 @@ def init_db(db_path: Path | None = None) -> None:
) )
""" """
) )
cols = {row["name"] for row in conn.execute("PRAGMA table_info(appointments)").fetchall()}
if "duration_minutes" not in cols:
conn.execute(
"ALTER TABLE appointments ADD COLUMN duration_minutes INTEGER NOT NULL DEFAULT 60"
)
def _row_to_dict(row: sqlite3.Row | None) -> dict | None: def _row_to_dict(row: sqlite3.Row | None) -> dict | None:
@@ -60,6 +66,7 @@ def create_appointment(
start_time_local: str, start_time_local: str,
timezone_name: str, timezone_name: str,
amount_usd: float, amount_usd: float,
duration_minutes: int = 60,
db_path: Path | None = None, db_path: Path | None = None,
) -> dict: ) -> dict:
"""Insert a new appointment in payment_pending state.""" """Insert a new appointment in payment_pending state."""
@@ -72,9 +79,9 @@ def create_appointment(
""" """
INSERT INTO appointments ( INSERT INTO appointments (
session_id, payment_id, client_name, start_time_local, session_id, payment_id, client_name, start_time_local,
timezone, amount_usd, status, created_at timezone, duration_minutes, amount_usd, status, created_at
) )
VALUES (?, ?, ?, ?, ?, ?, 'payment_pending', ?) VALUES (?, ?, ?, ?, ?, ?, ?, 'payment_pending', ?)
""", """,
( (
session_id, session_id,
@@ -82,6 +89,7 @@ def create_appointment(
client_name, client_name,
start_time_local, start_time_local,
timezone_name, timezone_name,
duration_minutes,
amount_usd, amount_usd,
created_at, created_at,
), ),
+1
View File
@@ -57,6 +57,7 @@ class AppointmentResponse(BaseModel):
client_name: str client_name: str
start_time_local: str start_time_local: str
timezone: str timezone: str
duration_minutes: int = 60
amount_usd: float amount_usd: float
status: Literal["payment_pending", "confirmed"] status: Literal["payment_pending", "confirmed"]
zoom_meeting_id: str | None = None zoom_meeting_id: str | None = None
+53
View File
@@ -431,3 +431,56 @@ def test_db_init_sets_wal_once_not_on_every_connection(tmp_path: Path):
with db.get_connection(db_file) as conn: with db.get_connection(db_file) as conn:
mode_after = conn.execute("PRAGMA journal_mode;").fetchone()[0] mode_after = conn.execute("PRAGMA journal_mode;").fetchone()[0]
assert mode_after.lower() == "delete" assert mode_after.lower() == "delete"
def test_duration_minutes_persisted_and_forwarded_to_zoom(client, monkeypatch):
test_client, _ = client
captured_payloads = []
def fake_post(url, **kwargs):
if url == "https://zoom.us/oauth/token":
return FakeResponse(200, {"access_token": "mock_token"})
if url == "https://api.zoom.us/v2/users/me/meetings":
captured_payloads.append(kwargs.get("json"))
return FakeResponse(
201,
{
"id": 11223344,
"join_url": "https://zoom.us/j/11223344",
"start_url": "https://zoom.us/s/11223344?zak=xyz",
},
)
raise AssertionError(f"Unexpected POST URL: {url}")
monkeypatch.setattr(zoom.requests, "post", fake_post)
monkeypatch.setattr(
zoom.requests,
"get",
lambda url, **kwargs: FakeResponse(200, {"meetings": []}),
)
c_resp = test_client.post(
"/api/appointments",
json={
"credentials": SAMPLE_CREDS,
"client_name": "Ana López",
"start_time_local": "2026-11-25T15:00",
"duration_minutes": 45,
},
)
assert c_resp.status_code == 201
appt = c_resp.get_json()
assert appt["duration_minutes"] == 45
g_resp = test_client.get(f"/api/appointments/{appt['session_id']}")
assert g_resp.status_code == 200
assert g_resp.get_json()["duration_minutes"] == 45
p_resp = test_client.post(
f"/api/appointments/{appt['session_id']}/pay",
json={"credentials": SAMPLE_CREDS},
)
assert p_resp.status_code == 200
assert p_resp.get_json()["duration_minutes"] == 45
assert len(captured_payloads) == 1
assert captured_payloads[0]["duration"] == 45