feat: add Money value object

This commit is contained in:
2026-07-26 07:28:11 -04:00
parent 18ade9c575
commit 1ce54ae53a
3 changed files with 32 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,7 @@
from dataclasses import dataclass
from decimal import Decimal
@dataclass(frozen=True)
class Money:
amount: Decimal

24
tests/test_money.py Normal file
View File

@@ -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