63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from decimal import Decimal
|
|
|
|
from app.domain.price import (
|
|
calculate_expected_payment_amount_kopecks,
|
|
is_init_payment_price_valid,
|
|
)
|
|
from app.schemas.response import DeliveryPrice
|
|
|
|
|
|
def _make_price(**overrides: object) -> DeliveryPrice:
|
|
payload = {
|
|
"provider": "cdek",
|
|
"service_name": "CDEK tariff",
|
|
"price": Decimal("1250.00"),
|
|
"currency": "RUB",
|
|
"delivery_days_min": 1,
|
|
"delivery_days_max": 2,
|
|
}
|
|
payload.update(overrides)
|
|
return DeliveryPrice.model_construct(**payload)
|
|
|
|
|
|
def test_init_payment_price_validation_accepts_exact_match() -> None:
|
|
provider_price = _make_price(price=Decimal("1250.00"))
|
|
|
|
assert is_init_payment_price_valid(125000, provider_price)
|
|
assert calculate_expected_payment_amount_kopecks(provider_price) == 125000
|
|
|
|
|
|
def test_init_payment_price_validation_rejects_mismatch() -> None:
|
|
provider_price = _make_price(price=Decimal("1250.00"))
|
|
|
|
assert not is_init_payment_price_valid(124999, provider_price)
|
|
|
|
|
|
def test_init_payment_price_validation_applies_multiplier_and_rounds_half_up() -> None:
|
|
provider_price = _make_price(price=Decimal("100.50"))
|
|
|
|
expected_amount = calculate_expected_payment_amount_kopecks(
|
|
provider_price,
|
|
price_multiplier=Decimal("1.1"),
|
|
)
|
|
|
|
assert expected_amount == 11100
|
|
assert is_init_payment_price_valid(
|
|
11100,
|
|
provider_price,
|
|
price_multiplier=Decimal("1.1"),
|
|
)
|
|
|
|
|
|
def test_init_payment_price_validation_converts_rub_to_kopecks() -> None:
|
|
provider_price = _make_price(price=Decimal("899.00"))
|
|
|
|
assert calculate_expected_payment_amount_kopecks(provider_price) == 89900
|
|
|
|
|
|
def test_init_payment_price_validation_rejects_non_rub_currency() -> None:
|
|
provider_price = _make_price(price=Decimal("899.00"), currency="USD")
|
|
|
|
assert calculate_expected_payment_amount_kopecks(provider_price) is None
|
|
assert not is_init_payment_price_valid(89900, provider_price)
|