Skip to content

Commit

Permalink
test & fix: 동영상 삭제 메서드 테스트, 공개 동영상 조회 시 삭제되지 않았을 경우만 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
SJ70 committed Jul 18, 2024
1 parent 825eb51 commit 2a92f0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface VideoRepository extends JpaRepository<Video, UUID> {

Optional<Video> findByIdAndUploaderIdAndDeletedAtIsNotNull(UUID id, UUID uploaderId);

Optional<Video> findByIdAndVideoStatus(UUID id, VideoStatus videoStatus);
Optional<Video> findByIdAndVideoStatusAndDeletedAtIsNull(UUID id, VideoStatus videoStatus);

Optional<Video> findByIdAndUploaderId(UUID id, UUID uploaderId);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/j9/bestmoments/service/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Video findDeletedByIdAndUploaderId(UUID id, UUID memberId) {
}

public Video findPublicById(UUID id) {
return videoRepository.findByIdAndVideoStatus(id, VideoStatus.PUBLIC)
return videoRepository.findByIdAndVideoStatusAndDeletedAtIsNull(id, VideoStatus.PUBLIC)
.orElseThrow(EntityNotFoundException::new);
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/j9/bestmoments/service/VideoServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,14 @@ void update() {
Assertions.assertEquals(changedVideoStatus, foundVideo.getVideoStatus());
}

@Test
@Transactional
void softDelete() {
videoService.softDelete(publicVideo);
UUID id = publicVideo.getId();
UUID uploaderId = publicVideo.getUploader().getId();
Assertions.assertThrows(EntityNotFoundException.class, () -> videoService.findPublicById(id));
Assertions.assertDoesNotThrow(() -> videoService.findDeletedByIdAndUploaderId(id, uploaderId));
}

}

0 comments on commit 2a92f0c

Please sign in to comment.