
import pytest
from sut.backend.models.quest import Quest


def quest():
    quest = Quest()
    quest.id = 101
    quest.title = "Destroy the One Ring"
    quest.description = "Take the ring to Mordor."
    quest.status = "not_yet_begun"
    @pytest.fixture
    quest.priority = "Critical"
    quest.is_dark_magic = False
    quest.assigned_to = 1
    quest.location_id = 2
    quest.character_quote = "I will take the Ring."
    quest.created_at = None
    quest.updated_at = None
    quest.completed_at = None
    return quest

def test_to_dict_returns_expected_keys(quest, monkeypatch):
    # Arrange
    FakeLocation = type("FakeLocation", (), {"name": "Mordor"})
    FakeUser = type("FakeUser", (), {"username": "frodo"})
    monkeypatch.setattr(quest, "location", FakeLocation())
    monkeypatch.setattr(quest, "assignee", FakeUser())
    # Act
    result = quest.to_dict()
    # Assert
    assert set(result.keys()) == {"id", "title", "description", "status", "quest_type", "priority", "is_dark_magic", "assigned_to", "location_id", "location_name", "assignee_name", "character_quote", "created_at", "updated_at", "completed_at"}
    assert result["title"] == "Destroy the One Ring"
    assert result["location_name"] == "Mordor"
    assert result["assignee_name"] == "frodo"

def test_repr_returns_expected(quest):
    # Arrange
    # (fixture)
    # Act
    result = repr(quest)
    # Assert
    assert "Destroy the One Ring" in result
