refactor(meeting): reduce complexity in join_room and implement test …#46
refactor(meeting): reduce complexity in join_room and implement test …#46aniebietafia merged 1 commit intomainfrom
Conversation
…suite - Refactor `MeetingService.join_room` into smaller helper methods to reduce cyclomatic complexity from 15 to under 10, resolving Ruff C901. - Implement comprehensive unit tests for `MeetingService` covering room lifecycle, participant management, and edge cases. - Add integration tests for meeting router using `httpx.AsyncClient` to ensure compatibility with Windows proactor event loops. - Resolve 21 Mypy type errors across `service.py`, `router.py`, and `state.py` related to dynamic attribute injection and async Redis interactions. Signed-off-by: aniebietafia <aniebietafia87@gmail.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughIntroduces a complete meeting room management system with database models, Alembic migrations, service layer, Redis state synchronization, FastAPI routing, and authentication improvements. Includes room creation, participant joining/management, meeting history, bulk invitations, and configuration updates, supported by comprehensive unit tests and email templates. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant API as API Router
participant Svc as MeetingService
participant Repo as MeetingRepository
participant DB as Database
participant Redis as Redis State
User->>API: POST /meetings (RoomCreate)
API->>Svc: create_room(host, name, settings, scheduled_at)
loop Retry until unique
Svc->>Repo: room_code_exists(code)
Repo->>DB: Query rooms table
DB-->>Repo: exists: bool
Repo-->>Svc: code_exists
end
Svc->>Repo: create_room(Room)
Repo->>DB: INSERT Room
DB-->>Repo: Room with id
Svc->>Repo: create_participant(Participant)
Repo->>DB: INSERT Participant (host)
DB-->>Repo: Participant
Svc->>Redis: add_participant(room_code, host_id)
Redis-->>Svc: ok
Svc-->>API: Room
API-->>User: RoomApiResponse {room_code, join_url}
sequenceDiagram
actor User
participant API as API Router
participant Svc as MeetingService
participant Repo as MeetingRepository
participant DB as Database
participant Redis as Redis State
User->>API: POST /meetings/{room_code}/join (JoinRoomRequest)
API->>Svc: join_room(room_code, user/guest_session_id, guest_name, language)
Svc->>Repo: get_room_by_code(room_code)
Repo->>DB: Query rooms
DB-->>Repo: Room
Repo-->>Svc: Room
alt Room is active/pending
Svc->>Redis: get_participants(room_code)
Redis-->>Svc: participants dict
alt Capacity exceeded or locked
Svc->>Redis: add_to_lobby(room_code, user_id, display_name)
Redis-->>Svc: ok
else Can join
Svc->>Repo: create_or_update_participant(Participant)
Repo->>DB: INSERT/UPDATE participant
DB-->>Repo: Participant
Svc->>Redis: add_participant(room_code, user_id, language)
Redis-->>Svc: ok
end
else Room ended/scheduled
Svc-->>API: BadRequestException
API-->>User: Error response
end
Svc-->>API: {room_code, participants, join_url}
API-->>User: JSONResponse
sequenceDiagram
actor User
participant API as API Router
participant Svc as MeetingService
participant Repo as MeetingRepository
participant DB as Database
User->>API: GET /meetings/history?role=all&page=1
API->>Svc: get_meeting_history(user_id, role_filter, page, page_size)
Svc->>Repo: get_meeting_history(user_id, role_filter, offset, limit)
Repo->>DB: Query rooms/participants (grouped)<br/>with duration & counts
DB-->>Repo: (total_count, Row[])
Repo-->>Svc: (total_count, results)
loop For each meeting row
Svc->>Svc: Transform to MeetingHistoryItem<br/>(room_code, name, duration_minutes, participant_count)
end
Svc-->>API: {total, page, page_size, items[]}
API-->>User: MeetingHistoryApiResponse
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| ) | ||
| sent_count += 1 | ||
| except Exception as e: | ||
| logger.error(f"Failed to queue Kafka event for email to {email}: {e}") |
| ) | ||
| if payload.get("type") == "guest": | ||
| return payload.get("sub") # type: ignore[no-any-return] | ||
| except Exception: |
|
|
||
| import json | ||
| import logging | ||
| from collections.abc import Awaitable |
| import json | ||
| import logging | ||
| from collections.abc import Awaitable | ||
| from typing import Any, cast |
…suite
MeetingService.join_roominto smaller helper methods to reduce cyclomatic complexity from 15 to under 10, resolving Ruff C901.MeetingServicecovering room lifecycle, participant management, and edge cases.httpx.AsyncClientto ensure compatibility with Windows proactor event loops.service.py,router.py, andstate.pyrelated to dynamic attribute injection and async Redis interactions.Summary by CodeRabbit
Release Notes