feat(backend): trigger reply notifications from CommentService

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-27 20:05:29 +01:00
parent 420f50b6d5
commit bc62f3b0af
2 changed files with 25 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import java.util.UUID;
public class CommentService {
private final CommentRepository commentRepository;
private final NotificationService notificationService;
public List<DocumentComment> getCommentsForDocument(UUID documentId) {
List<DocumentComment> roots =
@@ -60,7 +61,9 @@ public class CommentService {
.authorId(author.getId())
.authorName(resolveAuthorName(author))
.build();
return commentRepository.save(reply);
DocumentComment saved = commentRepository.save(reply);
notificationService.notifyReply(saved, root);
return saved;
}
@Transactional

View File

@@ -20,6 +20,7 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -30,6 +31,7 @@ import static org.springframework.http.HttpStatus.NOT_FOUND;
class CommentServiceTest {
@Mock CommentRepository commentRepository;
@Mock NotificationService notificationService;
@InjectMocks CommentService commentService;
// ─── postComment ──────────────────────────────────────────────────────────
@@ -119,6 +121,25 @@ class CommentServiceTest {
assertThat(result.getParentId()).isEqualTo(rootId);
}
@Test
void replyToComment_triggersNotification_afterSave() {
UUID docId = UUID.randomUUID();
UUID rootId = UUID.randomUUID();
AppUser author = AppUser.builder().id(UUID.randomUUID()).username("anna").build();
DocumentComment root = DocumentComment.builder()
.id(rootId).documentId(docId).parentId(null).content("Root").authorName("Hans").build();
DocumentComment saved = DocumentComment.builder()
.id(UUID.randomUUID()).documentId(docId).parentId(rootId).content("Reply").authorName("anna").build();
when(commentRepository.findById(rootId)).thenReturn(Optional.of(root));
when(commentRepository.save(any())).thenReturn(saved);
commentService.replyToComment(docId, rootId, "Reply", author);
verify(notificationService).notifyReply(eq(saved), eq(root));
}
// ─── editComment ──────────────────────────────────────────────────────────
@Test