|
1 | 1 | package com.example.solidconnection.admin.service; |
2 | 2 |
|
| 3 | +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_CONFIRMED; |
| 4 | +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_FOUND; |
| 5 | +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED; |
3 | 6 | import static org.assertj.core.api.Assertions.assertThat; |
| 7 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertAll; |
4 | 9 |
|
| 10 | +import com.example.solidconnection.admin.dto.MentorApplicationCountResponse; |
| 11 | +import com.example.solidconnection.admin.dto.MentorApplicationRejectRequest; |
5 | 12 | import com.example.solidconnection.admin.dto.MentorApplicationSearchCondition; |
6 | 13 | import com.example.solidconnection.admin.dto.MentorApplicationSearchResponse; |
| 14 | +import com.example.solidconnection.common.exception.CustomException; |
7 | 15 | import com.example.solidconnection.mentor.domain.MentorApplication; |
8 | 16 | import com.example.solidconnection.mentor.domain.MentorApplicationStatus; |
9 | 17 | import com.example.solidconnection.mentor.domain.UniversitySelectType; |
10 | 18 | import com.example.solidconnection.mentor.fixture.MentorApplicationFixture; |
| 19 | +import com.example.solidconnection.mentor.repository.MentorApplicationRepository; |
11 | 20 | import com.example.solidconnection.siteuser.domain.SiteUser; |
12 | 21 | import com.example.solidconnection.siteuser.fixture.SiteUserFixture; |
13 | 22 | import com.example.solidconnection.support.TestContainerSpringBootTest; |
@@ -40,6 +49,9 @@ class AdminMentorApplicationServiceTest { |
40 | 49 | @Autowired |
41 | 50 | private UniversityFixture universityFixture; |
42 | 51 |
|
| 52 | + @Autowired |
| 53 | + private MentorApplicationRepository mentorApplicationRepository; |
| 54 | + |
43 | 55 | private MentorApplication mentorApplication1; |
44 | 56 | private MentorApplication mentorApplication2; |
45 | 57 | private MentorApplication mentorApplication3; |
@@ -209,4 +221,160 @@ class 멘토_승격_지원서_목록_조회 { |
209 | 221 | .containsOnly(regionKoreanName); |
210 | 222 | } |
211 | 223 | } |
| 224 | + |
| 225 | + @Nested |
| 226 | + class 멘토_승격_지원서_승인{ |
| 227 | + |
| 228 | + @Test |
| 229 | + void 대기중인_멘토_지원서를_승인한다() { |
| 230 | + // given |
| 231 | + long pendingMentorApplicationId = mentorApplication2.getId(); |
| 232 | + |
| 233 | + // when |
| 234 | + adminMentorApplicationService.approveMentorApplication(pendingMentorApplicationId); |
| 235 | + |
| 236 | + // then |
| 237 | + MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get(); |
| 238 | + assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.APPROVED); |
| 239 | + assertThat(result.getApprovedAt()).isNotNull(); |
| 240 | + } |
| 241 | + |
| 242 | + @Test |
| 243 | + void 대학이_선택되지_않은_멘토_지원서를_승인하면_예외가_발생한다(){ |
| 244 | + // given |
| 245 | + SiteUser user = siteUserFixture.사용자(); |
| 246 | + MentorApplication noUniversityIdMentorApplication = mentorApplicationFixture.대기중_멘토신청(user.getId(), UniversitySelectType.OTHER, null); |
| 247 | + |
| 248 | + // when & then |
| 249 | + assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(noUniversityIdMentorApplication.getId())) |
| 250 | + .isInstanceOf(CustomException.class) |
| 251 | + .hasMessage(MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED.getMessage()); |
| 252 | + } |
| 253 | + |
| 254 | + @Test |
| 255 | + void 이미_승인된_멘토_지원서를_승인하면_예외가_발생한다() { |
| 256 | + // given |
| 257 | + long approvedMentorApplicationId = mentorApplication1.getId(); |
| 258 | + |
| 259 | + // when & then |
| 260 | + assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(approvedMentorApplicationId)) |
| 261 | + .isInstanceOf(CustomException.class) |
| 262 | + .hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage()); |
| 263 | + } |
| 264 | + |
| 265 | + @Test |
| 266 | + void 이미_거절된_멘토_지원서를_승인하면_예외가_발생한다() { |
| 267 | + // given |
| 268 | + long rejectedMentorApplicationId = mentorApplication3.getId(); |
| 269 | + |
| 270 | + // when & then |
| 271 | + assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(rejectedMentorApplicationId)) |
| 272 | + .isInstanceOf(CustomException.class) |
| 273 | + .hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage()); |
| 274 | + } |
| 275 | + |
| 276 | + @Test |
| 277 | + void 존재하지_않는_멘토_지원서를_승인하면_예외가_발생한다() { |
| 278 | + // given |
| 279 | + long nonExistentId = 99999L; |
| 280 | + |
| 281 | + // when & then |
| 282 | + assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(nonExistentId)) |
| 283 | + .isInstanceOf(CustomException.class) |
| 284 | + .hasMessage(MENTOR_APPLICATION_NOT_FOUND.getMessage()); |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + @Nested |
| 289 | + class 멘토_승격_지원서_거절{ |
| 290 | + |
| 291 | + @Test |
| 292 | + void 대기중인_멘토_지원서를_거절한다() { |
| 293 | + // given |
| 294 | + long pendingMentorApplicationId = mentorApplication2.getId(); |
| 295 | + MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락"); |
| 296 | + |
| 297 | + // when |
| 298 | + adminMentorApplicationService.rejectMentorApplication(pendingMentorApplicationId, request); |
| 299 | + |
| 300 | + // then |
| 301 | + MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get(); |
| 302 | + assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.REJECTED); |
| 303 | + assertThat(result.getRejectedReason()).isEqualTo(request.rejectedReason()); |
| 304 | + } |
| 305 | + |
| 306 | + @Test |
| 307 | + void 이미_승인된_멘토_지원서를_거절하면_예외가_발생한다() { |
| 308 | + // given |
| 309 | + long approvedMentorApplicationId = mentorApplication1.getId(); |
| 310 | + MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락"); |
| 311 | + |
| 312 | + // when & then |
| 313 | + assertThatCode(() -> adminMentorApplicationService.rejectMentorApplication(approvedMentorApplicationId, request)) |
| 314 | + .isInstanceOf(CustomException.class) |
| 315 | + .hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage()); |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + void 이미_거절된_멘토_지원서를_거절하면_예외가_발생한다() { |
| 320 | + // given |
| 321 | + long rejectedMentorApplicationId = mentorApplication3.getId(); |
| 322 | + MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락"); |
| 323 | + |
| 324 | + // when & then |
| 325 | + assertThatCode(() -> adminMentorApplicationService.rejectMentorApplication(rejectedMentorApplicationId, request)) |
| 326 | + .isInstanceOf(CustomException.class) |
| 327 | + .hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage()); |
| 328 | + } |
| 329 | + |
| 330 | + @Test |
| 331 | + void 존재하지_않는_멘토_지원서를_거절하면_예외가_발생한다() { |
| 332 | + // given |
| 333 | + long nonExistentId = 99999L; |
| 334 | + MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락"); |
| 335 | + |
| 336 | + // when & then |
| 337 | + assertThatCode(() -> adminMentorApplicationService.rejectMentorApplication(nonExistentId, request)) |
| 338 | + .isInstanceOf(CustomException.class) |
| 339 | + .hasMessage(MENTOR_APPLICATION_NOT_FOUND.getMessage()); |
| 340 | + } |
| 341 | + } |
| 342 | + |
| 343 | + @Nested |
| 344 | + class 멘토_지원서_상태별_개수_조회 { |
| 345 | + |
| 346 | + @Test |
| 347 | + void 상태별_멘토_지원서_개수를_조회한다() { |
| 348 | + // given |
| 349 | + List<MentorApplication> expectedApprovedCount = List.of(mentorApplication1, mentorApplication4); |
| 350 | + List<MentorApplication> expectedPendingCount = List.of(mentorApplication2, mentorApplication5); |
| 351 | + List<MentorApplication> expectedRejectedCount = List.of(mentorApplication3, mentorApplication6); |
| 352 | + |
| 353 | + // when |
| 354 | + MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount(); |
| 355 | + |
| 356 | + // then |
| 357 | + assertAll( |
| 358 | + () -> assertThat(response.approvedCount()).isEqualTo(expectedApprovedCount.size()), |
| 359 | + () -> assertThat(response.pendingCount()).isEqualTo(expectedPendingCount.size()), |
| 360 | + () -> assertThat(response.rejectedCount()).isEqualTo(expectedRejectedCount.size()) |
| 361 | + ); |
| 362 | + } |
| 363 | + |
| 364 | + @Test |
| 365 | + void 멘토_지원서가_없으면_모든_개수가_0이다() { |
| 366 | + // given |
| 367 | + mentorApplicationRepository.deleteAll(); |
| 368 | + |
| 369 | + // when |
| 370 | + MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount(); |
| 371 | + |
| 372 | + // then |
| 373 | + assertAll( |
| 374 | + () -> assertThat(response.approvedCount()).isEqualTo(0L), |
| 375 | + () -> assertThat(response.pendingCount()).isEqualTo(0L), |
| 376 | + () -> assertThat(response.rejectedCount()).isEqualTo(0L) |
| 377 | + ); |
| 378 | + } |
| 379 | + } |
212 | 380 | } |
0 commit comments