from django.test import SimpleTestCase

from .models import User
from .serializers import UserSerializer


class GraduationYearValidationTests(SimpleTestCase):
    def setUp(self):
        self.user = User(phone_number="+233240000000", username="+233240000000")

    def test_graduation_year_is_required_for_partial_profile_update(self):
        serializer = UserSerializer(self.user, data={"first_name": "Ama"}, partial=True)
        self.assertFalse(serializer.is_valid())
        self.assertIn("graduation_year", serializer.errors)

    def test_graduation_year_cannot_be_before_2000(self):
        serializer = UserSerializer(self.user, data={"graduation_year": 1999}, partial=True)
        self.assertFalse(serializer.is_valid())
        self.assertIn("graduation_year", serializer.errors)

    def test_boundary_graduation_years_are_valid(self):
        for year in (2000, 2050):
            serializer = UserSerializer(self.user, data={"graduation_year": year}, partial=True)
            self.assertTrue(serializer.is_valid(), serializer.errors)
