Skip to content

Commit

Permalink
add check if exist replies for parentCommentId (#6513)
Browse files Browse the repository at this point in the history
add check if exist replies for parentCommentId
  • Loading branch information
LiliaMokhnatska authored Oct 5, 2023
1 parent df4297d commit 1de4ae4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ public PageableDto<EcoNewsCommentDto> findAllActiveReplies(Pageable pageable, Lo
Page<EcoNewsComment> pages = ecoNewsCommentRepo
.findAllByParentCommentIdAndStatusNotOrderByCreatedDateDesc(pageable, parentCommentId,
CommentStatus.DELETED);
if (pages.isEmpty()) {
throw new NotFoundException(ErrorMessage.COMMENT_NOT_FOUND_BY_PARENT_COMMENT_ID);
}
UserVO user = userVO == null ? UserVO.builder().build() : userVO;
List<EcoNewsCommentDto> ecoNewsCommentDtos = pages
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,23 @@ void findAllActiveReplies() {
PageableDto<EcoNewsCommentDto> actual = ecoNewsCommentService.findAllActiveReplies(pageRequest, 1L, userVO);
assertEquals(pageableDto, actual);
}

@Test
void findAllActiveRepliesThrowException() {
UserVO userVO = ModelUtils.getUserVO();
List<EcoNewsComment> ecoNewsComments1 = List.of();
PageRequest pageRequest = PageRequest.of(0, 2);
Page<EcoNewsComment> page1 = new PageImpl<>(ecoNewsComments1, pageRequest, ecoNewsComments1.size());

when(ecoNewsCommentRepo
.findAllByParentCommentIdAndStatusNotOrderByCreatedDateDesc(pageRequest, 11111L,
CommentStatus.DELETED))
.thenReturn(page1);

assertThrows(NotFoundException.class,
() -> ecoNewsCommentService.findAllActiveReplies(pageRequest, 11111L, userVO));

verify(ecoNewsCommentRepo).findAllByParentCommentIdAndStatusNotOrderByCreatedDateDesc(pageRequest,
11111L, CommentStatus.DELETED);
}
}

0 comments on commit 1de4ae4

Please sign in to comment.