|
7 | 7 | import com.somemore.volunteer.domain.VolunteerDetail; |
8 | 8 | import com.somemore.volunteer.dto.request.VolunteerRegisterRequestDto; |
9 | 9 | import com.somemore.volunteer.dto.response.VolunteerProfileResponseDto; |
| 10 | +import com.somemore.volunteer.dto.response.VolunteerRankingResponseDto; |
10 | 11 | import com.somemore.volunteer.repository.VolunteerDetailRepository; |
11 | 12 | import com.somemore.volunteer.repository.VolunteerRepository; |
12 | 13 | import org.junit.jupiter.api.DisplayName; |
13 | 14 | import org.junit.jupiter.api.Test; |
14 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
15 | 16 | import org.springframework.transaction.annotation.Transactional; |
16 | 17 |
|
| 18 | +import java.util.List; |
17 | 19 | import java.util.UUID; |
18 | 20 |
|
19 | 21 | import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; |
@@ -152,6 +154,40 @@ void getVolunteerDetailedProfile() { |
152 | 154 | .hasMessage(UNAUTHORIZED_VOLUNTEER_DETAIL.getMessage()); |
153 | 155 | } |
154 | 156 |
|
| 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 | + |
155 | 191 | private static VolunteerDetail createVolunteerDetail(UUID volunteerId) { |
156 | 192 |
|
157 | 193 | VolunteerRegisterRequestDto volunteerRegisterRequestDto = |
|
0 commit comments