|
2 | 2 |
|
3 | 3 | import kgu.developers.common.response.PaginatedListResponse; |
4 | 4 | import kgu.developers.domain.graduationUser.application.query.GraduationUserQueryService; |
| 5 | +import kgu.developers.domain.graduationUser.domain.GraduationType; |
5 | 6 | import kgu.developers.domain.graduationUser.domain.GraduationUser; |
6 | 7 | import kgu.developers.domain.graduationUser.infrastructure.excel.GraduationUserExcelImpl; |
7 | 8 | import kgu.developers.domain.user.application.query.UserQueryService; |
| 9 | +import kgu.developers.domain.user.domain.User; |
8 | 10 | import mock.repository.FakeCertificateRepository; |
9 | 11 | import mock.repository.FakeGraduationUserRepository; |
10 | 12 | import mock.repository.FakeThesisRepository; |
|
13 | 15 | import org.junit.jupiter.api.DisplayName; |
14 | 16 | import org.junit.jupiter.api.Test; |
15 | 17 | import org.springframework.data.domain.PageRequest; |
| 18 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| 19 | +import org.springframework.security.core.context.SecurityContext; |
| 20 | +import org.springframework.security.core.context.SecurityContextHolder; |
| 21 | +import org.springframework.security.core.userdetails.UserDetails; |
16 | 22 |
|
17 | 23 | import java.time.LocalDate; |
18 | 24 |
|
| 25 | +import static kgu.developers.domain.user.domain.Major.CSE; |
19 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 27 |
|
21 | 28 | public class GraduationUserQueryServiceTest { |
22 | 29 | private GraduationUserQueryService graduationUserQueryService; |
23 | 30 | private static final Long TARGET_GRADUATION_USER_ID = 1L; |
24 | 31 | private static final String TARGET_STUDENT_ID = "202211444"; |
25 | | - |
| 32 | + FakeGraduationUserRepository fakeGraduationUserRepository; |
26 | 33 | @BeforeEach |
27 | 34 | public void init() { |
28 | | - FakeGraduationUserRepository fakeGraduationUserRepository = new FakeGraduationUserRepository(); |
29 | | - |
30 | | - UserQueryService userQueryService = new UserQueryService(new FakeUserRepository()); |
| 35 | + fakeGraduationUserRepository = new FakeGraduationUserRepository(); |
| 36 | + FakeUserRepository fakeUserRepository = new FakeUserRepository(); |
| 37 | + UserQueryService userQueryService = new UserQueryService(fakeUserRepository); |
31 | 38 |
|
32 | 39 | graduationUserQueryService = new GraduationUserQueryService( |
33 | 40 | userQueryService, |
@@ -55,6 +62,21 @@ public void init() { |
55 | 62 | fakeGraduationUserRepository.save(GraduationUser.create( |
56 | 63 | "202214567", "정수진", "이교수", false, "인공지능학과", LocalDate.of(2024, 2, 20) |
57 | 64 | )); |
| 65 | + |
| 66 | + fakeUserRepository.save(User.builder() |
| 67 | + .id("202211444") |
| 68 | + .password("password1234") |
| 69 | + .name("홍길동") |
| 70 | + .email("test1@kyonggi.ac.kr") |
| 71 | + .phone("010-1234-5679") |
| 72 | + .major(CSE) |
| 73 | + .build()); |
| 74 | + |
| 75 | + UserDetails user = userQueryService.getUserById("202211444"); |
| 76 | + SecurityContext context = SecurityContextHolder.getContext(); |
| 77 | + context.setAuthentication( |
| 78 | + new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities()) |
| 79 | + ); |
58 | 80 | } |
59 | 81 |
|
60 | 82 | @Test |
@@ -99,4 +121,33 @@ public void getByUserId_Success() { |
99 | 121 | assertEquals(TARGET_STUDENT_ID, graduationUser.getUserId()); |
100 | 122 |
|
101 | 123 | } |
| 124 | + |
| 125 | + @Test |
| 126 | + @DisplayName("getGraduationTypeByUserId는 해당 학번의 졸업 대상자의 졸업 방식을 반환한다.") |
| 127 | + public void getGraduationTypeByUserId_Success() { |
| 128 | + //given |
| 129 | + GraduationUser graduationUser = fakeGraduationUserRepository.findByUserIdAndDeletedAtIsNull(TARGET_STUDENT_ID).orElse(null); |
| 130 | + graduationUser.updateGraduationType(GraduationType.THESIS); |
| 131 | + fakeGraduationUserRepository.save(graduationUser); |
| 132 | + |
| 133 | + //when |
| 134 | + GraduationType graduationType = graduationUserQueryService.getGraduationTypeByUserId(TARGET_STUDENT_ID); |
| 135 | + |
| 136 | + //then |
| 137 | + assertEquals(GraduationType.THESIS, graduationType); |
| 138 | + |
| 139 | + } |
| 140 | + |
| 141 | + @Test |
| 142 | + @DisplayName("me는 현재 로그인 되어 있는 졸업 대상자를 조회한다.") |
| 143 | + public void Success() { |
| 144 | + //given |
| 145 | + |
| 146 | + //when |
| 147 | + GraduationUser result = graduationUserQueryService.me(); |
| 148 | + |
| 149 | + //then |
| 150 | + assertEquals(TARGET_GRADUATION_USER_ID, result.getId()); |
| 151 | + |
| 152 | + } |
102 | 153 | } |
0 commit comments