diff --git a/domain/marketplace/classified_ad.py b/domain/marketplace/classified_ad.py index 60edc5f..38e640e 100644 --- a/domain/marketplace/classified_ad.py +++ b/domain/marketplace/classified_ad.py @@ -1,7 +1,8 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from decimal import Decimal from domain.marketplace.classified_ad_id import ClassifiedAdId +from domain.marketplace.money import Money from domain.marketplace.user_id import UserId @@ -11,4 +12,4 @@ class ClassifiedAd: _ownerId: UserId title: str text: str - _price: Decimal = Decimal("0.00") + price: Money = field(default_factory=lambda: Money(amount=Decimal("0.00"))) diff --git a/tests/test_classified_ad.py b/tests/test_classified_ad.py index 5175e6c..b2c3e30 100644 --- a/tests/test_classified_ad.py +++ b/tests/test_classified_ad.py @@ -5,6 +5,7 @@ import pytest from domain.marketplace.classified_ad import ClassifiedAd from domain.marketplace.classified_ad_id import ClassifiedAdId +from domain.marketplace.money import Money from domain.marketplace.user_id import UserId @@ -17,14 +18,14 @@ def test_classified_ad_creation(): _ownerId=owner_id, title="Test Title", text="Test text content", - _price=Decimal("99.99"), + price=Money(amount=Decimal("99.99")), ) assert ad.id == ad_id assert ad._ownerId == owner_id assert ad.title == "Test Title" assert ad.text == "Test text content" - assert ad._price == Decimal("99.99") + assert ad.price == Money(amount=Decimal("99.99")) def test_classified_ad_can_not_be_created_without_id(): @@ -33,7 +34,7 @@ def test_classified_ad_can_not_be_created_without_id(): _ownerId=UserId(value=uuid4()), title="Title", text="Text", - _price=Decimal("10.00"), + price=Money(amount=Decimal("10.00")), ) @@ -43,7 +44,7 @@ def test_classified_ad_can_not_be_created_without_owner_id(): id=ClassifiedAdId(value=uuid4()), title="Title", text="Text", - _price=Decimal("10.00"), + price=Money(amount=Decimal("10.00")), ) @@ -62,7 +63,7 @@ def test_classified_ad_can_be_created_without_price(): assert ad._ownerId == owner_id assert ad.title == "Test Title" assert ad.text == "Test text content" - assert ad._price == Decimal("0.00") + assert ad.price == Money(amount=Decimal("0.00")) def test_classified_ad_is_immutable(): @@ -71,7 +72,7 @@ def test_classified_ad_is_immutable(): _ownerId=UserId(value=uuid4()), title="Title", text="Text", - _price=Decimal("10.00"), + price=Money(amount=Decimal("10.00")), ) try: @@ -90,14 +91,14 @@ def test_classified_ad_equality(): _ownerId=owner_id, title="Title", text="Text", - _price=Decimal("10.00"), + price=Money(amount=Decimal("10.00")), ) ad2 = ClassifiedAd( id=ad_id, _ownerId=owner_id, title="Title", text="Text", - _price=Decimal("10.00"), + price=Money(amount=Decimal("10.00")), ) assert ad1 == ad2