"""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()