Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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("Редактирование невозможно. Комментарий удален");
}

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down