"""Unit tests for cart total calculations.""" from __future__ import annotations from decimal import Decimal from types import SimpleNamespace import pytest from cart.bp.cart.services.total import total def _item(special=None, regular=None, qty=1): return SimpleNamespace( product_special_price=special, product_regular_price=regular, quantity=qty, ) class TestTotal: def test_empty_cart(self): assert total([]) == 0 def test_regular_price_only(self): result = total([_item(regular=10.0, qty=2)]) assert result == Decimal("20.0") def test_special_price_preferred(self): result = total([_item(special=5.0, regular=10.0, qty=1)]) assert result == Decimal("5.0") def test_none_prices_excluded(self): result = total([_item(special=None, regular=None, qty=1)]) assert result == 0 def test_mixed_items(self): items = [ _item(special=5.0, qty=2), # 10 _item(regular=3.0, qty=3), # 9 _item(), # excluded ] result = total(items) assert result == Decimal("19.0") def test_quantity_multiplication(self): result = total([_item(regular=7.5, qty=4)]) assert result == Decimal("30.0")