-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #76 - feat: 게시글 상세 조회시 조회수 증가 기능 구현 쿠키를 사용하여 중복된 조회수 증가를 방지한다. * #76 - test: 조회수 증가 기능 테스트 코드 작성 쿠키 생성을 확인함
- Loading branch information
Showing
5 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/cotato/bookitlist/post/service/PostServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cotato.bookitlist.post.service; | ||
|
||
import cotato.bookitlist.book.domain.entity.Book; | ||
import cotato.bookitlist.config.security.oauth.AuthProvider; | ||
import cotato.bookitlist.member.domain.Member; | ||
import cotato.bookitlist.post.domain.Post; | ||
import cotato.bookitlist.post.repository.PostRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.BDDMockito.then; | ||
|
||
@DisplayName("게시글 서비스 테스트") | ||
@ExtendWith(MockitoExtension.class) | ||
class PostServiceTest { | ||
|
||
@InjectMocks | ||
PostService sut; | ||
@Mock | ||
PostRepository postRepository; | ||
|
||
@Test | ||
@DisplayName("게시글 조회수 증가 요청시 조회수가 증가한다.") | ||
void givenPostId_whenIncreasingViewCount_thenIncreaseViewCount() throws Exception{ | ||
//given | ||
Long postId = 1L; | ||
Post post = createPost(postId); | ||
given(postRepository.getReferenceById(postId)).willReturn(post); | ||
|
||
//when | ||
sut.increaseViewCount(postId); | ||
|
||
//then | ||
then(postRepository).should().getReferenceById(postId); | ||
assertThat(post.getViewCount()).isEqualTo(1); | ||
} | ||
|
||
Post createPost(Long postId) { | ||
Post post = Post.of(createMember(), createBook(), "title", "content"); | ||
ReflectionTestUtils.setField(post, "id", postId); | ||
return post; | ||
} | ||
|
||
Book createBook() { | ||
return Book.of("title", "author", "pubisher", LocalDate.now(), "description", "link", "isbn13", 10000, "cover"); | ||
} | ||
|
||
Member createMember(Long memberId) { | ||
Member member = new Member("email", "name", "oauth2Id", AuthProvider.KAKAO); | ||
ReflectionTestUtils.setField(member, "id", memberId); | ||
return member; | ||
} | ||
|
||
Member createMember() { | ||
return createMember(1L); | ||
} | ||
} |