feat: make ClassifiedAd._price optional with default 0.00
This commit is contained in:
@@ -11,4 +11,4 @@ class ClassifiedAd:
|
|||||||
_ownerId: UserId
|
_ownerId: UserId
|
||||||
title: str
|
title: str
|
||||||
text: str
|
text: str
|
||||||
_price: Decimal
|
_price: Decimal = Decimal("0.00")
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from domain.marketplace.classified_ad import ClassifiedAd
|
from domain.marketplace.classified_ad import ClassifiedAd
|
||||||
from domain.marketplace.user_id import UserId
|
from domain.marketplace.user_id import UserId
|
||||||
|
|
||||||
@@ -24,6 +26,41 @@ def test_classified_ad_creation():
|
|||||||
assert ad._price == Decimal("99.99")
|
assert ad._price == Decimal("99.99")
|
||||||
|
|
||||||
|
|
||||||
|
def test_classified_ad_can_not_be_created_without_id():
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
ad = ClassifiedAd(
|
||||||
|
_ownerId=UserId(value=uuid4()),
|
||||||
|
title="Title",
|
||||||
|
text="Text",
|
||||||
|
_price=Decimal("10.00"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_classified_ad_can_not_be_created_without_owner_id():
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
ad = ClassifiedAd(
|
||||||
|
id=UserId(value=uuid4()),
|
||||||
|
title="Title",
|
||||||
|
text="Text",
|
||||||
|
_price=Decimal("10.00"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_classified_ad_can_be_created_without_price():
|
||||||
|
ad_id = uuid4()
|
||||||
|
owner_id = UserId(value=uuid4())
|
||||||
|
|
||||||
|
ad = ClassifiedAd(
|
||||||
|
id=ad_id,
|
||||||
|
_ownerId=owner_id,
|
||||||
|
title="Test Title",
|
||||||
|
text="Test text content",
|
||||||
|
)
|
||||||
|
|
||||||
|
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("0.00")
|
||||||
|
|
||||||
def test_classified_ad_is_immutable():
|
def test_classified_ad_is_immutable():
|
||||||
ad = ClassifiedAd(
|
ad = ClassifiedAd(
|
||||||
id=uuid4(),
|
id=uuid4(),
|
||||||
|
|||||||
Reference in New Issue
Block a user