Skip to content

Commit

Permalink
[#160] test: PostLikeEventHandlerTest 단위테스트로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
shin-mallang committed Dec 16, 2023
1 parent 38dec2e commit 1056c88
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mallang.post.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;

import com.mallang.common.ServiceTest;
import com.mallang.post.application.command.ClickPostLikeCommand;
import org.junit.jupiter.api.BeforeEach;
import com.mallang.post.domain.PostDeleteEvent;
import com.mallang.post.domain.PostId;
import com.mallang.post.domain.like.PostLikeRepository;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand All @@ -14,31 +16,27 @@
@DisplayName("포스트 좋아요 이벤트 핸들러 (PostLikeEventHandler) 은(는)")
@SuppressWarnings("NonAsciiCharacters")
@DisplayNameGeneration(ReplaceUnderscores.class)
class PostLikeEventHandlerTest extends ServiceTest {
class PostLikeEventHandlerTest {

private Long memberId;
private String blogName;
private Long postId;

@BeforeEach
void setUp() {
memberId = 회원을_저장한다("말랑");
blogName = 블로그_개설(memberId, "mallang-log");
postId = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1").getPostId();
}
private final PostLikeRepository postLikeRepository = mock(PostLikeRepository.class);
private final PostLikeEventHandler postLikeEventHandler = new PostLikeEventHandler(postLikeRepository);

@Nested
class 포스트_삭제_이벤트를_받아 {

@Test
void 해당_포스트에_눌린_좋아요를_모두_제거한다() {
postLikeService.like(new ClickPostLikeCommand(postId, blogName, memberId, null));
// given
PostId postId = new PostId(1L, 1L);
PostDeleteEvent postDeleteEvent = new PostDeleteEvent(postId);

// when
포스트를_삭제한다(memberId, postId, blogName);
postLikeEventHandler.deletePostLike(postDeleteEvent);

// then
assertThat(postLikeRepository.findByPostAndMember(postId, blogName, memberId)).isEmpty();
then(postLikeRepository)
.should(times(1))
.deleteAllByPostId(postId);
}
}
}

0 comments on commit 1056c88

Please sign in to comment.