-
Notifications
You must be signed in to change notification settings - Fork 1
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
지원서 조회 / 게시글 댓글 테스트 코드 작성 #126
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8966836
Test: 게시글 댓글 그룹 생성, 조회 쿼리 테스트
kwonssshyeon 4721459
Refac: Comment 테스트 코드 리팩토링
kwonssshyeon 1be2cac
Refac: 지원서 상태는 지원서 클래스에서 변경, transaction manager 빈 등록
kwonssshyeon ac636c1
Test: 어드민 지원서 관련 복잡한 쿼리 테스트 코드 작성
kwonssshyeon 5e51384
Fix: 새로 추가된 UNDEFINED 트랙을 응답에 포함하는 문제 수정
kwonssshyeon f130fef
Fix: 지원 상태 업데이트 조건문 변경
kwonssshyeon 3b340b6
Fix: + 연결자 대신 String formatter 변경
kwonssshyeon 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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/gdsc_knu/official_homepage/config/TxTemplateConfig.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,15 @@ | ||
package com.gdsc_knu.official_homepage.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
|
||
@Configuration | ||
public class TxTemplateConfig { | ||
public final TransactionTemplate transactionTemplate; | ||
|
||
public TxTemplateConfig(PlatformTransactionManager transactionManager) { | ||
this.transactionTemplate = new TransactionTemplate(transactionManager); | ||
} | ||
|
||
} |
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
12 changes: 11 additions & 1 deletion
12
src/main/java/com/gdsc_knu/official_homepage/entity/enumeration/Track.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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package com.gdsc_knu.official_homepage.entity.enumeration; | ||
|
||
public enum Track { | ||
FRONT_END, BACK_END, ANDROID, AI, DESIGNER, UNDEFINED | ||
FRONT_END, BACK_END, ANDROID, AI, DESIGNER, UNDEFINED; | ||
|
||
public static Track[] getValidTrack() { | ||
return new Track[] { | ||
FRONT_END, | ||
BACK_END, | ||
ANDROID, | ||
AI, | ||
DESIGNER | ||
}; | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...com/gdsc_knu/official_homepage/repository/application/AdminApplicationRepositoryTest.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,79 @@ | ||
package com.gdsc_knu.official_homepage.repository.application; | ||
|
||
import com.gdsc_knu.official_homepage.OfficialHomepageApplication; | ||
import com.gdsc_knu.official_homepage.config.QueryDslConfig; | ||
import com.gdsc_knu.official_homepage.dto.admin.application.ApplicationStatisticType; | ||
import com.gdsc_knu.official_homepage.entity.application.Application; | ||
import com.gdsc_knu.official_homepage.entity.enumeration.ApplicationStatus; | ||
import com.gdsc_knu.official_homepage.repository.ApplicationRepository; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DataJpaTest | ||
@Import(QueryDslConfig.class) | ||
@ContextConfiguration(classes = OfficialHomepageApplication.class) | ||
public class AdminApplicationRepositoryTest { | ||
@Autowired private ApplicationRepository applicationRepository; | ||
|
||
@AfterEach | ||
void clear() { | ||
applicationRepository.deleteAll(); | ||
} | ||
|
||
|
||
@Test | ||
@DisplayName("지원 현황을 정상적으로 카운트한다.") | ||
void getStatistic() { | ||
// given | ||
int start = 1; | ||
int countPerStatus = 5; | ||
List<Application> temporal = createApplicationList(start, start+countPerStatus, ApplicationStatus.TEMPORAL); | ||
start+=countPerStatus; | ||
List<Application> save = createApplicationList(start, start+countPerStatus, ApplicationStatus.SAVED); | ||
start+=countPerStatus; | ||
List<Application> approve = createApplicationList(start, start+countPerStatus, ApplicationStatus.APPROVED); | ||
start+=countPerStatus; | ||
List<Application> reject = createApplicationList(start, start+countPerStatus, ApplicationStatus.REJECTED); | ||
List<Application> allApplications = Stream.of(temporal, save, approve, reject) | ||
.flatMap(List::stream) | ||
.toList(); | ||
applicationRepository.saveAll(allApplications); | ||
|
||
// when | ||
ApplicationStatisticType statistic = applicationRepository.getStatistics(); | ||
|
||
// then | ||
assertThat(statistic.getTotal()).isEqualTo(15); | ||
assertThat(statistic.getApprovedCount()).isEqualTo(5); | ||
assertThat(statistic.getRejectedCount()).isEqualTo(5); | ||
assertThat(statistic.getOpenCount()).isEqualTo(0); | ||
} | ||
|
||
private List<Application> createApplicationList(int startNum, int count, ApplicationStatus status){ | ||
List<Application> applicationList = new ArrayList<>(); | ||
for (int i=startNum; i<count; i++) { | ||
applicationList.add(createApplication(i, status)); | ||
} | ||
return applicationList; | ||
} | ||
|
||
private Application createApplication(int id, ApplicationStatus status) { | ||
return Application.builder() | ||
.email("test"+id+"@email.com") | ||
.studentNumber("202400"+id) | ||
.phoneNumber("010-0000-"+id) | ||
.applicationStatus(status) | ||
.build(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/test/java/com/gdsc_knu/official_homepage/repository/post/CommentRepositoryTest.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,93 @@ | ||
package com.gdsc_knu.official_homepage.repository.post; | ||
|
||
import com.gdsc_knu.official_homepage.OfficialHomepageApplication; | ||
import com.gdsc_knu.official_homepage.config.QueryDslConfig; | ||
import com.gdsc_knu.official_homepage.entity.Member; | ||
import com.gdsc_knu.official_homepage.entity.enumeration.Track; | ||
import com.gdsc_knu.official_homepage.entity.post.Comment; | ||
import com.gdsc_knu.official_homepage.entity.post.Post; | ||
import com.gdsc_knu.official_homepage.repository.CommentRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
|
||
@DataJpaTest | ||
@Import(QueryDslConfig.class) | ||
@ContextConfiguration(classes = OfficialHomepageApplication.class) | ||
public class CommentRepositoryTest { | ||
@Autowired private CommentRepository commentRepository; | ||
@Autowired private TestEntityManager entityManager; | ||
|
||
private Member author; | ||
private Post post; | ||
@BeforeEach | ||
void setUp() { | ||
author = Member.builder() | ||
.email("[email protected]") | ||
.name("테스트 유저") | ||
.track(Track.BACK_END) | ||
.build(); | ||
entityManager.persistAndFlush(author); | ||
|
||
post = Post.builder() | ||
.member(author) | ||
.build(); | ||
entityManager.persistAndFlush(post); | ||
} | ||
|
||
@Test | ||
@DisplayName("댓글의 순서가 올바르게 조회된다") | ||
void findCommentAndReply() { | ||
// given | ||
Comment parent1 = Comment.from("1",author,post,null); | ||
Comment child1 = Comment.from("2",author,post,parent1); | ||
Comment child2 = Comment.from("3",author,post,parent1); | ||
Comment parent2 = Comment.from("4",author,post,null); | ||
Comment child3 = Comment.from("5",author,post,parent2); | ||
Comment child4 = Comment.from("6",author,post,parent2); | ||
|
||
commentRepository.saveAll(List.of(parent1, parent2, child1, child2, child3, child4)); | ||
// 2,5 댓글의 생성 시각 나중으로 변경 | ||
ReflectionTestUtils.setField(child3, "createAt", LocalDateTime.now()); | ||
ReflectionTestUtils.setField(child1, "createAt", LocalDateTime.now()); | ||
|
||
// when | ||
Page<Comment> commentList = commentRepository.findCommentAndReply(PageRequest.of(0,6), post.getId()); | ||
|
||
// then | ||
assertThat(commentList).extracting("content") | ||
.containsExactly("1","3","2","4","6","5"); | ||
} | ||
|
||
|
||
@Test | ||
@DisplayName("부모 댓글 생성 시 자신을 그룹으로 한다.") | ||
void save() { | ||
// given | ||
Comment parent = Comment.from("댓글내용",author,post,null); | ||
Comment child = Comment.from("댓글내용",author,post,parent); | ||
|
||
// when | ||
commentRepository.saveAll(List.of(parent, child)); | ||
|
||
// then | ||
assertThat(parent.getParent()).isEqualTo(parent); | ||
assertThat(child.getParent()).isEqualTo(parent); | ||
} | ||
|
||
|
||
} |
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.
사소하긴 한데 그냥 id를 쓰는것 보단 String.format 함수 써서 각각 자릿수 양식에 맞게 만드는 게 조금 더 좋지 않을까 생각해봅니다.