diff --git a/domain/marketplace/classified_ad.py b/domain/marketplace/classified_ad.py index 22ab7ec..ab9ec4e 100644 --- a/domain/marketplace/classified_ad.py +++ b/domain/marketplace/classified_ad.py @@ -11,4 +11,4 @@ class ClassifiedAd: _ownerId: UserId title: str text: str - _price: Decimal + _price: Decimal = Decimal("0.00") diff --git a/tests/test_classified_ad.py b/tests/test_classified_ad.py index 0d3b884..5775d51 100644 --- a/tests/test_classified_ad.py +++ b/tests/test_classified_ad.py @@ -1,6 +1,8 @@ from decimal import Decimal from uuid import uuid4 +import pytest + from domain.marketplace.classified_ad import ClassifiedAd from domain.marketplace.user_id import UserId @@ -24,6 +26,41 @@ def test_classified_ad_creation(): 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(): ad = ClassifiedAd( id=uuid4(),