diff --git a/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java b/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java index c3fa85c..02e3c0c 100644 --- a/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java +++ b/main-service/src/main/java/ru/practicum/explorewithme/main/service/CommentServiceImpl.java @@ -111,7 +111,7 @@ public CommentDto updateUserComment(Long userId, Long commentId, UpdateCommentDt throw new EntityNotFoundException("Искомый комментарий с id " + commentId + " пользователя с id " + userId + "не найден"); } - if (existedComment.isDeleted() == true) { + if (existedComment.isDeleted()) { throw new BusinessRuleViolationException("Редактирование невозможно. Комментарий удален"); } @@ -122,6 +122,6 @@ public CommentDto updateUserComment(Long userId, Long commentId, UpdateCommentDt existedComment.setText(updateCommentDto.getText()); existedComment.setEdited(true); - return commentMapper.toDto(commentRepository.save(existedComment)); + return commentMapper.toDto(commentRepository.saveAndFlush(existedComment)); } } diff --git a/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java b/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java index 78394c9..05f2565 100644 --- a/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java +++ b/main-service/src/test/java/ru/practicum/explorewithme/main/service/CommentServiceImplTest.java @@ -155,13 +155,13 @@ void updateUserComment_shouldUpdateCommentAndReturnDto() { when(commentRepository.findById(commentId)).thenReturn(Optional.of(comment)); when(commentMapper.toDto(any(Comment.class))).thenReturn(expectedDto); - when(commentRepository.save(any(Comment.class))).thenAnswer(invocation -> invocation.getArgument(0)); + when(commentRepository.saveAndFlush(any(Comment.class))).thenAnswer(invocation -> invocation.getArgument(0)); CommentDto result = commentService.updateUserComment(userId, commentId, updateCommentDto); Assertions.assertEquals("Updated text", result.getText()); Assertions.assertTrue(comment.isEdited()); - verify(commentRepository).save(comment); + verify(commentRepository).saveAndFlush(comment); } @Test