import pytest

from maps_adv.billing_proxy.lib.domain.exceptions import OrderDoesNotExist

pytestmark = [pytest.mark.asyncio, pytest.mark.mock_dm]


async def test_uses_dm(orders_domain, orders_dm):
    orders_dm.find_order.coro.return_value = {"id": 1, "title": "Заказ"}

    result = await orders_domain.update_order(
        order_id=1, title="Заказ ещё", text="Текст", comment="Коммент"
    )

    orders_dm.update_order.assert_called_with(
        order_id=1, title="Заказ ещё", text="Текст", comment="Коммент"
    )
    assert result == {"id": 1, "title": "Заказ"}


async def test_raises_for_inexistent_order(orders_domain, orders_dm):
    orders_dm.find_order.coro.return_value = None

    with pytest.raises(OrderDoesNotExist) as exc:
        await orders_domain.update_order(
            order_id=1, title="Заказ ещё", text="Текст", comment="Коммент"
        )

    assert exc.value.order_id == 1
