diff --git a/domain/marketplace/__init__.py b/domain/marketplace/__init__.py index 93c3132..1daa737 100644 --- a/domain/marketplace/__init__.py +++ b/domain/marketplace/__init__.py @@ -1,3 +1,4 @@ from .classified_ad import ClassifiedAd as ClassifiedAd from .classified_ad_id import ClassifiedAdId as ClassifiedAdId +from .money import Money as Money from .user_id import UserId as UserId diff --git a/domain/marketplace/money.py b/domain/marketplace/money.py new file mode 100644 index 0000000..fdf17e1 --- /dev/null +++ b/domain/marketplace/money.py @@ -0,0 +1,7 @@ +from dataclasses import dataclass +from decimal import Decimal + + +@dataclass(frozen=True) +class Money: + amount: Decimal diff --git a/tests/test_money.py b/tests/test_money.py new file mode 100644 index 0000000..601e2d6 --- /dev/null +++ b/tests/test_money.py @@ -0,0 +1,24 @@ +from decimal import Decimal + +from domain.marketplace.money import Money + + +def test_money_creation(): + money = Money(amount=Decimal("99.99")) + assert money.amount == Decimal("99.99") + + +def test_money_is_immutable(): + money = Money(amount=Decimal("10.00")) + + try: + money.amount = Decimal("20.00") # type: ignore + assert False, "Should have raised FrozenInstanceError" + except AttributeError: + pass + + +def test_money_equality(): + money1 = Money(amount=Decimal("50.00")) + money2 = Money(amount=Decimal("50.00")) + assert money1 == money2