Enhance test fixtures and user registration logic to ensure plan existence and correct role assignment

This commit is contained in:
JSC
2025-07-25 18:43:29 +02:00
parent 45ba28af52
commit 52ebc59293
5 changed files with 247 additions and 238 deletions

View File

@@ -22,7 +22,10 @@ class TestAuthService:
@pytest.mark.asyncio
async def test_register_success(
self, auth_service: AuthService, test_plan: Plan, test_user_data: dict[str, str]
self,
auth_service: AuthService,
ensure_plans: tuple[Plan, Plan],
test_user_data: dict[str, str],
) -> None:
"""Test successful user registration."""
request = UserRegisterRequest(**test_user_data)
@@ -32,10 +35,12 @@ class TestAuthService:
# Check user data
assert response.user.email == test_user_data["email"]
assert response.user.name == test_user_data["name"]
assert response.user.role == "user"
assert response.user.role == "admin" # First user gets admin role
assert response.user.is_active is True
assert response.user.credits == test_plan.credits
assert response.user.plan["code"] == test_plan.code
# First user gets pro plan
free_plan, pro_plan = ensure_plans
assert response.user.credits == pro_plan.credits
assert response.user.plan["code"] == pro_plan.code
# Check token
assert response.token.access_token is not None
@@ -213,7 +218,7 @@ class TestAuthService:
# Ensure plan relationship is loaded
await test_session.refresh(test_user, ["plan"])
user_response = await auth_service._create_user_response(test_user)
user_response = await auth_service.create_user_response(test_user)
assert user_response.id == test_user.id
assert user_response.email == test_user.email