Skip to content

Commit

Permalink
[Test]: 도메인 변경에 따른 테스트 깨짐 현상 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
momnpa333 committed Sep 4, 2024
1 parent bd51e55 commit 2d67ebe
Showing 1 changed file with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@
@SpringBootTest
@Transactional
class ChallengeGroupQueryServiceTest {

@Autowired
ChallengeGroupQueryService challengeGroupQueryService;
@Autowired ChallengeGroupRepository challengeGroupRepository;
@Autowired ChallengeRepository challengeRepository;
@Autowired ChallengeGroupImageRepository challengeGroupImageRepository;
@Autowired EntityManager em;
@Autowired
ChallengeGroupRepository challengeGroupRepository;
@Autowired
ChallengeRepository challengeRepository;
@Autowired
ChallengeGroupImageRepository challengeGroupImageRepository;
@Autowired
EntityManager em;

@DisplayName("챌린지 그룹 목록 페이징이 정상적으로 동작한다.")
@Test
void getChallengeGroupsPaging() {
// given
for(int i = 0; i < 20; i++) {
ChallengeGroup challengeGroup = createChallengeGroup("title" + i, ChallengeCategory.ECHO);
for (int i = 0; i < 20; i++) {
ChallengeGroup challengeGroup = createChallengeGroup("title" + i,
ChallengeCategory.ECHO);
challengeGroupRepository.save(challengeGroup);
}
for(int i = 0; i < 10; i++) {
ChallengeGroup challengeGroup = createChallengeGroup("title" + i, ChallengeCategory.VOLUNTEER);
for (int i = 0; i < 10; i++) {
ChallengeGroup challengeGroup = createChallengeGroup("title" + i,
ChallengeCategory.VOLUNTEER);
challengeGroupRepository.save(challengeGroup);
}

Expand All @@ -48,7 +55,8 @@ void getChallengeGroupsPaging() {
em.clear();

// then
Page<ChallengeGroupModel.Info> challengeGroupsPaging = challengeGroupQueryService.getChallengeGroupsPaging(pageable, category);
Page<ChallengeGroupModel.Info> challengeGroupsPaging = challengeGroupQueryService.getChallengeGroupsPaging(
pageable, category);

assertEquals(10, challengeGroupsPaging.getContent().size());
assertEquals(2, challengeGroupsPaging.getTotalPages());
Expand All @@ -63,23 +71,25 @@ void getChallengeGroupDetail() {
challengeGroupRepository.save(challengeGroup);

Challenge challenge = Challenge.builder()
.challengeGroup(challengeGroup)
.requiredCount(12)
.successExp(100)
.onceExp(10)
.difficulty(3)
.build();
.challengeGroup(challengeGroup)
.requiredCount(12)
.successExp(100)
.onceExp(10)
.difficulty(3)
.activePeriod(7)
.build();
challengeRepository.save(challenge);

ChallengeGroupImage challengeGroupImage = ChallengeGroupImage.builder()
.challengeGroup(challengeGroup)
.imageUrl("image-url")
.build();
.challengeGroup(challengeGroup)
.imageUrl("image-url")
.build();
challengeGroupImageRepository.save(challengeGroupImage);

em.clear();
// when
ChallengeGroupModel.Detail model = challengeGroupQueryService.getChallengeGroupDetail(challengeGroup.getId());
ChallengeGroupModel.Detail model = challengeGroupQueryService.getChallengeGroupDetail(
challengeGroup.getId());

// then
assertEquals(challengeGroup.getId(), model.id());
Expand All @@ -103,14 +113,15 @@ void getChallengeGroupRanking() {
}



private ChallengeGroup createChallengeGroup(String title, ChallengeCategory category) {
return ChallengeGroup.builder()
.title(title)
.category(category)
.content("content")
.guide("guide")
.cumulativeCount(0)
.build();
.title(title)
.category(category)
.content("content")
.guide("guide")
.cumulativeCount(0)
.joinStartDate(LocalDate.now())
.joinEndDate(LocalDate.now().plusDays(10))
.build();
}
}

0 comments on commit 2d67ebe

Please sign in to comment.