81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from app.domain.payment_notifications import (
|
|
TBankPaymentNotificationAction,
|
|
resolve_tbank_payment_notification_action,
|
|
should_apply_tbank_payment_status,
|
|
)
|
|
|
|
|
|
def test_confirmed_success_zero_error_code_registers_cdek_order() -> None:
|
|
result = resolve_tbank_payment_notification_action(
|
|
status="CONFIRMED",
|
|
success=True,
|
|
error_code="0",
|
|
)
|
|
|
|
assert result is TBankPaymentNotificationAction.REGISTER_CDEK_ORDER
|
|
|
|
|
|
def test_confirmed_without_success_acknowledges_only() -> None:
|
|
result = resolve_tbank_payment_notification_action(
|
|
status="CONFIRMED",
|
|
success=False,
|
|
error_code="0",
|
|
)
|
|
|
|
assert result is TBankPaymentNotificationAction.ACKNOWLEDGE_ONLY
|
|
|
|
|
|
def test_confirmed_with_non_zero_error_code_acknowledges_only() -> None:
|
|
result = resolve_tbank_payment_notification_action(
|
|
status="CONFIRMED",
|
|
success=True,
|
|
error_code="101",
|
|
)
|
|
|
|
assert result is TBankPaymentNotificationAction.ACKNOWLEDGE_ONLY
|
|
|
|
|
|
def test_known_non_confirmed_statuses_acknowledge_only() -> None:
|
|
for status in ("AUTHORIZED", "REJECTED", "CANCELED", "DEADLINE_EXPIRED"):
|
|
result = resolve_tbank_payment_notification_action(
|
|
status=status,
|
|
success=True,
|
|
error_code="0",
|
|
)
|
|
|
|
assert result is TBankPaymentNotificationAction.ACKNOWLEDGE_ONLY
|
|
|
|
|
|
def test_unknown_status_acknowledges_only() -> None:
|
|
result = resolve_tbank_payment_notification_action(
|
|
status="UNKNOWN_STATUS",
|
|
success=True,
|
|
error_code="0",
|
|
)
|
|
|
|
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
|