Skip to content

Commit

Permalink
test: add post deleting service test
Browse files Browse the repository at this point in the history
  • Loading branch information
ASak1104 committed Aug 4, 2024
1 parent 67d3cf0 commit 686995a
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -21,6 +22,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import team.silvertown.masil.common.exception.DataNotFoundException;
import team.silvertown.masil.common.exception.ForbiddenException;
import team.silvertown.masil.common.map.KakaoPoint;
import team.silvertown.masil.common.scroll.OrderType;
import team.silvertown.masil.common.scroll.dto.NormalListRequest;
Expand Down Expand Up @@ -172,6 +174,56 @@ void cleanUp() {
assertThat(actual.pins()).hasSize(pinSize);
}

@Test
void 산책로_포스트를_삭제한다() {
// given
Post post = postRepository.save(PostTexture.createDependentPost(user, 3));

entityManager.clear();

// when
postService.deleteById(user.getId(), post.getId());

// then
Optional<Post> actual = postRepository.findById(post.getId());

assertThat(actual).isEmpty();
}

@Test
void 존재하지_않는_산책로_포스트는_삭제에_실패한다() {
// given
Post post = postRepository.save(PostTexture.createDependentPost(user, 3));

entityManager.clear();

// when
ThrowingCallable deleteNotExistPost = () -> postService.deleteById(user.getId(), post.getId() + 1);

// then

assertThatExceptionOfType(DataNotFoundException.class)
.isThrownBy(deleteNotExistPost)
.withMessage(PostErrorCode.POST_NOT_FOUND.getMessage());
}

@Test
void 로그인한_사용자와_산책로_포스트_작성자가_다를_경우_삭제에_실패한다() {
// given
Post post = postRepository.save(PostTexture.createDependentPost(user, 3));

entityManager.clear();

// when
ThrowingCallable deleteByNotMatchingUser = () -> postService.deleteById(user.getId() + 1, post.getId());

// then

assertThatExceptionOfType(ForbiddenException.class)
.isThrownBy(deleteByNotMatchingUser)
.withMessage(PostErrorCode.AUTHOR_NOT_MATCHING.getMessage());
}

@Test
void 같은_IP_산책로_포스트_단일_조회__조회수가__번만_한다() {
// given
Expand Down

0 comments on commit 686995a

Please sign in to comment.