Skip to content

Commit b379cf4

Browse files
committed
test: 변경된 로직에 따라 테스트 케이스 수정
1 parent 4a28529 commit b379cf4

File tree

2 files changed

+96
-85
lines changed

2 files changed

+96
-85
lines changed

src/test/java/dmu/dasom/api/domain/applicant/ApplicantServiceTest.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import dmu.dasom.api.domain.email.enums.MailType;
1414
import dmu.dasom.api.domain.email.service.EmailService;
1515
import dmu.dasom.api.domain.google.service.GoogleApiService;
16+
import dmu.dasom.api.domain.recruit.dto.ResultCheckRequestDto;
17+
import dmu.dasom.api.domain.recruit.dto.ResultCheckResponseDto;
18+
import dmu.dasom.api.domain.recruit.enums.ResultCheckType;
19+
import dmu.dasom.api.domain.recruit.service.RecruitServiceImpl;
1620
import dmu.dasom.api.global.dto.PageResponse;
1721
import jakarta.mail.MessagingException;
1822
import org.junit.jupiter.api.BeforeEach;
@@ -44,6 +48,9 @@ class ApplicantServiceTest {
4448
@Mock
4549
private EmailService emailService;
4650

51+
@Mock
52+
private RecruitServiceImpl recruitService;
53+
4754
@InjectMocks
4855
private ApplicantServiceImpl applicantService;
4956

@@ -61,6 +68,7 @@ void apply_success() {
6168
// given
6269
ApplicantCreateRequestDto request = mock(ApplicantCreateRequestDto.class);
6370
when(request.getStudentNo()).thenReturn("20210000");
71+
when(recruitService.isRecruitmentActive()).thenReturn(true);
6472

6573
Applicant mockApplicant = Applicant.builder()
6674
.name("홍길동")
@@ -100,6 +108,7 @@ void apply_fail() {
100108
ApplicantCreateRequestDto request = mock(ApplicantCreateRequestDto.class);
101109
when(request.getStudentNo()).thenReturn("20210000");
102110
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(mock(Applicant.class)));
111+
when(recruitService.isRecruitmentActive()).thenReturn(true);
103112
when(request.getIsOverwriteConfirmed()).thenReturn(false);
104113

105114
// when
@@ -120,6 +129,7 @@ void apply_overwrite() {
120129
when(request.getStudentNo()).thenReturn("20210000");
121130
Applicant existingApplicant = mock(Applicant.class); // 기존 Applicant 객체 모킹
122131
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(existingApplicant));
132+
when(recruitService.isRecruitmentActive()).thenReturn(true);
123133
when(request.getIsOverwriteConfirmed()).thenReturn(true);
124134

125135
// when
@@ -334,6 +344,7 @@ void apply_overwrite_withGoogleSheets() {
334344
// given
335345
ApplicantCreateRequestDto request = mock(ApplicantCreateRequestDto.class);
336346
when(request.getStudentNo()).thenReturn("20210000");
347+
when(recruitService.isRecruitmentActive()).thenReturn(true);
337348

338349
Applicant existingApplicant = mock(Applicant.class); // 기존 Applicant 객체 모킹
339350
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(existingApplicant));
@@ -348,4 +359,89 @@ void apply_overwrite_withGoogleSheets() {
348359
verify(googleApiService).updateSheet(List.of(existingApplicant));
349360
}
350361

362+
@Test
363+
@DisplayName("합격 결과 확인 - 성공")
364+
void checkResult_success() {
365+
// given
366+
LocalDateTime pastDateTime = LocalDateTime.now().minusHours(1);
367+
when(recruitService.getResultAnnouncementSchedule(ResultCheckType.DOCUMENT_PASS)).thenReturn(pastDateTime);
368+
369+
ResultCheckRequestDto request = mock(ResultCheckRequestDto.class);
370+
when(request.getType()).thenReturn(ResultCheckType.DOCUMENT_PASS);
371+
when(request.getStudentNo()).thenReturn("20210000");
372+
when(request.getContactLastDigit()).thenReturn("1234");
373+
374+
Applicant applicant = mock(Applicant.class);
375+
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(applicant));
376+
377+
ApplicantDetailsResponseDto responseDto = mock(ApplicantDetailsResponseDto.class);
378+
when(responseDto.getContact()).thenReturn("010-5678-1234");
379+
when(responseDto.getStatus()).thenReturn(ApplicantStatus.DOCUMENT_PASSED);
380+
when(responseDto.getStudentNo()).thenReturn("20210000");
381+
when(responseDto.getName()).thenReturn("TestName");
382+
383+
when(applicant.toApplicantDetailsResponse()).thenReturn(responseDto);
384+
385+
when(recruitService.generateReservationCode("20210000", "1234")).thenReturn("202100001234");
386+
387+
// when
388+
ResultCheckResponseDto result = applicantService.checkResult(request);
389+
390+
// then
391+
assertNotNull(result);
392+
assertTrue(result.getIsPassed());
393+
verify(recruitService).getResultAnnouncementSchedule(ResultCheckType.DOCUMENT_PASS);
394+
verify(applicantRepository).findByStudentNo("20210000");
395+
}
396+
397+
@Test
398+
@DisplayName("합격 결과 확인 - 실패 (확인 기간 아님)")
399+
void checkResult_fail_inquiryPeriod() {
400+
// given
401+
LocalDateTime futureDateTime = LocalDateTime.now().plusHours(1);
402+
when(recruitService.getResultAnnouncementSchedule(ResultCheckType.DOCUMENT_PASS)).thenReturn(futureDateTime);
403+
404+
ResultCheckRequestDto request = mock(ResultCheckRequestDto.class);
405+
when(request.getType()).thenReturn(ResultCheckType.DOCUMENT_PASS);
406+
407+
// when
408+
CustomException exception = assertThrows(CustomException.class, () -> {
409+
applicantService.checkResult(request);
410+
});
411+
412+
// then
413+
assertEquals(ErrorCode.INVALID_INQUIRY_PERIOD, exception.getErrorCode());
414+
verify(recruitService).getResultAnnouncementSchedule(ResultCheckType.DOCUMENT_PASS);
415+
}
416+
417+
@Test
418+
@DisplayName("합격 결과 확인 - 실패 (연락처 뒷자리 불일치)")
419+
void checkResult_fail_contactMismatch() {
420+
// given
421+
LocalDateTime pastDateTime = LocalDateTime.now().minusHours(1);
422+
when(recruitService.getResultAnnouncementSchedule(ResultCheckType.DOCUMENT_PASS)).thenReturn(pastDateTime);
423+
424+
ResultCheckRequestDto request = mock(ResultCheckRequestDto.class);
425+
when(request.getType()).thenReturn(ResultCheckType.DOCUMENT_PASS);
426+
when(request.getStudentNo()).thenReturn("20210000");
427+
when(request.getContactLastDigit()).thenReturn("0000");
428+
429+
Applicant applicant = mock(Applicant.class);
430+
when(applicantRepository.findByStudentNo("20210000")).thenReturn(Optional.of(applicant));
431+
432+
ApplicantDetailsResponseDto responseDto = mock(ApplicantDetailsResponseDto.class);
433+
when(responseDto.getContact()).thenReturn("010-5678-1234");
434+
when(applicant.toApplicantDetailsResponse()).thenReturn(responseDto);
435+
436+
// when
437+
CustomException exception = assertThrows(CustomException.class, () -> {
438+
applicantService.checkResult(request);
439+
});
440+
441+
// then
442+
assertEquals(ErrorCode.ARGUMENT_NOT_VALID, exception.getErrorCode());
443+
verify(recruitService).getResultAnnouncementSchedule(ResultCheckType.DOCUMENT_PASS);
444+
verify(applicantRepository).findByStudentNo("20210000");
445+
}
446+
351447
}

