feat: add ClassifiedAdText value object and use it in ClassifiedAd
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from .classified_ad import ClassifiedAd as ClassifiedAd
|
||||
from .classified_ad_id import ClassifiedAdId as ClassifiedAdId
|
||||
from .classified_ad_text import ClassifiedAdText as ClassifiedAdText
|
||||
from .classified_ad_title import ClassifiedAdTitle as ClassifiedAdTitle
|
||||
from .money import Money as Money
|
||||
from .price import Price as Price
|
||||
|
||||
@@ -2,6 +2,7 @@ from dataclasses import dataclass, field
|
||||
from decimal import Decimal
|
||||
|
||||
from domain.marketplace.classified_ad_id import ClassifiedAdId
|
||||
from domain.marketplace.classified_ad_text import ClassifiedAdText
|
||||
from domain.marketplace.classified_ad_title import ClassifiedAdTitle
|
||||
from domain.marketplace.price import Price
|
||||
from domain.marketplace.user_id import UserId
|
||||
@@ -12,5 +13,5 @@ class ClassifiedAd:
|
||||
id: ClassifiedAdId
|
||||
_ownerId: UserId
|
||||
title: ClassifiedAdTitle
|
||||
text: str
|
||||
text: ClassifiedAdText
|
||||
price: Price = field(default_factory=lambda: Price(amount=Decimal("0.00")))
|
||||
|
||||
6
domain/marketplace/classified_ad_text.py
Normal file
6
domain/marketplace/classified_ad_text.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ClassifiedAdText:
|
||||
text: str
|
||||
@@ -5,6 +5,7 @@ import pytest
|
||||
|
||||
from domain.marketplace.classified_ad import ClassifiedAd
|
||||
from domain.marketplace.classified_ad_id import ClassifiedAdId
|
||||
from domain.marketplace.classified_ad_text import ClassifiedAdText
|
||||
from domain.marketplace.classified_ad_title import ClassifiedAdTitle
|
||||
from domain.marketplace.price import Price
|
||||
from domain.marketplace.user_id import UserId
|
||||
@@ -18,14 +19,14 @@ def test_classified_ad_creation():
|
||||
id=ad_id,
|
||||
_ownerId=owner_id,
|
||||
title=ClassifiedAdTitle(title="Test Title"),
|
||||
text="Test text content",
|
||||
text=ClassifiedAdText(text="Test text content"),
|
||||
price=Price(amount=Decimal("99.99")),
|
||||
)
|
||||
|
||||
assert ad.id == ad_id
|
||||
assert ad._ownerId == owner_id
|
||||
assert ad.title == ClassifiedAdTitle(title="Test Title")
|
||||
assert ad.text == "Test text content"
|
||||
assert ad.text == ClassifiedAdText(text="Test text content")
|
||||
assert ad.price == Price(amount=Decimal("99.99"))
|
||||
|
||||
|
||||
@@ -34,7 +35,7 @@ def test_classified_ad_can_not_be_created_without_id():
|
||||
ClassifiedAd(
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title=ClassifiedAdTitle(title="Title"),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
@@ -44,7 +45,7 @@ def test_classified_ad_can_not_be_created_without_owner_id():
|
||||
ClassifiedAd(
|
||||
id=ClassifiedAdId(value=uuid4()),
|
||||
title=ClassifiedAdTitle(title="Title"),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
@@ -57,13 +58,13 @@ def test_classified_ad_can_be_created_without_price():
|
||||
id=ad_id,
|
||||
_ownerId=owner_id,
|
||||
title=ClassifiedAdTitle(title="Test Title"),
|
||||
text="Test text content",
|
||||
text=ClassifiedAdText(text="Test text content"),
|
||||
)
|
||||
|
||||
assert ad.id == ad_id
|
||||
assert ad._ownerId == owner_id
|
||||
assert ad.title == ClassifiedAdTitle(title="Test Title")
|
||||
assert ad.text == "Test text content"
|
||||
assert ad.text == ClassifiedAdText(text="Test text content")
|
||||
assert ad.price == Price(amount=Decimal("0.00"))
|
||||
|
||||
|
||||
@@ -73,7 +74,7 @@ def test_classified_ad_can_not_have_negative_price():
|
||||
id=ClassifiedAdId(value=uuid4()),
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title=ClassifiedAdTitle(title="Title"),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("-10.00")),
|
||||
)
|
||||
|
||||
@@ -83,7 +84,7 @@ def test_classified_ad_is_immutable():
|
||||
id=ClassifiedAdId(value=uuid4()),
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title=ClassifiedAdTitle(title="Title"),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
@@ -102,14 +103,14 @@ def test_classified_ad_equality():
|
||||
id=ad_id,
|
||||
_ownerId=owner_id,
|
||||
title=ClassifiedAdTitle(title="Title"),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
ad2 = ClassifiedAd(
|
||||
id=ad_id,
|
||||
_ownerId=owner_id,
|
||||
title=ClassifiedAdTitle(title="Title"),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
@@ -123,6 +124,6 @@ def test_classified_ad_title_validation():
|
||||
id=ClassifiedAdId(value=uuid4()),
|
||||
_ownerId=UserId(value=uuid4()),
|
||||
title=ClassifiedAdTitle(title=long_title),
|
||||
text="Text",
|
||||
text=ClassifiedAdText(text="Text"),
|
||||
price=Price(amount=Decimal("10.00")),
|
||||
)
|
||||
|
||||
7
tests/test_classified_ad_text.py
Normal file
7
tests/test_classified_ad_text.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from domain.marketplace.classified_ad_text import ClassifiedAdText
|
||||
|
||||
|
||||
def test_classified_ad_text_creation():
|
||||
text = ClassifiedAdText(text="This is a classified ad description.")
|
||||
|
||||
assert text.text == "This is a classified ad description."
|
||||
Reference in New Issue
Block a user