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:
@@ -12,41 +12,24 @@ from app import app
|
||||
from v1.auth.dependencies import get_auth_service
|
||||
from v1.auth.schemas import (
|
||||
AuthUser,
|
||||
SessionCreateRequest,
|
||||
OtpSendRequest,
|
||||
PhoneSessionCreateRequest,
|
||||
SessionRefreshRequest,
|
||||
SessionResponse,
|
||||
VerificationCreateRequest,
|
||||
VerificationCreateResponse,
|
||||
VerificationResendRequest,
|
||||
VerificationVerifyRequest,
|
||||
)
|
||||
from v1.auth.service import AuthService
|
||||
|
||||
|
||||
class FakeE2EAuthService(AuthService):
|
||||
def __init__(self) -> None:
|
||||
self._user = AuthUser(id="user-1", email="user@example.com")
|
||||
self._user = AuthUser(id="user-1", phone="+8613812345678")
|
||||
|
||||
async def create_verification(
|
||||
self, request: VerificationCreateRequest
|
||||
) -> VerificationCreateResponse:
|
||||
return VerificationCreateResponse(email=request.email)
|
||||
|
||||
async def verify_verification(
|
||||
self, request: VerificationVerifyRequest
|
||||
) -> SessionResponse:
|
||||
return SessionResponse(
|
||||
access_token="access-1",
|
||||
refresh_token="refresh-1",
|
||||
expires_in=3600,
|
||||
token_type="bearer",
|
||||
user=self._user,
|
||||
)
|
||||
|
||||
async def resend_verification(self, request: VerificationResendRequest) -> None:
|
||||
async def send_otp(self, request: OtpSendRequest) -> None:
|
||||
return None
|
||||
|
||||
async def create_session(self, request: SessionCreateRequest) -> SessionResponse:
|
||||
async def create_phone_session(
|
||||
self, request: PhoneSessionCreateRequest
|
||||
) -> SessionResponse:
|
||||
return SessionResponse(
|
||||
access_token="access-2",
|
||||
refresh_token="refresh-2",
|
||||
@@ -105,41 +88,25 @@ def test_auth_flow_e2e() -> None:
|
||||
base_url=f"http://{host}:{port}"
|
||||
)
|
||||
try:
|
||||
verification = request_context.post(
|
||||
"/api/v1/auth/verifications",
|
||||
data=json.dumps(
|
||||
{
|
||||
"username": "demo",
|
||||
"email": "user@example.com",
|
||||
"password": "secret123",
|
||||
}
|
||||
),
|
||||
send_code = request_context.post(
|
||||
"/api/v1/auth/otp/send",
|
||||
data=json.dumps({"phone": "+8613812345678"}),
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
assert verification.status == 202
|
||||
assert send_code.status == 204
|
||||
|
||||
verify = request_context.post(
|
||||
"/api/v1/auth/verify",
|
||||
login_or_register = request_context.post(
|
||||
"/api/v1/auth/phone-session",
|
||||
data=json.dumps(
|
||||
{
|
||||
"email": "user@example.com",
|
||||
"phone": "+8613812345678",
|
||||
"token": "123456",
|
||||
}
|
||||
),
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
assert verify.status == 200
|
||||
assert verify.json()["access_token"] == "access-1"
|
||||
|
||||
login = request_context.post(
|
||||
"/api/v1/auth/sessions",
|
||||
data=json.dumps(
|
||||
{"email": "user@example.com", "password": "secret123"}
|
||||
),
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
assert login.status == 200
|
||||
assert login.json()["access_token"] == "access-2"
|
||||
assert login_or_register.status == 200
|
||||
assert login_or_register.json()["access_token"] == "access-2"
|
||||
|
||||
refresh = request_context.post(
|
||||
"/api/v1/auth/sessions/refresh",
|
||||
|
||||
@@ -4,11 +4,16 @@ import socket
|
||||
import threading
|
||||
import time
|
||||
|
||||
import pytest
|
||||
from playwright.sync_api import sync_playwright
|
||||
import uvicorn
|
||||
|
||||
from app import app
|
||||
from v1.infra.dependencies import get_redis_service
|
||||
|
||||
pytest.skip(
|
||||
"infra health endpoint removed from v1 API",
|
||||
allow_module_level=True,
|
||||
)
|
||||
|
||||
|
||||
class _FakeService:
|
||||
@@ -52,8 +57,6 @@ def _start_server(host: str, port: int):
|
||||
|
||||
|
||||
def test_infra_health_e2e() -> None:
|
||||
app.dependency_overrides[get_redis_service] = lambda: _FakeService()
|
||||
|
||||
host = "127.0.0.1"
|
||||
port = _find_free_port()
|
||||
server, thread = _start_server(host, port)
|
||||
|
||||
@@ -11,21 +11,22 @@ import uvicorn
|
||||
|
||||
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, UserUpdateRequest
|
||||
from v1.users.schemas import UserUpdateRequest
|
||||
|
||||
|
||||
class FakeUserService:
|
||||
"""Fake service for E2E testing."""
|
||||
|
||||
def __init__(self, user: UserResponse) -> None:
|
||||
def __init__(self, user: UserContext) -> None:
|
||||
self._user = user
|
||||
|
||||
async def get_me(self) -> UserResponse:
|
||||
async def get_me(self) -> UserContext:
|
||||
return self._user
|
||||
|
||||
async def update_me(self, update: UserUpdateRequest) -> UserResponse:
|
||||
return UserResponse(
|
||||
async def update_me(self, update: UserUpdateRequest) -> UserContext:
|
||||
return UserContext(
|
||||
id=self._user.id,
|
||||
username=(
|
||||
update.username if update.username is not None else self._user.username
|
||||
@@ -38,6 +39,7 @@ class FakeUserService:
|
||||
bio=update.bio if update.bio is not None else self._user.bio,
|
||||
)
|
||||
|
||||
|
||||
def _find_free_port() -> int:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
@@ -65,7 +67,7 @@ def _start_server(host: str, port: int):
|
||||
|
||||
def test_profile_flow_e2e() -> 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