"""Tests for OrderService. Repo uses src layout: add src to path for order_app."""

import sys
from pathlib import Path

import pytest

# Fixture repo root; parent of tests/
_repo_root = Path(__file__).resolve().parent.parent
_src = _repo_root / "src"
if str(_src) not in sys.path:
    sys.path.insert(0, str(_src))

from order_app.domain.order import Order
from order_app.services.order_service import OrderService
from order_app.repositories.order_repository import OrderRepository


def test_create_order() -> None:
    repo = OrderRepository()
    service = OrderService(repo)
    order = service.create_order(product_id="prod-1", quantity=2)
    assert isinstance(order, Order)
    assert order.product_id == "prod-1"
    assert order.quantity == 2
    assert order.status == "pending"


def test_get_order_returns_saved_order() -> None:
    repo = OrderRepository()
    service = OrderService(repo)
    created = service.create_order(product_id="p1")
    found = service.get_order(created.id)
    assert found is not None
    assert found.id == created.id
