This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
@@ -87,6 +88,55 @@ def test_get_order_parses_status_and_waybill_uuid() -> None:
|
||||
assert http_client.calls[0]["headers"] == {"Authorization": "Bearer test-token"}
|
||||
|
||||
|
||||
def test_get_order_logs_request_errors() -> None:
|
||||
response = httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"entity": {"uuid": "cdek-order-uuid", "statuses": []},
|
||||
"requests": [
|
||||
{
|
||||
"request_uuid": "request-uuid",
|
||||
"type": "CREATE",
|
||||
"state": "INVALID",
|
||||
"errors": [
|
||||
{
|
||||
"code": "invalid_order",
|
||||
"message": "Order data is invalid",
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
request=httpx.Request(
|
||||
"GET", "https://api.cdek.test/v2/orders/cdek-order-uuid"
|
||||
),
|
||||
)
|
||||
client = _make_client(SequenceHTTPClient([response]))
|
||||
|
||||
with patch(
|
||||
"app.adapters.delivery_providers.cdek.client.log.warning"
|
||||
) as warning_mock:
|
||||
asyncio.run(client.get_order("cdek-order-uuid"))
|
||||
|
||||
warning_mock.assert_called_once_with(
|
||||
"cdek_order_request_errors",
|
||||
cdek_order_uuid="cdek-order-uuid",
|
||||
requests=[
|
||||
{
|
||||
"request_uuid": "request-uuid",
|
||||
"type": "CREATE",
|
||||
"state": "INVALID",
|
||||
"errors": [
|
||||
{
|
||||
"code": "invalid_order",
|
||||
"message": "Order data is invalid",
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_get_order_retries_on_5xx_and_succeeds() -> None:
|
||||
flaky = httpx.Response(
|
||||
503,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from app.domain.payment_notifications import (
|
||||
TBankPaymentNotificationAction,
|
||||
resolve_tbank_payment_notification_action,
|
||||
should_apply_tbank_payment_status,
|
||||
)
|
||||
|
||||
|
||||
@@ -53,3 +54,27 @@ def test_unknown_status_acknowledges_only() -> None:
|
||||
)
|
||||
|
||||
assert result is TBankPaymentNotificationAction.ACKNOWLEDGE_ONLY
|
||||
|
||||
|
||||
def test_authorized_does_not_downgrade_confirmed() -> None:
|
||||
assert should_apply_tbank_payment_status("CONFIRMED", "AUTHORIZED") is False
|
||||
|
||||
|
||||
def test_confirmed_overwrites_authorized() -> None:
|
||||
assert should_apply_tbank_payment_status("AUTHORIZED", "CONFIRMED") is True
|
||||
|
||||
|
||||
def test_first_status_always_applies() -> None:
|
||||
assert should_apply_tbank_payment_status(None, "AUTHORIZED") is True
|
||||
|
||||
|
||||
def test_same_status_applies() -> None:
|
||||
assert should_apply_tbank_payment_status("CONFIRMED", "CONFIRMED") is True
|
||||
|
||||
|
||||
def test_refund_overwrites_confirmed() -> None:
|
||||
assert should_apply_tbank_payment_status("CONFIRMED", "REFUNDED") is True
|
||||
|
||||
|
||||
def test_unknown_status_does_not_overwrite_known() -> None:
|
||||
assert should_apply_tbank_payment_status("CONFIRMED", "WAT") is False
|
||||
|
||||
@@ -136,7 +136,9 @@ class StubOrderRepository:
|
||||
def session(self) -> StubSession:
|
||||
return StubSession()
|
||||
|
||||
async def get_order_by_order_uuid(self, session: object, order_uuid: str) -> StoredOrder:
|
||||
async def get_order_by_order_uuid(
|
||||
self, session: object, order_uuid: str, *, for_update: bool = False
|
||||
) -> StoredOrder:
|
||||
return self._order
|
||||
|
||||
async def mark_payment_status(
|
||||
|
||||
@@ -90,6 +90,8 @@ class StubOrderRepository:
|
||||
self,
|
||||
session: object,
|
||||
order_uuid: str,
|
||||
*,
|
||||
for_update: bool = False,
|
||||
) -> StoredOrder | None:
|
||||
self.calls.append(("get_order_by_order_uuid", (session, order_uuid)))
|
||||
return self._orders.get(order_uuid)
|
||||
|
||||
Reference in New Issue
Block a user