feat: use Price in ClassifiedAd and add negative price test
This commit is contained in:
@@ -2,7 +2,7 @@ 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.price import Price
|
||||
from domain.marketplace.user_id import UserId
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@ class ClassifiedAd:
|
||||
_ownerId: UserId
|
||||
title: str
|
||||
text: str
|
||||
price: Money = field(default_factory=lambda: Money(amount=Decimal("0.00")))
|
||||
price: Price = field(default_factory=lambda: Price(amount=Decimal("0.00")))
|
||||
|
||||
@@ -5,7 +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.price import Price
|
||||
from domain.marketplace.user_id import UserId
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@ def test_classified_ad_creation():
|
||||
_ownerId=owner_id,
|
||||
title="Test Title",
|
||||
text="Test text content",
|
||||
price=Money(amount=Decimal("99.99")),
|
||||
price=Price(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 == Money(amount=Decimal("99.99"))
|
||||
assert ad.price == Price(amount=Decimal("99.99"))
|
||||
|
||||
|
||||
def test_classified_ad_can_not_be_created_without_id():
|
||||
@@ -34,7 +34,7 @@ def test_classified_ad_can_not_be_created_without_id():
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title="Title",
|
||||
text="Text",
|
||||
price=Money(amount=Decimal("10.00")),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_classified_ad_can_not_be_created_without_owner_id():
|
||||
id=ClassifiedAdId(value=uuid4()),
|
||||
title="Title",
|
||||
text="Text",
|
||||
price=Money(amount=Decimal("10.00")),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
|
||||
@@ -63,7 +63,18 @@ 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 == Money(amount=Decimal("0.00"))
|
||||
assert ad.price == Price(amount=Decimal("0.00"))
|
||||
|
||||
|
||||
def test_classified_ad_can_not_have_negative_price():
|
||||
with pytest.raises(ValueError):
|
||||
ClassifiedAd(
|
||||
id=ClassifiedAdId(value=uuid4()),
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title="Title",
|
||||
text="Text",
|
||||
price=Price(amount=Decimal("-10.00")),
|
||||
)
|
||||
|
||||
|
||||
def test_classified_ad_is_immutable():
|
||||
@@ -72,7 +83,7 @@ def test_classified_ad_is_immutable():
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title="Title",
|
||||
text="Text",
|
||||
price=Money(amount=Decimal("10.00")),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -91,14 +102,14 @@ def test_classified_ad_equality():
|
||||
_ownerId=owner_id,
|
||||
title="Title",
|
||||
text="Text",
|
||||
price=Money(amount=Decimal("10.00")),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
ad2 = ClassifiedAd(
|
||||
id=ad_id,
|
||||
_ownerId=owner_id,
|
||||
title="Title",
|
||||
text="Text",
|
||||
price=Money(amount=Decimal("10.00")),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
assert ad1 == ad2
|
||||
|
||||
Reference in New Issue
Block a user