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:
@@ -5,72 +5,28 @@ from pydantic import ValidationError
|
||||
|
||||
from v1.auth.schemas import (
|
||||
AuthUser,
|
||||
SessionCreateRequest,
|
||||
OtpSendRequest,
|
||||
PhoneSessionCreateRequest,
|
||||
SessionDeleteRequest,
|
||||
SessionRefreshRequest,
|
||||
SessionResponse,
|
||||
VerificationCreateRequest,
|
||||
VerificationVerifyRequest,
|
||||
VerificationResendRequest,
|
||||
)
|
||||
|
||||
|
||||
def test_signup_requires_valid_email() -> None:
|
||||
def test_send_otp_requires_valid_phone() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
VerificationCreateRequest(
|
||||
username="demo", email="not-an-email", password="secret123"
|
||||
)
|
||||
OtpSendRequest(phone="13812345678")
|
||||
|
||||
|
||||
def test_signup_requires_username() -> None:
|
||||
def test_send_otp_accepts_e164_phone() -> None:
|
||||
request = OtpSendRequest(phone="+14155552671")
|
||||
|
||||
assert request.phone == "+14155552671"
|
||||
|
||||
|
||||
def test_phone_session_requires_six_digit_token() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
VerificationCreateRequest.model_validate(
|
||||
{"email": "user@example.com", "password": "secret123"}
|
||||
)
|
||||
|
||||
|
||||
def test_signup_allows_any_invite_code_input() -> None:
|
||||
request = VerificationCreateRequest(
|
||||
username="demo",
|
||||
email="user@example.com",
|
||||
password="secret123",
|
||||
invite_code="abc123",
|
||||
)
|
||||
|
||||
assert request.invite_code == "abc123"
|
||||
|
||||
|
||||
def test_signup_verify_requires_six_digit_token() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
VerificationVerifyRequest(email="user@example.com", token="abc123")
|
||||
|
||||
|
||||
def test_signup_verify_disallows_new_password() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
VerificationVerifyRequest(
|
||||
type="signup",
|
||||
email="user@example.com",
|
||||
token="123456",
|
||||
new_password="secret123",
|
||||
)
|
||||
|
||||
|
||||
def test_recovery_verify_requires_new_password() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
VerificationVerifyRequest(
|
||||
type="recovery",
|
||||
email="user@example.com",
|
||||
token="123456",
|
||||
)
|
||||
|
||||
|
||||
def test_signup_resend_requires_valid_email() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
VerificationResendRequest(email="invalid")
|
||||
|
||||
|
||||
def test_login_requires_valid_email() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
SessionCreateRequest(email="invalid", password="secret123")
|
||||
PhoneSessionCreateRequest(phone="+8613812345678", token="abc123")
|
||||
|
||||
|
||||
def test_refresh_requires_token() -> None:
|
||||
@@ -78,8 +34,13 @@ def test_refresh_requires_token() -> None:
|
||||
SessionRefreshRequest(refresh_token="")
|
||||
|
||||
|
||||
def test_logout_requires_token() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
SessionDeleteRequest(refresh_token="")
|
||||
|
||||
|
||||
def test_session_response_maps_user() -> None:
|
||||
user = AuthUser(id="user-1", email="user@example.com")
|
||||
user = AuthUser(id="user-1", phone="+14155552671")
|
||||
response = SessionResponse(
|
||||
access_token="access",
|
||||
refresh_token="refresh",
|
||||
@@ -89,4 +50,4 @@ def test_session_response_maps_user() -> None:
|
||||
)
|
||||
|
||||
assert response.user.id == "user-1"
|
||||
assert response.user.email == "user@example.com"
|
||||
assert response.user.phone == "+14155552671"
|
||||
|
||||
Reference in New Issue
Block a user