test(unit): add roles, web deps, use cases, VO boundary tests — reach 70% coverage
Some checks failed
ci/woodpecker/pr/pipeline Pipeline was canceled
Some checks failed
ci/woodpecker/pr/pipeline Pipeline was canceled
This commit is contained in:
@@ -91,3 +91,73 @@ class TestSlug:
|
||||
slug2 = Slug("test-slug")
|
||||
assert slug1 == slug2
|
||||
assert hash(slug1) == hash(slug2)
|
||||
|
||||
def test_slug_str_and_primitive(self) -> None:
|
||||
"""Test slug string and primitive conversion."""
|
||||
slug = Slug("test-slug")
|
||||
assert str(slug) == "test-slug"
|
||||
assert slug.to_primitive() == "test-slug"
|
||||
|
||||
def test_slug_eq_with_non_value_object(self) -> None:
|
||||
"""Test slug equality with non-ValueObject returns False."""
|
||||
slug = Slug("test-slug")
|
||||
assert slug != "test-slug"
|
||||
|
||||
def test_slug_not_string(self) -> None:
|
||||
"""Test non-string slug raises ValueError."""
|
||||
with pytest.raises(ValueError, match="string"):
|
||||
Slug(123) # type: ignore[arg-type]
|
||||
|
||||
def test_slug_too_long(self) -> None:
|
||||
"""Test slug exceeding max length raises ValueError."""
|
||||
with pytest.raises(ValueError, match="at most"):
|
||||
Slug("a" * 201)
|
||||
|
||||
|
||||
class TestValueObjectBase:
|
||||
"""Test base ValueObject behavior across types."""
|
||||
|
||||
def test_title_eq_with_non_value_object(self) -> None:
|
||||
"""Test title equality with non-ValueObject returns False."""
|
||||
title = Title("Test Title")
|
||||
assert title != "Test Title"
|
||||
|
||||
def test_content_str_and_primitive(self) -> None:
|
||||
"""Test content string and primitive conversion."""
|
||||
content = Content("Enough characters for valid content")
|
||||
assert str(content) == "Enough characters for valid content"
|
||||
assert content.to_primitive() == "Enough characters for valid content"
|
||||
|
||||
def test_content_not_string(self) -> None:
|
||||
"""Test non-string content raises ValueError."""
|
||||
with pytest.raises(ValueError, match="string"):
|
||||
Content(123) # type: ignore[arg-type]
|
||||
|
||||
def test_value_object_eq_and_hash_directly(self) -> None:
|
||||
"""Test ValueObject base eq and hash via direct call."""
|
||||
from app.domain.value_objects.base import ValueObject
|
||||
|
||||
class SimpleVO(ValueObject[str]):
|
||||
def _validate(self) -> None:
|
||||
pass
|
||||
|
||||
vo1 = SimpleVO("test")
|
||||
vo2 = SimpleVO("test")
|
||||
vo3 = SimpleVO("other")
|
||||
|
||||
assert ValueObject.__eq__(vo1, vo2) is True
|
||||
assert ValueObject.__eq__(vo1, vo3) is False
|
||||
assert ValueObject.__eq__(vo1, "test") is False
|
||||
assert ValueObject.__hash__(vo1) == hash("test")
|
||||
|
||||
def test_content_exact_min_length(self) -> None:
|
||||
"""Test content at exact minimum length boundary."""
|
||||
min_content = "a" * 10
|
||||
content = Content(min_content)
|
||||
assert content.value == min_content
|
||||
|
||||
def test_slug_exact_max_length(self) -> None:
|
||||
"""Test slug at exact maximum length boundary."""
|
||||
max_slug = "a" * 200
|
||||
slug = Slug(max_slug)
|
||||
assert slug.value == max_slug
|
||||
|
||||
Reference in New Issue
Block a user