Skip to content

Commit e3104ec

Browse files
committed
test(VolunteerQueryService): 봉사 시간 기준 봉사자 조회
- 상위 4명 조회 - 봉사자 없으면 빈 리스트 반환
1 parent 3dfb0b2 commit e3104ec

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/test/java/com/somemore/volunteer/service/VolunteerQueryServiceTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import com.somemore.volunteer.domain.VolunteerDetail;
88
import com.somemore.volunteer.dto.request.VolunteerRegisterRequestDto;
99
import com.somemore.volunteer.dto.response.VolunteerProfileResponseDto;
10+
import com.somemore.volunteer.dto.response.VolunteerRankingResponseDto;
1011
import com.somemore.volunteer.repository.VolunteerDetailRepository;
1112
import com.somemore.volunteer.repository.VolunteerRepository;
1213
import org.junit.jupiter.api.DisplayName;
1314
import org.junit.jupiter.api.Test;
1415
import org.springframework.beans.factory.annotation.Autowired;
1516
import org.springframework.transaction.annotation.Transactional;
1617

18+
import java.util.List;
1719
import java.util.UUID;
1820

1921
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;
@@ -152,6 +154,40 @@ void getVolunteerDetailedProfile() {
152154
.hasMessage(UNAUTHORIZED_VOLUNTEER_DETAIL.getMessage());
153155
}
154156

157+
@DisplayName("봉사 시간 기준 상위 4명의 랭킹을 조회한다.")
158+
@Test
159+
void getRankingByHours() {
160+
// given
161+
for (int i = 1; i <= 5; i++) {
162+
Volunteer volunteer = Volunteer.createDefault(oAuthProvider, "oauth-id-" + i);
163+
volunteer.updateVolunteerStats(i * 10, i);
164+
volunteerRepository.save(volunteer);
165+
}
166+
167+
// when
168+
VolunteerRankingResponseDto response = volunteerQueryService.getRankingByHours();
169+
170+
// then
171+
assertThat(response).isNotNull();
172+
assertThat(response.rankings()).hasSize(4);
173+
174+
List<Integer> hours = response.rankings().stream()
175+
.map(VolunteerRankingResponseDto.VolunteerOverview::totalVolunteerHours)
176+
.toList();
177+
assertThat(hours).isSortedAccordingTo((a, b) -> b - a);
178+
}
179+
180+
@DisplayName("등록된 봉사자가 없는 경우 빈 랭킹 리스트를 반환한다.")
181+
@Test
182+
void getRankingByHours_noVolunteers() {
183+
// when
184+
VolunteerRankingResponseDto response = volunteerQueryService.getRankingByHours();
185+
186+
// then
187+
assertThat(response).isNotNull();
188+
assertThat(response.rankings()).isEmpty();
189+
}
190+
155191
private static VolunteerDetail createVolunteerDetail(UUID volunteerId) {
156192

157193
VolunteerRegisterRequestDto volunteerRegisterRequestDto =

0 commit comments

Comments
 (0)