Добавлена обработка уведомлений через ручку
This commit is contained in:
+1
-1
@@ -181,7 +181,7 @@ adapter:
|
||||
|
||||
tbank_payment:
|
||||
init_url: "https://securepay.tinkoff.ru/v2/Init"
|
||||
notification_url: "https://merchant.test/tbank/notification"
|
||||
notification_url: "https://merchant.test/api/v1/delivery/tbank/notifications"
|
||||
success_url: "https://merchant.test/payment/success"
|
||||
auth:
|
||||
terminal_key: "test-terminal-key"
|
||||
|
||||
@@ -101,7 +101,11 @@ def test_create_order_persists_all_required_fields() -> None:
|
||||
assert persisted_order.packages == order_data.packages
|
||||
assert persisted_order.services == order_data.services
|
||||
assert persisted_order.comment == "Test payment"
|
||||
assert persisted_order.payment_status is None
|
||||
assert persisted_order.tbank_payment_id is None
|
||||
assert persisted_order.cdek_order_uuid is None
|
||||
assert persisted_order.created_at is not None
|
||||
assert persisted_order.updated_at is not None
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
@@ -143,3 +147,159 @@ def test_create_order_rejects_duplicate_order_uuid() -> None:
|
||||
await repository.create_order(session, order_data)
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_get_order_by_order_uuid_returns_persisted_order() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
_session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
order_data = _make_order_data()
|
||||
|
||||
async with repository.session() as session:
|
||||
await repository.create_order(session, order_data)
|
||||
|
||||
async with repository.session() as session:
|
||||
order = await repository.get_order_by_order_uuid(session, "order-uuid-1")
|
||||
|
||||
assert order is not None
|
||||
assert order.order_uuid == "order-uuid-1"
|
||||
assert order.payment_url == "https://pay.test/payment/1"
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_get_order_by_order_uuid_returns_none_for_missing_order() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
_session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
async with repository.session() as session:
|
||||
order = await repository.get_order_by_order_uuid(session, "missing-order")
|
||||
|
||||
assert order is None
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_mark_payment_status_persists_status_and_payment_id() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
async with repository.session() as session:
|
||||
await repository.create_order(session, _make_order_data())
|
||||
|
||||
async with repository.session() as session:
|
||||
order = await repository.mark_payment_status(
|
||||
session,
|
||||
"order-uuid-1",
|
||||
"CONFIRMED",
|
||||
8347568144,
|
||||
)
|
||||
|
||||
async with session_factory() as session:
|
||||
result = await session.execute(
|
||||
select(Order).where(Order.order_uuid == "order-uuid-1")
|
||||
)
|
||||
persisted_order = result.scalar_one()
|
||||
|
||||
assert order is not None
|
||||
assert persisted_order.payment_status == "CONFIRMED"
|
||||
assert persisted_order.tbank_payment_id == 8347568144
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_mark_payment_status_returns_none_for_missing_order() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
_session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
async with repository.session() as session:
|
||||
order = await repository.mark_payment_status(
|
||||
session,
|
||||
"missing-order",
|
||||
"CONFIRMED",
|
||||
8347568144,
|
||||
)
|
||||
|
||||
assert order is None
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_mark_cdek_order_registered_persists_cdek_order_uuid() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
async with repository.session() as session:
|
||||
await repository.create_order(session, _make_order_data())
|
||||
|
||||
async with repository.session() as session:
|
||||
order = await repository.mark_cdek_order_registered(
|
||||
session,
|
||||
"order-uuid-1",
|
||||
"cdek-order-uuid-1",
|
||||
)
|
||||
|
||||
async with session_factory() as session:
|
||||
result = await session.execute(
|
||||
select(Order).where(Order.order_uuid == "order-uuid-1")
|
||||
)
|
||||
persisted_order = result.scalar_one()
|
||||
|
||||
assert order is not None
|
||||
assert persisted_order.cdek_order_uuid == "cdek-order-uuid-1"
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_mark_cdek_order_registered_is_idempotent_for_same_uuid() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
async with repository.session() as session:
|
||||
await repository.create_order(session, _make_order_data())
|
||||
|
||||
async with repository.session() as session:
|
||||
await repository.mark_cdek_order_registered(
|
||||
session,
|
||||
"order-uuid-1",
|
||||
"cdek-order-uuid-1",
|
||||
)
|
||||
|
||||
async with repository.session() as session:
|
||||
await repository.mark_cdek_order_registered(
|
||||
session,
|
||||
"order-uuid-1",
|
||||
"cdek-order-uuid-1",
|
||||
)
|
||||
|
||||
async with session_factory() as session:
|
||||
result = await session.execute(select(Order))
|
||||
orders = result.scalars().all()
|
||||
|
||||
assert len(orders) == 1
|
||||
assert orders[0].cdek_order_uuid == "cdek-order-uuid-1"
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
|
||||
def test_mark_cdek_order_registered_returns_none_for_missing_order() -> None:
|
||||
async def run(
|
||||
repository: OrderRepository,
|
||||
_session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> None:
|
||||
async with repository.session() as session:
|
||||
order = await repository.mark_cdek_order_registered(
|
||||
session,
|
||||
"missing-order",
|
||||
"cdek-order-uuid-1",
|
||||
)
|
||||
|
||||
assert order is None
|
||||
|
||||
asyncio.run(_with_repository(run))
|
||||
|
||||
Reference in New Issue
Block a user