refactor(backend): update API routes and service layer
- Update agent router/service/repository with new endpoints - Update auth routes with phone-based authentication - Update users service with new phone lookup - Update schedule_items with new schemas - Update message schemas with visibility support - Update settings with new automation scheduler config - Update CLI with new commands - Update tests to match new API contracts
This commit is contained in:
@@ -8,30 +8,31 @@ from fastapi.testclient import TestClient
|
||||
|
||||
from app import app
|
||||
from core.auth.models import CurrentUser
|
||||
from schemas.user.context import UserContext
|
||||
from v1.users.dependencies import get_current_user, get_user_service
|
||||
from v1.users.schemas import UserResponse, UserSearchRequest, UserUpdateRequest
|
||||
from v1.users.schemas import UserSearchRequest, UserUpdateRequest
|
||||
from v1.users.service import UserService
|
||||
|
||||
|
||||
class FakeUserService:
|
||||
"""Fake service for integration testing."""
|
||||
|
||||
def __init__(self, user: UserResponse) -> None:
|
||||
def __init__(self, user: UserContext) -> None:
|
||||
self._user = user
|
||||
self._search_results: list[UserResponse] = []
|
||||
self._search_results: list[UserContext] = []
|
||||
|
||||
def set_search_results(self, results: list[UserResponse]) -> None:
|
||||
def set_search_results(self, results: list[UserContext]) -> None:
|
||||
self._search_results = results
|
||||
|
||||
async def get_me(self) -> UserResponse:
|
||||
async def get_me(self) -> UserContext:
|
||||
if self._user.id is None:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
return self._user
|
||||
|
||||
async def update_me(self, update: UserUpdateRequest) -> UserResponse:
|
||||
async def update_me(self, update: UserUpdateRequest) -> UserContext:
|
||||
if self._user.id is None:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
return UserResponse(
|
||||
return UserContext(
|
||||
id=self._user.id,
|
||||
username=(
|
||||
update.username if update.username is not None else self._user.username
|
||||
@@ -44,7 +45,7 @@ class FakeUserService:
|
||||
bio=update.bio if update.bio is not None else self._user.bio,
|
||||
)
|
||||
|
||||
async def search_users(self, request: UserSearchRequest) -> list[UserResponse]:
|
||||
async def search_users(self, request: UserSearchRequest) -> list[UserContext]:
|
||||
if request.query:
|
||||
return self._search_results if self._search_results else [self._user]
|
||||
return []
|
||||
@@ -68,7 +69,7 @@ def _override_current_user(user_id: UUID) -> Callable[[], CurrentUser]:
|
||||
|
||||
def test_get_me_returns_user() -> None:
|
||||
user_id = UUID("00000000-0000-0000-0000-000000000001")
|
||||
user = UserResponse(
|
||||
user = UserContext(
|
||||
id=str(user_id),
|
||||
username="demo",
|
||||
avatar_url=None,
|
||||
@@ -91,7 +92,7 @@ def test_get_me_returns_user() -> None:
|
||||
|
||||
def test_patch_me_updates_user() -> None:
|
||||
user_id = UUID("00000000-0000-0000-0000-000000000001")
|
||||
user = UserResponse(
|
||||
user = UserContext(
|
||||
id=str(user_id),
|
||||
username="demo",
|
||||
avatar_url=None,
|
||||
@@ -117,7 +118,7 @@ def test_patch_me_updates_user() -> None:
|
||||
|
||||
def test_patch_me_validation_error_returns_problem_details() -> None:
|
||||
user_id = UUID("00000000-0000-0000-0000-000000000001")
|
||||
user = UserResponse(
|
||||
user = UserContext(
|
||||
id=str(user_id),
|
||||
username="demo",
|
||||
avatar_url=None,
|
||||
@@ -142,7 +143,7 @@ def test_patch_me_validation_error_returns_problem_details() -> None:
|
||||
|
||||
def test_search_users_returns_list() -> None:
|
||||
user_id = UUID("00000000-0000-0000-0000-000000000001")
|
||||
user = UserResponse(
|
||||
user = UserContext(
|
||||
id=str(user_id),
|
||||
username="demo",
|
||||
avatar_url=None,
|
||||
@@ -167,7 +168,7 @@ def test_search_users_returns_list() -> None:
|
||||
|
||||
def test_search_users_empty_query_returns_422() -> None:
|
||||
user_id = UUID("00000000-0000-0000-0000-000000000001")
|
||||
user = UserResponse(
|
||||
user = UserContext(
|
||||
id=str(user_id),
|
||||
username="demo",
|
||||
avatar_url=None,
|
||||
|
||||
Reference in New Issue
Block a user