Skip to content

Commit 3dfb0b2

Browse files
committed
test(VolunteerRepository): 봉사 시간 기준 봉사자 조회
- 상위 4명 조회 - 봉사자 없으면 빈 리스트 반환 - 봉사자 4명 미만이면 전체 조회
1 parent ff98bcf commit 3dfb0b2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/test/java/com/somemore/volunteer/repository/VolunteerRepositoryTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import com.somemore.IntegrationTestSupport;
44
import com.somemore.auth.oauth.OAuthProvider;
55
import com.somemore.volunteer.domain.Volunteer;
6+
import com.somemore.volunteer.repository.mapper.VolunteerOverviewForRankingByHours;
67
import org.junit.jupiter.api.BeforeEach;
78
import org.junit.jupiter.api.DisplayName;
89
import org.junit.jupiter.api.Test;
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.transaction.annotation.Transactional;
1112

13+
import java.util.List;
1214
import java.util.Optional;
1315
import java.util.UUID;
1416

@@ -76,4 +78,57 @@ void findByOauthId() {
7678
assertThat(foundVolunteer.get().getOauthId()).isEqualTo(oAuthId);
7779
assertThat(foundVolunteer.get().getNickname()).isEqualTo(volunteer.getNickname());
7880
}
81+
82+
@DisplayName("봉사 시간 기준 상위 4명을 조회한다.")
83+
@Test
84+
void findRankingByVolunteerHours_top4() {
85+
// given
86+
for (int i = 1; i <= 5; i++) {
87+
createVolunteerAndUpdateVolunteerStats(i);
88+
}
89+
90+
// when
91+
List<VolunteerOverviewForRankingByHours> rankings = volunteerRepository.findRankingByVolunteerHours();
92+
93+
// then
94+
assertThat(rankings).hasSize(4);
95+
assertThat(rankings.get(0).totalVolunteerHours()).isGreaterThan(rankings.get(1).totalVolunteerHours());
96+
}
97+
98+
@DisplayName("등록된 봉사자가 없는 경우 빈 리스트를 반환한다.")
99+
@Test
100+
void findRankingByVolunteerHours_noVolunteers() {
101+
// given
102+
volunteerRepository.deleteAllInBatch();
103+
104+
// when
105+
List<VolunteerOverviewForRankingByHours> rankings = volunteerRepository.findRankingByVolunteerHours();
106+
107+
// then
108+
assertThat(rankings).isEmpty();
109+
}
110+
111+
@DisplayName("등록된 봉사자가 4명 이하인 경우 전체 봉사자를 반환한다.")
112+
@Test
113+
void findRankingByVolunteerHours_lessThan4Volunteers() {
114+
// given
115+
volunteerRepository.deleteAllInBatch();
116+
117+
for (int i = 1; i <= 3; i++) {
118+
createVolunteerAndUpdateVolunteerStats(i);
119+
}
120+
121+
// when
122+
List<VolunteerOverviewForRankingByHours> rankings = volunteerRepository.findRankingByVolunteerHours();
123+
124+
// then
125+
assertThat(rankings).hasSize(3);
126+
assertThat(rankings.get(0).totalVolunteerHours()).isGreaterThan(rankings.get(1).totalVolunteerHours());
127+
}
128+
129+
private void createVolunteerAndUpdateVolunteerStats(int i) {
130+
Volunteer volunteer = Volunteer.createDefault(OAuthProvider.NAVER, "oauth-id-" + i);
131+
volunteer.updateVolunteerStats(i * 10, i);
132+
volunteerRepository.save(volunteer);
133+
}
79134
}

0 commit comments

Comments
 (0)