import pytest
from sut.backend.models.user import User


import pytest
from sut.backend.models.user import User
from werkzeug.security import check_password_hash

@pytest.fixture
def user():
    user = User()
    user.id = 5
    user.username = "frodo"
    user.email = "frodo@shire.me"
    user.role = "ring-bearer"
    user.gold = 100
    user.created_at = None
    return user

def test_set_and_check_password(user):
    # Arrange
    password = "mysecret"
    # Act
    user.set_password(password)
    # Assert
    assert user.password_hash != password
    assert check_password_hash(user.password_hash, password)
    assert user.check_password(password)

def test_to_dict_returns_expected_keys(user):
    # Arrange
    # (fixture)
    # Act
    result = user.to_dict()
    # Assert
    assert set(result.keys()) == {"id", "username", "email", "role", "gold", "created_at"}
    assert result["username"] == "frodo"

def test_repr_returns_username(user):
    # Arrange
    # (fixture)
    # Act
    result = repr(user)
    # Assert
    assert "frodo" in result
