"""
Unit тесты для сериализаторов подписок.
"""
import pytest
from decimal import Decimal
from apps.subscriptions.serializers import SubscriptionPlanSerializer, SubscriptionSerializer
from apps.subscriptions.models import SubscriptionPlan, Subscription


@pytest.mark.django_db
@pytest.mark.unit
class TestSubscriptionPlanSerializer:
    """Тесты сериализатора SubscriptionPlan."""
    
    def test_plan_serialization(self):
        """Тест сериализации тарифного плана."""
        plan = SubscriptionPlan.objects.create(
            name='Базовый',
            slug='basic',
            price=Decimal('1000.00'),
            duration_days=30,
            max_students=5
        )
        
        serializer = SubscriptionPlanSerializer(plan)
        data = serializer.data
        
        assert data['name'] == 'Базовый'
        assert data['slug'] == 'basic'
        assert float(data['price']) == 1000.00
        assert data['duration_days'] == 30
        assert data['max_students'] == 5


@pytest.mark.django_db
@pytest.mark.unit
class TestSubscriptionSerializer:
    """Тесты сериализатора Subscription."""
    
    def test_subscription_serialization(self, mentor_user):
        """Тест сериализации подписки."""
        plan = SubscriptionPlan.objects.create(
            name='Премиум',
            slug='premium',
            price=Decimal('2000.00'),
            duration_days=30
        )
        
        subscription = Subscription.objects.create(
            user=mentor_user,
            plan=plan,
            status='active'
        )
        
        serializer = SubscriptionSerializer(subscription)
        data = serializer.data
        
        assert data['status'] == 'active'
        assert 'plan' in data
        assert 'user' in data

