
import pytest
from sut.backend.models.inventory_item import InventoryItem


@pytest.fixture
def inventory_item():
    item = InventoryItem()
    item.id = 1
    item.user_id = 2
    item.item_id = 3
    item.paid_price = 100
    item.base_price_revealed = 120
    item.savings_percent = 0.17
    item.acquired_price = 100
    item.created_at = None
    return item

def test_to_dict_returns_expected_keys(inventory_item, monkeypatch):
    # Arrange
    FakeItem = type("FakeItem", (), {"name": "Sword", "owner_character": "Aragorn", "description": "A fine blade"})
    FakeUser = type("FakeUser", (), {"username": "frodo"})
    inventory_item.__dict__["item"] = FakeItem()
    inventory_item.__dict__["user"] = FakeUser()
    # Act
    result = inventory_item.to_dict()
    # Assert
    assert set(result.keys()) == {"id", "user_id", "item_id", "item_name", "owner_character", "description", "paid_price", "base_price_revealed", "savings_percent", "acquired_price", "created_at"}
    assert result["item_name"] == "Sword"
    assert result["owner_character"] == "Aragorn"

def test_repr_returns_expected(inventory_item):
    # Arrange
    # (fixture)
    # Act
    result = repr(inventory_item)
    # Assert
    assert "user=2" in result and "item=3" in result
