This commit is contained in:
35
backend/core/users/tests/test_services.py
Normal file
35
backend/core/users/tests/test_services.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from rest_framework.exceptions import ValidationError as DRFValidationError
|
||||
from core.users.services import UserService
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestUserService:
|
||||
|
||||
def setup_method(self):
|
||||
self.user = User.objects.create_user(
|
||||
email="servis@primjer.hr",
|
||||
password="password123"
|
||||
)
|
||||
|
||||
def test_update_profile_success(self):
|
||||
"""Testira uspješno ažuriranje profila preko servisa."""
|
||||
new_data = {"first_name": "Novi", "last_name": "Korisnik"}
|
||||
|
||||
updated_user = UserService.update_user_profile(self.user, new_data)
|
||||
|
||||
assert updated_user.first_name == "Novi"
|
||||
assert updated_user.last_name == "Korisnik"
|
||||
# Provjera da email nije promijenjen ako nismo poslali
|
||||
assert updated_user.email == "servis@primjer.hr"
|
||||
|
||||
def test_update_profile_invalid_data(self):
|
||||
"""Testira validaciju (npr. neispravan format podataka)."""
|
||||
# Pretpostavimo da dodamo logiku u serializer koja brani prazno ime
|
||||
invalid_data = {"first_name": ""}
|
||||
|
||||
with pytest.raises(DRFValidationError):
|
||||
UserService.update_user_profile(self.user, invalid_data)
|
||||
Reference in New Issue
Block a user