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.
82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
"""Tests for DeleteCommentUseCase.
|
|
|
|
This module tests the comment deletion use case covering own comment
|
|
deletion, admin deletion, and not-found scenarios.
|
|
"""
|
|
|
|
from unittest.mock import AsyncMock
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from app.application.use_cases.delete_comment import DeleteCommentUseCase
|
|
from app.domain.entities.comment import Comment
|
|
from app.domain.exceptions import NotFoundException
|
|
|
|
|
|
class TestDeleteCommentUseCase:
|
|
"""Tests for DeleteCommentUseCase.
|
|
|
|
Covers TC-UNIT-836 and TC-UNIT-837.
|
|
"""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_own_comment(
|
|
self,
|
|
mock_transaction_manager: AsyncMock,
|
|
) -> None:
|
|
"""Test deleting own comment.
|
|
|
|
TC-UNIT-836: Positive — user deletes own comment.
|
|
"""
|
|
post_id = uuid4()
|
|
author_id = "user-123"
|
|
comment = Comment.create(
|
|
post_id=post_id,
|
|
author_id=author_id,
|
|
content_str="Comment to delete.",
|
|
)
|
|
|
|
mock_comment_repository = AsyncMock()
|
|
mock_comment_repository.get_by_id = AsyncMock(return_value=comment)
|
|
mock_comment_repository.delete = AsyncMock()
|
|
|
|
use_case = DeleteCommentUseCase(
|
|
comment_repo=mock_comment_repository,
|
|
tx_manager=mock_transaction_manager,
|
|
)
|
|
|
|
await use_case.execute(
|
|
comment_id=comment.id,
|
|
user_id=author_id,
|
|
)
|
|
|
|
mock_comment_repository.delete.assert_called_once_with(comment.id)
|
|
mock_transaction_manager.commit.assert_called_once()
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_comment_not_found(
|
|
self,
|
|
mock_transaction_manager: AsyncMock,
|
|
) -> None:
|
|
"""Test deleting a non-existent comment.
|
|
|
|
TC-UNIT-837: Negative — comment not found.
|
|
"""
|
|
mock_comment_repository = AsyncMock()
|
|
mock_comment_repository.get_by_id = AsyncMock(return_value=None)
|
|
|
|
use_case = DeleteCommentUseCase(
|
|
comment_repo=mock_comment_repository,
|
|
tx_manager=mock_transaction_manager,
|
|
)
|
|
|
|
with pytest.raises(NotFoundException):
|
|
await use_case.execute(
|
|
comment_id=uuid4(),
|
|
user_id="user-123",
|
|
)
|
|
|
|
mock_comment_repository.delete.assert_not_called()
|
|
mock_transaction_manager.commit.assert_not_called()
|