- PostLike domain entity (post_id, liked_by) with BaseEntity integration
- Post entity: add like_count field (default 0) and to_dict serialization
- PostRepository interface: add get_like, add_like, remove_like methods
- TogglePostLikeUseCase: toggle logic (like → unlike, unlike → like)
- PostResponseDTO/PostResponseSchema: add like_count field
- PostLikeORM model with FK to posts and cascade delete
- SQLAlchemyPostRepository: implement like query/add/remove with ORM mapping
- DI provider registration for TogglePostLikeUseCase
- API endpoint POST /api/v1/posts/{id}/like (auth required)
- Unit tests: PostLike entity, Post.like_count, TogglePostLikeUseCase (7 tests)
- API tests: POST /api/v1/posts/{id}/like (4 tests)
- Test model files: FEATURE_LIKES.md, TEST_MODEL.md updated
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""Tests for PostLike domain entity.
|
|
|
|
This module tests the PostLike entity creation, attributes,
|
|
and BaseEntity integration.
|
|
"""
|
|
|
|
from uuid import UUID
|
|
|
|
from app.domain.entities.like import PostLike
|
|
|
|
|
|
class TestPostLikeEntity:
|
|
"""Tests for the PostLike domain entity.
|
|
|
|
Covers TC-UNIT-826: PostLike entity valid creation.
|
|
"""
|
|
|
|
def test_post_like_creation(self) -> None:
|
|
"""Test creating a PostLike with valid attributes.
|
|
|
|
TC-UNIT-826: Positive — create PostLike instance.
|
|
|
|
Expected:
|
|
- post_id matches input
|
|
- liked_by matches input
|
|
- id is a valid UUID
|
|
- created_at is set
|
|
"""
|
|
post_id = UUID("00000000-0000-0000-0000-000000000001")
|
|
liked_by = "user-123"
|
|
|
|
like = PostLike(post_id=post_id, liked_by=liked_by)
|
|
|
|
assert like.post_id == post_id
|
|
assert like.liked_by == liked_by
|
|
assert isinstance(like.id, UUID)
|
|
assert like.created_at is not None
|
|
|
|
def test_post_like_to_dict(self) -> None:
|
|
"""Test PostLike to_dict serialization."""
|
|
post_id = UUID("00000000-0000-0000-0000-000000000001")
|
|
liked_by = "device-abc-123"
|
|
|
|
like = PostLike(post_id=post_id, liked_by=liked_by)
|
|
data = like.to_dict()
|
|
|
|
assert data["post_id"] == str(post_id)
|
|
assert data["liked_by"] == liked_by
|
|
assert "id" in data
|
|
assert "created_at" in data
|