-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: 스크랩 관련 Domain, Service 유닛 테스트 코드 작성 #155
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2e5c027
[#130] fix: 최신순 조회 문제 해결
yumzen 394ea11
fix: merge conflict 해결
yumzen adc0723
test: PostUtilTest builderPost 생성
yumzen 26e412b
[#135] test: PostServiceTest 초기화
yumzen cbc99ec
[#139] test: postService scrapPost메소드 테스트 코드 작성
yumzen 924d081
[#139] test: 스크랩 기능 Controller Test 코드
yumzen 412026d
fix: 스크랩 페이지네이션 전체 페이지수 반환 오류 수정
yumzen 09be46a
feat: PostScrapDomainTest 작성
yumzen 1365b3e
fix: 스크랩 페이지네이션 JPA 메소드 수정
yumzen ec05b30
fix: merge conflict 해결
yumzen d0227df
저장
yumzen 45d2782
merge conflict
yumzen 6eff3f8
fix: merge conflict 해결
yumzen 26c7a0e
Merge branch 'main' of https://github.com/Gongjakso/server into feat/…
yumzen f011ac9
merge conflict
yumzen f855618
스크랩 관련 테스트 코드 작성
yumzen 4354a9d
merge conflict
yumzen 4fc35de
merge conflict
yumzen 6af4ca9
fix: 페이지네이션 테스트 코드 수정
yumzen 8af601f
Merge branch 'test/post-pagination' of https://github.com/Gongjakso/s…
yumzen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 식으로 쿼리로 리팩토링하신 것 좋은 방법인 것 같습니다! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,22 @@ public static Member buildMember() { | |
.build(); | ||
} | ||
|
||
public static Member buildMemberAndId(Long id) { | ||
return new Member( | ||
id, | ||
"[email protected]", | ||
"password123", | ||
"공작소", | ||
"010-1234-5678", | ||
"http://example.com", | ||
MemberType.GENERAL.toString(), | ||
LoginType.KAKAO.toString(), | ||
"상태", | ||
"전공", | ||
"직업" | ||
); | ||
} | ||
|
||
public static MemberReq buildMemberReq() { | ||
return MemberReq.builder() | ||
.name("변경 공작소") | ||
|
68 changes: 68 additions & 0 deletions
68
src/test/java/com/gongjakso/server/domain/post/controller/PaginationControllerTest.java
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Security가 있어서 통합 테스트하려면 Security 테스트 환경을 구축해야 합니다! 제가 아직 안 해놔서.. 꼭 시간 나면 해놓을게요 |
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,68 @@ | ||
package com.gongjakso.server.domain.post.controller; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
|
||
@AutoConfigureMockMvc | ||
@ExtendWith(MockitoExtension.class) | ||
public class PaginationControllerTest { | ||
/* | ||
MockMvc mockMvc; | ||
|
||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@MockBean | ||
private PostService postService; | ||
|
||
@MockBean | ||
private PostRepository postRepository; | ||
|
||
@MockBean | ||
private MemberRepository memberRepository; | ||
|
||
@MockBean | ||
private ApplyService applyService; | ||
|
||
@MockBean | ||
private TokenProvider tokenProvider; | ||
|
||
@MockBean | ||
private RedisClient redisClient; | ||
|
||
@MockBean | ||
private JwtFilter jwtFilter; | ||
|
||
private Member member; | ||
private PrincipalDetails principalDetails; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
member = MemberUtilTest.buildMemberAndId(1L); | ||
principalDetails = new PrincipalDetails(member); | ||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( | ||
principalDetails, null, principalDetails.getAuthorities()); | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
} | ||
|
||
@Test | ||
@DisplayName("공고 스크랩 저장 및 취소 기능") | ||
void scrapPost() throws Exception { | ||
//given | ||
Post post = PostUtilTest.builderPost(1L, member); | ||
PostScrapRes postScrapRes = PostScrapUtilTest.ScrapPostRes(post.getPostId(), member.getMemberId(), true); | ||
given(postService.scrapPost(any(Member.class), anyLong())).willReturn(postScrapRes); | ||
String resJson = objectMapper.writeValueAsString(postScrapRes); | ||
|
||
mockMvc.perform(post("/api/v1/post/{id}", post.getPostId()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.principal((Principal) principalDetails)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().json(resJson)) | ||
.andDo(print()); | ||
|
||
verify(postService).scrapPost(any(Member.class), any(Long.class)); | ||
} | ||
|
||
*/ | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/gongjakso/server/domain/post/domain/ScrapDomainTest.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,55 @@ | ||
package com.gongjakso.server.domain.post.domain; | ||
|
||
|
||
import com.gongjakso.server.domain.member.entity.Member; | ||
import com.gongjakso.server.domain.member.util.MemberUtilTest; | ||
import com.gongjakso.server.domain.post.entity.Post; | ||
import com.gongjakso.server.domain.post.entity.PostScrap; | ||
import com.gongjakso.server.domain.post.util.PostScrapUtilTest; | ||
import com.gongjakso.server.domain.post.util.PostUtilTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DisplayName("PostScrap 도메인 테스트") | ||
public class ScrapDomainTest{ | ||
|
||
private Post post; | ||
private Member member; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
member = MemberUtilTest.buildMemberAndId(1L); | ||
post = PostUtilTest.builderPost(1L, member); | ||
} | ||
|
||
@Nested | ||
@DisplayName("Builder테스트") | ||
class BuilderTests { | ||
|
||
@Test | ||
@DisplayName("Id없이 빌드 되어야 함") | ||
public void testPostScrapBuilder() { | ||
PostScrap postScrap = PostScrapUtilTest.builderPostScrap(post, post.getMember()); | ||
System.out.println(postScrap.getMember()); | ||
System.out.println(member); | ||
assertThat(postScrap.getPost()).isEqualTo(post); | ||
assertThat(postScrap.getMember()).isEqualTo(member); | ||
assertThat(postScrap.getScrapStatus()).isTrue(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Id와 함께 빌드 되어야 함") | ||
public void testPostScrapBuilderWithId() { | ||
Long postScrapId = 1L; | ||
PostScrap postScrap = PostScrapUtilTest.builderPostScrapWithPostAndMember(postScrapId, post, post.getMember()); | ||
assertThat(postScrap.getPostScrapId()).isEqualTo(postScrapId); | ||
assertThat(postScrap.getPost()).isEqualTo(post); | ||
assertThat(postScrap.getMember()).isEqualTo(member); | ||
assertThat(postScrap.getScrapStatus()).isTrue(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별도의 Builder 패턴을 사용하지 않고 이렇게 생성자를 만드신 이유 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builder 패턴 사용했을 때 id값이 자동으로 설정이 안되어서 수동으로 id값을 설정해주기 위해 사용했습니다 이 부분에 대해서는 한번 다시 찾아보고 수정해보겠습니다!!