All checks were successful
ci/woodpecker/pr/pipeline Pipeline was successful
Implement full comments system: domain entities (Comment, CommentLike), value objects (CommentContent), use cases (CRUD, like toggle), SQLAlchemy repository, API v1 endpoints, web UI with comment form and nested replies, i18n translations (EN/RU/FR/DE), and E2E tests. Fix nested reply (reply-to-reply) not displaying — the flat reply_comments dict was only queried for top-level comment IDs, so deeply nested replies were saved to DB (incrementing comment count) but never rendered. Switch to a recursive Jinja2 macro that renders any nesting depth.
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""Tests for ListCommentsUseCase.
|
|
|
|
This module tests the comment listing use case covering retrieval
|
|
of comments by post ID.
|
|
"""
|
|
|
|
from unittest.mock import AsyncMock, Mock
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from app.application.use_cases.list_comments import ListCommentsUseCase
|
|
from app.domain.entities.comment import Comment
|
|
|
|
|
|
class TestListCommentsUseCase:
|
|
"""Tests for ListCommentsUseCase.
|
|
|
|
Covers TC-UNIT-835.
|
|
"""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_comments_by_post(
|
|
self,
|
|
mock_transaction_manager: Mock,
|
|
) -> None:
|
|
"""Test listing comments for a post.
|
|
|
|
TC-UNIT-835: Positive — returns comments for given post_id.
|
|
"""
|
|
post_id = uuid4()
|
|
author_id = "user-123"
|
|
|
|
comments = [
|
|
Comment.create(
|
|
post_id=post_id,
|
|
author_id=author_id,
|
|
content_str="First comment.",
|
|
),
|
|
Comment.create(
|
|
post_id=post_id,
|
|
author_id="user-456",
|
|
content_str="Second comment.",
|
|
),
|
|
]
|
|
mock_comment_repository = AsyncMock()
|
|
mock_comment_repository.get_by_post = AsyncMock(return_value=comments)
|
|
|
|
use_case = ListCommentsUseCase(
|
|
comment_repo=mock_comment_repository,
|
|
)
|
|
|
|
result = await use_case.execute(post_id=post_id)
|
|
|
|
assert len(result) == 2
|
|
assert result[0].post_id == post_id
|
|
assert result[0].author_id == author_id
|
|
assert result[1].author_id == "user-456"
|
|
mock_comment_repository.get_by_post.assert_called_once_with(post_id)
|