src/test/java/dmu/dasom/api/domain/recruit/RecruitServiceTest.java

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -102,91 +102,6 @@ void modifyRecruitSchedule_fail() {
102102
assertEquals(ErrorCode.INVALID_TIME_FORMAT, exception.getErrorCode());
103103
}
104104

105-
@Test
106-
@DisplayName("합격 결과 확인 - 성공")
107-
void checkResult_success() {
108-
// given
109-
Recruit recruit = mock(Recruit.class);
110-
when(recruitRepository.findByKey(ConfigKey.DOCUMENT_PASS_ANNOUNCEMENT)).thenReturn(Optional.of(recruit));
111-
String pastDateTime = LocalDateTime.now().minusHours(1)
112-
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
113-
when(recruit.getValue()).thenReturn(pastDateTime);
114-
115-
ResultCheckRequestDto request = mock(ResultCheckRequestDto.class);
116-
when(request.getType()).thenReturn(ResultCheckType.DOCUMENT_PASS);
117-
when(request.getStudentNo()).thenReturn("20210000");
118-
when(request.getContactLastDigit()).thenReturn("1234");
119-
120-
ApplicantDetailsResponseDto applicant = mock(ApplicantDetailsResponseDto.class);
121-
when(applicant.getContact()).thenReturn("010-5678-1234");
122-
when(applicant.getStatus()).thenReturn(ApplicantStatus.DOCUMENT_PASSED);
123-
when(applicant.getStudentNo()).thenReturn("20210000");
124-
when(applicant.getName()).thenReturn("TestName");
125-
when(applicantService.getApplicantByStudentNo("20210000")).thenReturn(applicant);
126-
127-
// when
128-
ResultCheckResponseDto result = recruitService.checkResult(request);
129-
130-
// then
131-
assertNotNull(result);
132-
assertTrue(result.getIsPassed());
133-
verify(recruitRepository, times(1)).findByKey(ConfigKey.DOCUMENT_PASS_ANNOUNCEMENT);
134-
verify(applicantService, times(1)).getApplicantByStudentNo("20210000");
135-
}
136-
137-
@Test
138-
@DisplayName("합격 결과 확인 - 실패 (확인 기간 아님)")
139-
void checkResult_fail_inquiryPeriod() {
140-
// given
141-
Recruit recruit = mock(Recruit.class);
142-
when(recruitRepository.findByKey(ConfigKey.DOCUMENT_PASS_ANNOUNCEMENT)).thenReturn(Optional.of(recruit));
143-
String futureDateTime = LocalDateTime.now().plusHours(1)
144-
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
145-
when(recruit.getValue()).thenReturn(futureDateTime);
146-
147-
ResultCheckRequestDto request = mock(ResultCheckRequestDto.class);
148-
when(request.getType()).thenReturn(ResultCheckType.DOCUMENT_PASS);
149-
150-
// when
151-
CustomException exception = assertThrows(CustomException.class, () -> {
152-
recruitService.checkResult(request);
153-
});
154-
155-
// then
156-
assertEquals(ErrorCode.INVALID_INQUIRY_PERIOD, exception.getErrorCode());
157-
verify(recruitRepository, times(1)).findByKey(ConfigKey.DOCUMENT_PASS_ANNOUNCEMENT);
158-
}
159-
160-
@Test
161-
@DisplayName("합격 결과 확인 - 실패 (연락처 뒷자리 불일치)")
162-
void checkResult_fail_contactMismatch() {
163-
// given
164-
Recruit recruit = mock(Recruit.class);
165-
when(recruitRepository.findByKey(ConfigKey.DOCUMENT_PASS_ANNOUNCEMENT)).thenReturn(Optional.of(recruit));
166-
String pastDateTime = LocalDateTime.now().minusHours(1)
167-
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
168-
when(recruit.getValue()).thenReturn(pastDateTime);
169-
170-
ResultCheckRequestDto request = mock(ResultCheckRequestDto.class);
171-
when(request.getType()).thenReturn(ResultCheckType.DOCUMENT_PASS);
172-
when(request.getStudentNo()).thenReturn("20210000");
173-
when(request.getContactLastDigit()).thenReturn("0000");
174-
175-
ApplicantDetailsResponseDto applicant = mock(ApplicantDetailsResponseDto.class);
176-
when(applicant.getContact()).thenReturn("010-5678-1234");
177-
when(applicantService.getApplicantByStudentNo("20210000")).thenReturn(applicant);
178-
179-
// when
180-
CustomException exception = assertThrows(CustomException.class, () -> {
181-
recruitService.checkResult(request);
182-
});
183-
184-
// then
185-
assertEquals(ErrorCode.ARGUMENT_NOT_VALID, exception.getErrorCode());
186-
verify(recruitRepository, times(1)).findByKey(ConfigKey.DOCUMENT_PASS_ANNOUNCEMENT);
187-
verify(applicantService, times(1)).getApplicantByStudentNo("20210000");
188-
}
189-
190105
@Test
191106
@DisplayName("면접 일정 생성 - 성공")
192107
void createInterviewSlots_success() {

0 commit comments

Comments
 (0)