Skip to content

Commit

Permalink
added test to check if user can like their own comment. should not like
Browse files Browse the repository at this point in the history
  • Loading branch information
Warded120 committed Dec 3, 2024
1 parent 7249fb8 commit 4d8d9ad
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,37 @@ void likeTest() {
verify(modelMapper).map(userVO, User.class);
}

@Test
void likeTest_OwnerUserLikesTheirComment_ShouldNotLike() {
Long commentId = 1L;
UserVO userVO = getUserVO();
User user = getUser();
Comment comment = getComment();
RatingPoints ratingPoints = RatingPoints.builder().id(1L).name("LIKE_COMMENT_OR_REPLY").points(1).build();
Long articleId = 10L;
Habit habit = getHabit();
habit.setUserId(user.getId());
HabitTranslation habitTranslation = getHabitTranslation();

when(userRepo.findById(user.getId())).thenReturn(Optional.of(user));
when(habitRepo.findById(articleId)).thenReturn(Optional.of(habit));
when(habitTranslationRepo.findByHabitAndLanguageCode(habit, Locale.of("en").getLanguage()))
.thenReturn(Optional.ofNullable(habitTranslation));
when(ratingPointsRepo.findByNameOrThrow("LIKE_COMMENT_OR_REPLY")).thenReturn(ratingPoints);
when(commentRepo.findByIdAndStatusNot(commentId, CommentStatus.DELETED)).thenReturn(Optional.of(comment));
when(modelMapper.map(userVO, User.class)).thenReturn(user);
doNothing().when(userNotificationService).createNotification(
any(UserVO.class), any(UserVO.class), any(NotificationType.class),
anyLong(), anyString(), anyLong(), anyString());

commentService.like(commentId, userVO, Locale.ENGLISH);

assertFalse(comment.getUsersLiked().contains(user));

verify(commentRepo).findByIdAndStatusNot(commentId, CommentStatus.DELETED);
verify(modelMapper).map(userVO, User.class);
}

@Test
void likeEcoNewsCommentTest() {
Long commentId = 1L;
Expand Down

0 comments on commit 4d8d9ad

Please sign in to comment.