diff --git a/src/main/java/com/postgraduate/domain/available/application/util/AvailableUtil.java b/src/main/java/com/postgraduate/domain/available/application/util/AvailableUtil.java index 1f9d580a..0561a0e4 100644 --- a/src/main/java/com/postgraduate/domain/available/application/util/AvailableUtil.java +++ b/src/main/java/com/postgraduate/domain/available/application/util/AvailableUtil.java @@ -2,8 +2,11 @@ import com.postgraduate.domain.available.application.dto.req.AvailableCreateRequest; import com.postgraduate.domain.available.domain.entity.Available; +import com.postgraduate.domain.available.exception.DayAvailableException; import com.postgraduate.domain.senior.domain.entity.Senior; +import lombok.AllArgsConstructor; +import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -16,21 +19,7 @@ public static List sortAvailable(List availab Comparator.comparing( (AvailableCreateRequest availableCreateRequest) -> { String day = availableCreateRequest.day(); - if (day.equals("월")) - return 0; - if (day.equals("화")) - return 1; - if (day.equals("수")) - return 2; - if (day.equals("목")) - return 3; - if (day.equals("금")) - return 4; - if (day.equals("토")) - return 5; - if (day.equals("일")) - return 6; - throw new IllegalArgumentException(); + return Day.sortDay(day); } ).thenComparingInt( availableCreateRequest -> { @@ -46,4 +35,17 @@ public static List sortAvailable(List availab return sortedAvailable; } + @AllArgsConstructor + private enum Day { + 월(0), 화(1), 수(2), 목(3), 금(4), 토(5), 일(6); + private final int day; + + private static int sortDay(String inputDay) { + return Arrays.stream(Day.values()) + .filter(day -> day.name().equals(inputDay)) + .findFirst() + .orElseThrow(DayAvailableException::new) + .day; + } + } } diff --git a/src/main/java/com/postgraduate/domain/available/exception/DayAvailableException.java b/src/main/java/com/postgraduate/domain/available/exception/DayAvailableException.java new file mode 100644 index 00000000..d01aec81 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/available/exception/DayAvailableException.java @@ -0,0 +1,10 @@ +package com.postgraduate.domain.available.exception; + +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode; +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage; + +public class DayAvailableException extends AvailableException { + public DayAvailableException() { + super(SeniorResponseMessage.INVALID_DAY.getMessage(), SeniorResponseCode.INVALID_DAY.getCode()); + } +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index 1d1e75c7..df426053 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -9,6 +9,10 @@ import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; import com.postgraduate.domain.mentoring.exception.MentoringNotExpectedException; import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException; +import com.postgraduate.domain.payment.domain.entity.Payment; +import com.postgraduate.domain.payment.domain.entity.constant.Status; +import com.postgraduate.domain.payment.domain.service.PaymentGetService; +import com.postgraduate.domain.payment.domain.service.PaymentUpdateService; import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest; import com.postgraduate.domain.refuse.application.mapper.RefuseMapper; import com.postgraduate.domain.refuse.domain.entity.Refuse; @@ -43,12 +47,17 @@ public class MentoringManageUseCase { private final SeniorGetService seniorGetService; private final SalaryGetService salaryGetService; private final SalaryUpdateService salaryUpdateService; + private final PaymentGetService paymentGetService; + private final PaymentUpdateService paymentUpdateService; public void updateCancel(User user, Long mentoringId) { Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId); if (mentoring.getStatus() != WAITING) throw new MentoringNotWaitingException(); mentoringUpdateService.updateStatus(mentoring, CANCEL); + Payment payment = paymentGetService.byMentoring(mentoring); + paymentUpdateService.updateStatus(payment, Status.CANCEL); + // todo 환불 구현 후 수정 } public void updateDone(User user, Long mentoringId) { diff --git a/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentDslRepositoryImpl.java b/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentDslRepositoryImpl.java index 48b31ed3..0d146d7d 100644 --- a/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentDslRepositoryImpl.java +++ b/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentDslRepositoryImpl.java @@ -1,6 +1,7 @@ package com.postgraduate.domain.payment.domain.repository; import com.postgraduate.domain.payment.domain.entity.Payment; +import com.postgraduate.domain.payment.domain.entity.constant.Status; import com.postgraduate.domain.senior.domain.entity.Senior; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -29,6 +30,7 @@ public List findAllBySeniorAndStatus(Senior senior, Boolean status) { return queryFactory.selectFrom(payment) .where( payment.mentoring.senior.eq(senior), + payment.status.eq(Status.DONE), payment.salary.status.eq(status) ) .join(payment.salary, salary) diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorMyPageProfileRequest.java b/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorMyPageProfileRequest.java index 2e0c4006..76cda6fb 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorMyPageProfileRequest.java +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorMyPageProfileRequest.java @@ -1,6 +1,7 @@ package com.postgraduate.domain.senior.application.dto.req; import com.postgraduate.domain.available.application.dto.req.AvailableCreateRequest; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; @@ -22,5 +23,7 @@ public record SeniorMyPageProfileRequest( @NotBlank String oneLiner, @NotEmpty + @Valid List times -) {} +) { +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java index 04de5c71..5829695b 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorManageUseCase.java @@ -6,8 +6,8 @@ import com.postgraduate.domain.account.domain.service.AccountUpdateService; import com.postgraduate.domain.available.application.dto.req.AvailableCreateRequest; import com.postgraduate.domain.available.domain.entity.Available; -import com.postgraduate.domain.available.domain.service.AvailableSaveService; import com.postgraduate.domain.available.domain.service.AvailableDeleteService; +import com.postgraduate.domain.available.domain.service.AvailableSaveService; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.service.SalaryGetService; import com.postgraduate.domain.salary.domain.service.SalaryUpdateService; @@ -90,29 +90,27 @@ public void updateSeniorMyPageUserAccount(User user, SeniorMyPageUserAccountRequ userUtils.checkPhoneNumber(myPageUserAccountRequest.phoneNumber()); Senior senior = seniorGetService.byUser(user); user = userGetService.getUser(user.getUserId()); + userUpdateService.updateSeniorUserAccount(user, myPageUserAccountRequest); + Optional optionalAccount = accountGetService.bySenior(senior); if (optionalAccount.isEmpty()) { - updateSeniorMyPageUserAccountNoneAccount(senior, user, myPageUserAccountRequest); + updateSeniorMyPageUserAccountNoneAccount(senior, myPageUserAccountRequest); return; } if (myPageUserAccountRequest.accountNumber().isEmpty() || myPageUserAccountRequest.accountHolder().isEmpty() || myPageUserAccountRequest.bank().isEmpty()) throw new NoneAccountException(); Account account = optionalAccount.get(); String accountNumber = encryptorUtils.encryptData(myPageUserAccountRequest.accountNumber()); - userUpdateService.updateSeniorUserAccount(user, myPageUserAccountRequest); accountUpdateService.updateAccount(account, myPageUserAccountRequest, accountNumber); updateSalaryAccount(senior, myPageUserAccountRequest.bank(), accountNumber, myPageUserAccountRequest.accountHolder()); } - private void updateSeniorMyPageUserAccountNoneAccount(Senior senior, User user, SeniorMyPageUserAccountRequest myPageUserAccountRequest) { - user = userGetService.getUser(user.getUserId()); + private void updateSeniorMyPageUserAccountNoneAccount(Senior senior, SeniorMyPageUserAccountRequest myPageUserAccountRequest) { if (myPageUserAccountRequest.accountNumber().isEmpty() || myPageUserAccountRequest.accountHolder().isEmpty() || myPageUserAccountRequest.bank().isEmpty()) { - userUpdateService.updateSeniorUserAccount(user, myPageUserAccountRequest); return; } String accountNumber = encryptorUtils.encryptData(myPageUserAccountRequest.accountNumber()); Account account = mapToAccount(senior, myPageUserAccountRequest, accountNumber); - userUpdateService.updateSeniorUserAccount(user, myPageUserAccountRequest); accountSaveService.saveAccount(account); updateSalaryAccount(senior, myPageUserAccountRequest.bank(), accountNumber, myPageUserAccountRequest.accountHolder()); } diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java index fc6bf8d9..d9e27483 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java @@ -14,6 +14,7 @@ import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.entity.constant.Status; import com.postgraduate.domain.senior.domain.service.SeniorGetService; +import com.postgraduate.domain.senior.exception.NoneProfileException; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.service.WishGetService; @@ -49,6 +50,9 @@ public SeniorMyPageResponse getSeniorInfo(User user) { public SeniorMyPageProfileResponse getSeniorMyPageProfile(User user) { Senior senior = seniorGetService.byUser(user); + if (senior.getProfile() == null) { + throw new NoneProfileException(); + } List availables = availableGetService.bySenior(senior); List times = availables.stream() .map(AvailableMapper::mapToAvailableTimes) diff --git a/src/main/java/com/postgraduate/domain/senior/exception/NoneProfileException.java b/src/main/java/com/postgraduate/domain/senior/exception/NoneProfileException.java new file mode 100644 index 00000000..fb3f72f5 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/exception/NoneProfileException.java @@ -0,0 +1,11 @@ +package com.postgraduate.domain.senior.exception; + +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode; +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage; +import com.postgraduate.global.exception.ApplicationException; + +public class NoneProfileException extends ApplicationException { + public NoneProfileException() { + super(SeniorResponseMessage.NONE_PROFILE.getMessage(), SeniorResponseCode.NONE_PROFILE.getCode()); + } +} diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseCode.java b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseCode.java index d2ed3f50..8f1750fd 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseCode.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseCode.java @@ -16,6 +16,8 @@ public enum SeniorResponseCode { NOT_WAITING_STATUS("EX402"), INVALID_KEYWORD("EX402"), EMPTY_TIME("EX403"), + INVALID_DAY("EX404"), + NONE_PROFILE("EX405"), ; private final String code; } diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java index 836a22b7..3299138f 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java @@ -28,6 +28,8 @@ public enum SeniorResponseMessage { INVALID_KEYWORD("키워드가 잘못되었습니다."), NOT_WAITING_STATUS("승인대기 상태의 선배가 아닙니다."), EMPTY_TIME("가능 시간이 비었습니다."), + INVALID_DAY("잘못된 요일입니다."), + NONE_PROFILE("등록한 프로필이 없습니다."), ; private final String message; diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 249924e7..9bf8a1b6 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -14,13 +14,19 @@ import com.postgraduate.domain.wish.domain.repository.WishRepository; import com.postgraduate.global.config.redis.RedisRepository; import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import com.postgraduate.global.exception.constant.ErrorCode; +import com.postgraduate.global.exception.constant.ErrorMessage; +import com.postgraduate.global.slack.SlackMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; +import java.io.IOException; import java.util.Optional; import static com.postgraduate.domain.auth.presentation.constant.AuthResponseCode.*; @@ -31,8 +37,10 @@ import static com.postgraduate.domain.user.domain.entity.constant.Role.USER; import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_NOT_FOUND; import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.NOT_FOUND_USER; +import static java.lang.Boolean.FALSE; import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -53,14 +61,17 @@ class AuthControllerTest extends IntegrationTest { private WishRepository wishRepository; @MockBean RedisRepository redisRepository; + @MockBean + private SlackMessage slackMessage; private User user; private final Long anonymousUserSocialId = 2L; @BeforeEach - void setUp() { + void setUp() throws IOException { user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); userRepository.save(user); + doNothing().when(slackMessage).sendSlackLog(any()); } @Test @@ -127,6 +138,28 @@ void signUpUser() throws Exception { .andExpect(jsonPath("$.data.role").value(USER.name())); } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("희망 대학원/학과와 연구분야를 입력하지 않아도 대학생 회원가입이 가능하다.") + void signUpUserWithoutWish(String empty) throws Exception { + authLoginByAnonymousUser(); + + String request = objectMapper.writeValueAsString( + new SignUpRequest(anonymousUserSocialId, "01012345678", "nickname", + true, empty, empty, false) + ); + + mvc.perform(post("/auth/user/signup") + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value(USER.name())); + } + @Test @DisplayName("대학원생이 대학생으로 변경한다.") void changeUserToken() throws Exception { @@ -177,6 +210,26 @@ void changeUser() throws Exception { .andExpect(jsonPath("$.data.role").value(USER.name())); } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("전공과 분야가 없어도 후배로 추가 가입할 수 있다") + void changeUser(String empty) throws Exception { + String seniorAccessToken = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); + + String request = objectMapper.writeValueAsString( + new UserChangeRequest(empty, empty, FALSE) + ); + + mvc.perform(post("/auth/user/change") + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())); + } + @Test @DisplayName("선배가 회원가입한다.") void singUpSenior() throws Exception { @@ -199,6 +252,26 @@ void singUpSenior() throws Exception { .andExpect(jsonPath("$.data.role").value(SENIOR.name())); } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("필수 정보를 입력하지 않으면 선배로 회원가입할 수 없다.") + void singUpSenior(String empty) throws Exception { + authLoginByAnonymousUser(); + + String request = objectMapper.writeValueAsString( + new SeniorSignUpRequest(anonymousUserSocialId, "01012345678", "nickname", + true, empty, empty, empty, empty, empty, empty, empty) + ); + + mvc.perform(post("/auth/senior/signup") + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + @Test @DisplayName("후배가 선배로 추가 가입합니다.") void changeSenior() throws Exception { @@ -221,6 +294,26 @@ void changeSenior() throws Exception { .andExpect(jsonPath("$.data.role").value(SENIOR.name())); } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("선배 필수 정보가 없으면 선배로 추가 가입할 수 없다") + void changeSenior(String empty) throws Exception { + String userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), USER); + + String request = objectMapper.writeValueAsString( + new SeniorChangeRequest(empty, empty, empty, empty, empty, empty, empty) + ); + + mvc.perform(post("/auth/senior/change") + .header(AUTHORIZATION, BEARER + userAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + @Test @DisplayName("대학생이 대학원생으로 변경한다.") void changeSeniorToken() throws Exception { diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java index 66975bdd..ba28dcb5 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCaseTest.java @@ -8,12 +8,15 @@ import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; import com.postgraduate.domain.mentoring.exception.MentoringNotExpectedException; import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException; +import com.postgraduate.domain.payment.domain.entity.Payment; +import com.postgraduate.domain.payment.domain.entity.constant.Status; +import com.postgraduate.domain.payment.domain.service.PaymentGetService; +import com.postgraduate.domain.payment.domain.service.PaymentUpdateService; import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest; import com.postgraduate.domain.refuse.domain.entity.Refuse; import com.postgraduate.domain.refuse.domain.service.RefuseSaveService; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.service.SalaryGetService; -import com.postgraduate.domain.salary.domain.service.SalarySaveService; import com.postgraduate.domain.salary.domain.service.SalaryUpdateService; import com.postgraduate.domain.senior.domain.entity.Info; import com.postgraduate.domain.senior.domain.entity.Profile; @@ -36,7 +39,6 @@ import static com.postgraduate.domain.user.domain.entity.constant.Role.USER; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; -import static java.time.LocalDateTime.now; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; @@ -54,7 +56,7 @@ class MentoringManageUseCaseTest { private MentoringUpdateService mentoringUpdateService; @Mock - private MentoringGetService mentoringGetServicel; + private MentoringGetService mentoringGetService; @Mock private RefuseSaveService refuseSaveService; @@ -71,6 +73,12 @@ class MentoringManageUseCaseTest { @Mock private SalaryUpdateService salaryUpdateService; + @Mock + private PaymentGetService paymentGetService; + + @Mock + private PaymentUpdateService paymentUpdateService; + @InjectMocks private MentoringManageUseCase mentoringManageUseCase; @@ -100,9 +108,15 @@ void updateCancel() { , 40, WAITING , LocalDateTime.now(), LocalDateTime.now()); + Payment payment = new Payment(0L, mentoring, null, 24000, null + , null, null, null, null, Status.DONE); + given(checkIsMyMentoringUseCase.byUser(user, mentoringId)) .willReturn(mentoring); + given(paymentGetService.byMentoring(mentoring)) + .willReturn(payment); + mentoringManageUseCase.updateCancel(user, mentoringId); verify(mentoringUpdateService).updateStatus(mentoring, CANCEL); diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index fa5430a3..21e62cb8 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -22,23 +22,33 @@ import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.domain.repository.UserRepository; import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import com.postgraduate.global.exception.constant.ErrorCode; +import com.postgraduate.global.exception.constant.ErrorMessage; +import com.postgraduate.global.slack.SlackMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; +import java.io.IOException; import java.time.LocalDate; +import static com.postgraduate.domain.auth.presentation.constant.AuthResponseCode.AUTH_DENIED; +import static com.postgraduate.domain.auth.presentation.constant.AuthResponseMessage.PERMISSION_DENIED; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; import static com.postgraduate.domain.payment.domain.entity.constant.Status.DONE; import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -60,13 +70,15 @@ class MentoringControllerTest extends IntegrationTest { private SalaryRepository salaryRepository; @Autowired private PaymentRepository paymentRepository; + @MockBean + private SlackMessage slackMessage; private User user; private Senior senior; private String userAccessToken; private String seniorAccessToken; @BeforeEach - void setUp() { + void setUp() throws IOException { user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); userRepository.save(user); @@ -80,6 +92,8 @@ void setUp() { userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); seniorAccessToken = jwtUtil.generateAccessToken(userOfSenior.getUserId(), Role.SENIOR); + + doNothing().when(slackMessage).sendSlackLog(any()); } @ParameterizedTest @@ -127,6 +141,21 @@ void getMentoringDetail(Status status) throws Exception { .andExpect(jsonPath("$.data.seniorId").value(senior.getSeniorId())); } + @Test + @DisplayName("자신이 신청한 멘토링이 아니라면 상세조회되지 않는다") + void getOtherMentoringDetail() throws Exception { + User otherUser = new User(-1L, 0L, "mail", "다른 후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + userRepository.save(otherUser); + Mentoring mentoring = new Mentoring(0L, otherUser, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + userAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(AUTH_DENIED.getCode())) + .andExpect(jsonPath("$.message").value(PERMISSION_DENIED.getMessage())); + } + @ParameterizedTest @EnumSource(value = Status.class, names = {"DONE", "CANCEL", "REFUSE"}) @@ -174,6 +203,22 @@ void applyMentoringWithoutThreeDates(String date) throws Exception { } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("신청서가 빈 칸이라면 멘토링을 신청할 수 없다") + void emptyApplyMentoring(String empty) throws Exception { + String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), empty, empty, empty)); + + mvc.perform(post("/mentoring/applying") + .header(AUTHORIZATION, BEARER + userAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + @Test @DisplayName("대학생이 멘토링을 완료한다.") void updateMentoringDone() throws Exception { @@ -213,6 +258,9 @@ void updateMentoringCancel() throws Exception { Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.WAITING, now(), now()); mentoringRepository.save(mentoring); + Payment payment = new Payment(0L, mentoring, null, 24000, null, null, null, null, null, DONE); + paymentRepository.save(payment); + mvc.perform(patch("/mentoring/me/{mentoringId}/cancel", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) @@ -271,6 +319,26 @@ void getSeniorMentoringDetails(Status status) throws Exception { } + @Test + @DisplayName("자신이 신청받은 멘토링이 아니라면 상세조회되지 않는다") + void getOtherSeniorMentoringDetail() throws Exception { + User otherUser = new User(-1L, 0L, "mail", "다른 후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + userRepository.save(otherUser); + + Info info = new Info("major", "서울대학교", "교수님", "키워드1,키워드2", "랩실", "인공지능", false, false, "인공지능,키워드1,키워드2"); + Senior otherSenior = new Senior(-1L, otherUser, "certification", WAITING, 0, info, null, now(), now()); + seniorRepository.save(otherSenior); + + Mentoring mentoring = new Mentoring(0L, otherUser, otherSenior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + userAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(AUTH_DENIED.getCode())) + .andExpect(jsonPath("$.message").value(PERMISSION_DENIED.getMessage())); + } + @ParameterizedTest @EnumSource(value = Status.class, names = {"DONE", "CANCEL", "REFUSE"}) @DisplayName("대학원생의 완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") @@ -320,6 +388,24 @@ void updateSeniorMentoringExpectedWithoutWaiting(Status status) throws Exception .andExpect(jsonPath("$.message").value(NOT_WAITING_MENTORING.getMessage())); } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("확정날짜가 비어있다면 멘토링을 수락할 수 없다") + void updateSeniorMentoringExpectedWithoutDate(String empty) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); + mentoringRepository.save(mentoring); + + String request = objectMapper.writeValueAsString(new MentoringDateRequest(empty)); + mvc.perform(patch("/mentoring/senior/me/{mentoringId}/expected", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + @Test @DisplayName("대학원생이 멘토링을 거절한다.") void updateSeniorMentoringRefuse() throws Exception { @@ -354,4 +440,22 @@ void updateSeniorMentoringRefuseWithoutWaiting(Status status) throws Exception { .andExpect(jsonPath("$.code").value(MENTORING_NOT_WAITING.getCode())) .andExpect(jsonPath("$.message").value(NOT_WAITING_MENTORING.getMessage())); } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("사유가 비어있다면 멘토링을 거절할 수 없다") + void updateSeniorMentoringExpectedWithoutRefuse(String empty) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); + mentoringRepository.save(mentoring); + + String request = objectMapper.writeValueAsString(new MentoringRefuseRequest(empty)); + mvc.perform(patch("/mentoring/senior/me/{mentoringId}/refuse", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } } \ No newline at end of file diff --git a/src/test/java/com/postgraduate/domain/salary/presentation/SalaryControllerTest.java b/src/test/java/com/postgraduate/domain/salary/presentation/SalaryControllerTest.java new file mode 100644 index 00000000..c509ef98 --- /dev/null +++ b/src/test/java/com/postgraduate/domain/salary/presentation/SalaryControllerTest.java @@ -0,0 +1,111 @@ +package com.postgraduate.domain.salary.presentation; + +import com.postgraduate.IntegrationTest; +import com.postgraduate.domain.salary.domain.entity.Salary; +import com.postgraduate.domain.salary.domain.repository.SalaryRepository; +import com.postgraduate.domain.salary.util.SalaryUtil; +import com.postgraduate.domain.senior.domain.entity.Info; +import com.postgraduate.domain.senior.domain.entity.Profile; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.entity.constant.Status; +import com.postgraduate.domain.senior.domain.repository.SeniorRepository; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.entity.constant.Role; +import com.postgraduate.domain.user.domain.repository.UserRepository; +import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import com.postgraduate.global.slack.SlackMessage; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; + +import java.io.IOException; + +import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseCode.SALARY_FIND; +import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseCode.SALARY_NOT_FOUND; +import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseMessage.*; +import static java.time.LocalDateTime.now; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class SalaryControllerTest extends IntegrationTest { + private static final String AUTHORIZATION = "Authorization"; + private static final String BEARER = "Bearer "; + @Autowired + private JwtUtils jwtUtil; + @Autowired + private UserRepository userRepository; + @Autowired + private SeniorRepository seniorRepository; + @Autowired + private SalaryRepository salaryRepository; + @MockBean + private SlackMessage slackMessage; + private String token; + private Salary salary; + + + @BeforeEach + void setUp() throws IOException { + User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); + userRepository.save(user); + + Info info = new Info("major", "postgradu", "교수님", "keyword1,keyword2", "랩실", "field", false, false, "field,keyword1,keyword2"); + Profile profile = new Profile("저는요", "한줄소개", "대상", "chatLink", 40); + Senior senior = new Senior(0L, user, "certification", Status.APPROVE, 0, info, profile, now(), now()); + seniorRepository.save(senior); + + salary = new Salary(0L, false, senior, null, 0, SalaryUtil.getSalaryDate(), null, "bank", "account", "holder"); + salaryRepository.save(salary); + + token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); + + doNothing().when(slackMessage).sendSlackLog(any()); + } + + @Test + @DisplayName("대학원생 정산 예정액과 다음 정산 예정일을 조회한다") + void getSalary() throws Exception { + mvc.perform(get("/salary") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SALARY_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SALARY_INFO.getMessage())); + } + + @Test + @DisplayName("정산이 없다면 예외가 발생한다") + void getEmptySalary() throws Exception { + salaryRepository.delete(salary); + + mvc.perform(get("/salary") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SALARY_NOT_FOUND.getCode())) + .andExpect(jsonPath("$.message").value(NOT_FOUND_SALARY.getMessage())); + } + + @Test + @DisplayName("대학원생 정산예정 목록을 조회한다") + void getWaitingSalary() throws Exception { + mvc.perform(get("/salary/waiting") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SALARY_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SALARY_LIST_INFO.getMessage())); + } + + @Test + @DisplayName("대학원생 정산완료 목록을 조회한다") + void getDoneSalary() throws Exception { + mvc.perform(get("/salary/done") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SALARY_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SALARY_LIST_INFO.getMessage())); + } +} \ No newline at end of file diff --git a/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java b/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java new file mode 100644 index 00000000..073fb840 --- /dev/null +++ b/src/test/java/com/postgraduate/domain/senior/presentation/SeniorControllerTest.java @@ -0,0 +1,593 @@ +package com.postgraduate.domain.senior.presentation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.postgraduate.IntegrationTest; +import com.postgraduate.domain.account.domain.entity.Account; +import com.postgraduate.domain.account.domain.repository.AccountRepository; +import com.postgraduate.domain.available.application.dto.req.AvailableCreateRequest; +import com.postgraduate.domain.available.domain.entity.Available; +import com.postgraduate.domain.available.domain.repository.AvailableRepository; +import com.postgraduate.domain.salary.domain.entity.Salary; +import com.postgraduate.domain.salary.domain.repository.SalaryRepository; +import com.postgraduate.domain.senior.application.dto.req.*; +import com.postgraduate.domain.senior.domain.entity.Info; +import com.postgraduate.domain.senior.domain.entity.Profile; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.entity.constant.Status; +import com.postgraduate.domain.senior.domain.repository.SeniorRepository; +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode; +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.entity.constant.Role; +import com.postgraduate.domain.user.domain.repository.UserRepository; +import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import com.postgraduate.global.exception.constant.ErrorCode; +import com.postgraduate.global.exception.constant.ErrorMessage; +import com.postgraduate.global.slack.SlackMessage; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EmptySource; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; +import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.*; +import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.*; +import static java.time.LocalDateTime.now; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class SeniorControllerTest extends IntegrationTest { + private static final String AUTHORIZATION = "Authorization"; + private static final String BEARER = "Bearer "; + @Autowired + private ObjectMapper objectMapper; + @Autowired + private JwtUtils jwtUtil; + @Autowired + private UserRepository userRepository; + @Autowired + private SeniorRepository seniorRepository; + @Autowired + private SalaryRepository salaryRepository; + @Autowired + private AccountRepository accountRepository; + @Autowired + private AvailableRepository availableRepository; + @MockBean + private SlackMessage slackMessage; + private Senior senior; + private String token; + + @BeforeEach + void setUp() throws IOException { + User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); + userRepository.save(user); + + Info info = new Info("major", "postgradu", "교수님", "keyword1,keyword2", "랩실", "field", false, false, "field,keyword1,keyword2"); + senior = new Senior(0L, user, "certification", Status.APPROVE, 0, info, null, now(), now()); + seniorRepository.save(senior); + + token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); + + doNothing().when(slackMessage).sendSlackLog(any()); + } + + + private void updateProfile() { + Profile profile = new Profile("저는요", "한줄소개", "대상", "chatLink", 30); + senior.updateProfile(profile); + seniorRepository.save(senior); + } + + private void updateAvailable() { + List availables = List.of( + new Available(0L, "월", "17:00", "23:00", senior), + new Available(0L, "금", "10:00", "20:00", senior), + new Available(0L, "토", "10:00", "20:00", senior) + ); + availableRepository.saveAll(availables); + } + + @Test + @DisplayName("대학원생 인증한다") + void updateCertification() throws Exception { + String request = objectMapper.writeValueAsString( + new SeniorCertificationRequest("certification") + ); + mvc.perform(patch("/senior/certification") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_CERTIFICATION.getMessage())); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("잘못된 이미지로 인증한다") + void updateInvalidCertification(String certification) throws Exception { + String request = objectMapper.writeValueAsString( + new SeniorCertificationRequest(certification) + ); + mvc.perform(patch("/senior/certification") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + + @Test + @DisplayName("대학원생 프로필을 등록한다") + void singUpSenior() throws Exception { + List availableCreateRequests = List.of( + new AvailableCreateRequest("월", "17:00", "23:00"), + new AvailableCreateRequest("금", "10:00", "20:00"), + new AvailableCreateRequest("토", "10:00", "20:00") + ); + String request = objectMapper.writeValueAsString( + new SeniorProfileRequest("저는요", "대상", "chatLink", "한줄소개", availableCreateRequests) + ); + + mvc.perform(patch("/senior/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_PROFILE.getMessage())); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("잘못된 대학원생 프로필을 등록한다") + void singUpInvalidSenior(String empty) throws Exception { + List availableCreateRequests = new ArrayList<>(); + String request = objectMapper.writeValueAsString( + new SeniorProfileRequest(empty, empty, empty, empty, availableCreateRequests) + ); + + mvc.perform(patch("/senior/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + + @Test + @DisplayName("월-일 외 요일을 입력하면 예외가 발생한다") + void InvalidDay() throws Exception { + List availableCreateRequests = List.of( + new AvailableCreateRequest("월", "17:00", "23:00"), + new AvailableCreateRequest("잉", "17:00", "23:00") + ); + + String request = objectMapper.writeValueAsString( + new SeniorProfileRequest("저는요", "대상", "chatLink", "한줄소개", availableCreateRequests) + ); + + mvc.perform(patch("/senior/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SeniorResponseCode.INVALID_DAY.getCode())) + .andExpect(jsonPath("$.message").value(SeniorResponseMessage.INVALID_DAY.getMessage())); + } + + @Test + @DisplayName("대학원생 정산 계좌를 생성한다") + void updateAccount() throws Exception { + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); + salaryRepository.save(salary); + + String request = objectMapper.writeValueAsString( + new SeniorAccountRequest("농협", "주인", "123123123456") + ); + + mvc.perform(post("/senior/account") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(CREATE_ACCOUNT.getMessage())); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("빈 정산 계좌를 입력으면 예외가 발생한다") + void updateInvalidAccount(String empty) throws Exception { + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); + salaryRepository.save(salary); + + String request = objectMapper.writeValueAsString( + new SeniorAccountRequest(empty, empty, empty) + ); + + mvc.perform(post("/senior/account") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + + @Test + @DisplayName("대학원생 마이페이지 기본 정보를 조회한다") + void getSeniorInfo() throws Exception { + mvc.perform(get("/senior/me") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_INFO.getMessage())) + .andExpect(jsonPath("$.data.seniorId").value(senior.getSeniorId())) + .andExpect(jsonPath("$.data.socialId").isNotEmpty()) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.profile").isNotEmpty()) + .andExpect(jsonPath("$.data.certificationRegister").isNotEmpty()) + .andExpect(jsonPath("$.data.profileRegister").isNotEmpty()); + } + + @Test + @DisplayName("대학원생 마이페이지 프로필 수정시 기존 정보를 조회한다") + void getSeniorProfile() throws Exception { + updateProfile(); + updateAvailable(); + + mvc.perform(get("/senior/me/profile") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_MYPAGE_PROFILE.getMessage())) + .andExpect(jsonPath("$.data.lab").isNotEmpty()) + .andExpect(jsonPath("$.data.keyword").isNotEmpty()) + .andExpect(jsonPath("$.data.info").isNotEmpty()) + .andExpect(jsonPath("$.data.target").isNotEmpty()) + .andExpect(jsonPath("$.data.chatLink").isNotEmpty()) + .andExpect(jsonPath("$.data.field").isNotEmpty()) + .andExpect(jsonPath("$.data.oneLiner").isNotEmpty()) + .andExpect(jsonPath("$.data.times").exists()); + } + + @Test + @DisplayName("등록된 프로필이 없다면 [내 프로필 수정] 기본 정보를 조회할 수 없다") + void getEmptySeniorProfile() throws Exception { + mvc.perform(get("/senior/me/profile") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SeniorResponseCode.NONE_PROFILE.getCode())) + .andExpect(jsonPath("$.message").value(SeniorResponseMessage.NONE_PROFILE.getMessage())); + } + + @Test + @DisplayName("대학원생 마이페이지 프로필을 수정한다") + void updateSeniorProfile() throws Exception { + List availableCreateRequests = List.of( + new AvailableCreateRequest("월", "17:00", "23:00"), + new AvailableCreateRequest("금", "10:00", "20:00"), + new AvailableCreateRequest("토", "10:00", "20:00") + ); + String request = objectMapper.writeValueAsString( + new SeniorMyPageProfileRequest("lab", "keyword1,keyword2", "info", "target", "chatLink", "AI", "oneliner", availableCreateRequests) + ); + + mvc.perform(patch("/senior/me/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_MYPAGE_PROFILE.getMessage())); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("가능 시간대가 비어있으면 예외가 발생한다") + void updateInvalidAvailableSeniorProfile(String empty) throws Exception { + List availableCreateRequests = List.of( + new AvailableCreateRequest(empty, empty, empty), + new AvailableCreateRequest(empty, empty, empty), + new AvailableCreateRequest(empty, empty, empty) + ); + + String request = objectMapper.writeValueAsString( + new SeniorMyPageProfileRequest("lab", "keyword1,keyword2", "info", "target", "chatLink", "AI", "oneliner", availableCreateRequests) + ); + + mvc.perform(patch("/senior/me/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("프로필이 비어있으면 예외가 발생한다") + void updateInvalidSeniorProfile(String empty) throws Exception { + List availableCreateRequests = List.of( + new AvailableCreateRequest("월", "17:00", "23:00"), + new AvailableCreateRequest("금", "10:00", "20:00"), + new AvailableCreateRequest("토", "10:00", "20:00") + ); + + String request = objectMapper.writeValueAsString( + new SeniorMyPageProfileRequest(empty, empty, empty, empty, empty, empty, empty, availableCreateRequests) + ); + + mvc.perform(patch("/senior/me/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + + @Test + @DisplayName("키워드가 6개 초과라면 예외가 발생한다") + void updateInvalidKeyword() throws Exception { + List availableCreateRequests = List.of( + new AvailableCreateRequest("월", "17:00", "23:00"), + new AvailableCreateRequest("금", "10:00", "20:00"), + new AvailableCreateRequest("토", "10:00", "20:00") + ); + String request = objectMapper.writeValueAsString( + new SeniorMyPageProfileRequest("lab", "1,2,3,4,5,6,7", "info", "target", "chatLink", "AI", "oneliner", availableCreateRequests) + ); + + mvc.perform(patch("/senior/me/profile") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SeniorResponseCode.INVALID_KEYWORD.getCode())) + .andExpect(jsonPath("$.message").value(SeniorResponseMessage.INVALID_KEYWORD.getMessage())); + } + + @Test + @DisplayName("등록한 계좌가 없다면 null을 반환한다.") + void getSeniorUserEmptyAccount() throws Exception { + mvc.perform(get("/senior/me/account") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_MYPAGE_ACCOUNT.getMessage())) + .andExpect(jsonPath("$.data.profile").isNotEmpty()) + .andExpect(jsonPath("$.data.phoneNumber").isNotEmpty()) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.bank").isEmpty()) + .andExpect(jsonPath("$.data.accountNumber").isEmpty()) + .andExpect(jsonPath("$.data.accountHolder").isEmpty()); + } + + @Test + @DisplayName("대학원생 마이페이지 계정 설정시 기존 정보를 조회한다") + void getSeniorUserAccount() throws Exception { + updateAccount(); + + mvc.perform(get("/senior/me/account") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_MYPAGE_ACCOUNT.getMessage())) + .andExpect(jsonPath("$.data.profile").isNotEmpty()) + .andExpect(jsonPath("$.data.phoneNumber").isNotEmpty()) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.bank").isNotEmpty()) + .andExpect(jsonPath("$.data.accountNumber").isNotEmpty()) + .andExpect(jsonPath("$.data.accountHolder").isNotEmpty()); + } + + @Test + @DisplayName("대학원생 마이페이지 계정을 설정한다") + void updateSeniorUserAccount() throws Exception { + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); + salaryRepository.save(salary); + + String request = objectMapper.writeValueAsString( + new SeniorMyPageUserAccountRequest("뉴닉", "01098765432", "profile", "98765", "국민", "예금주") + ); + + mvc.perform(patch("/senior/me/account") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_MYPAGE_ACCOOUNT.getMessage())); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("대학원생 마이페이지 계정을 수정 요청에 닉네임, 전화번호, 프로필사진이 없다면 예외가 발생한다") + void updateEmptySeniorUserAccount(String empty) throws Exception { + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); + salaryRepository.save(salary); + + String request = objectMapper.writeValueAsString( + new SeniorMyPageUserAccountRequest(empty, empty, empty, "98765", "국민", "예금주") + ); + + mvc.perform(patch("/senior/me/account") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.VALID_BLANK.getCode())) + .andExpect(jsonPath("$.message").value(ErrorMessage.VALID_BLANK.getMessage())); + } + + @ParameterizedTest + @EmptySource + @DisplayName("계좌등록을 한 선배가 수정할 때 계좌를 입력하지 않으면 예외가 발생한다") + void updateSeniorUserWithoutAccount(String empty) throws Exception { + Account account = new Account(0L, "accountNumber", "bank", "accountHolder", senior); + accountRepository.save(account); + + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); + salaryRepository.save(salary); + + String request = objectMapper.writeValueAsString( + new SeniorMyPageUserAccountRequest("뉴닉", "01098765432", "profile", empty, empty, empty) + ); + + mvc.perform(patch("/senior/me/account") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SeniorResponseCode.NONE_ACCOUNT.getCode())) + .andExpect(jsonPath("$.message").value(SeniorResponseMessage.NONE_ACCOUNT.getMessage())); + } + + @Test + @DisplayName("대학원생을 상세 조회한다") + void getSeniorDetails() throws Exception { + updateProfile(); + updateAvailable(); + + mvc.perform(get("/senior/{seniorId}", senior.getSeniorId())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_INFO.getMessage())) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.term").isNotEmpty()) + .andExpect(jsonPath("$.data.profile").isNotEmpty()) + .andExpect(jsonPath("$.data.postgradu").isNotEmpty()) + .andExpect(jsonPath("$.data.major").isNotEmpty()) + .andExpect(jsonPath("$.data.lab").isNotEmpty()) + .andExpect(jsonPath("$.data.professor").isNotEmpty()) + .andExpect(jsonPath("$.data.keyword").isNotEmpty()) + .andExpect(jsonPath("$.data.info").isNotEmpty()) + .andExpect(jsonPath("$.data.oneLiner").isNotEmpty()) + .andExpect(jsonPath("$.data.target").isNotEmpty()) + .andExpect(jsonPath("$.data.times").isNotEmpty()) + ; + } + + @ParameterizedTest + @EnumSource(value = Status.class, names = {"NOT_APPROVE", "WAITING"}) + @DisplayName("승인되지 않은 대학원생은 조회되지 않는다.") + void getNotApprovedSeniorDetails(Status status) throws Exception { + senior.updateStatus(status); + seniorRepository.save(senior); + + mvc.perform(get("/senior/{seniorId}", senior.getSeniorId())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SeniorResponseCode.NONE_SENIOR.getCode())) + .andExpect(jsonPath("$.message").value(SeniorResponseMessage.NONE_SENIOR.getMessage())); + } + + @Test + @DisplayName("결제 시 대학원생의 기본 정보를 확인한다") + void testGetSeniorProfile() throws Exception { + updateProfile(); + updateAvailable(); + + mvc.perform(get("/senior/{seniorId}/profile", senior.getSeniorId())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_INFO.getMessage())) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.profile").isNotEmpty()) + .andExpect(jsonPath("$.data.major").isNotEmpty()) + .andExpect(jsonPath("$.data.lab").isNotEmpty()) + .andExpect(jsonPath("$.data.term").isNotEmpty()); + } + + @Test + @DisplayName("신청서 작성 시 대학원생의 가능 시간 정보를 조회한다") + void getSeniorTimes() throws Exception { + updateProfile(); + updateAvailable(); + + mvc.perform(get("/senior/{seniorId}/times", senior.getSeniorId())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_TIME.getMessage())) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.times").isNotEmpty()); + } + + @Test + @DisplayName("대학원생을 검색한다") + void getSearchSenior() throws Exception { + mvc.perform(get("/senior/search", senior.getSeniorId()) + .param("find", "keyword")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_LIST_INFO.getMessage())) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].seniorId").value(senior.getSeniorId())) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].profile").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].postgradu").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].major").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].lab").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].keyword").isNotEmpty()); + } + + @Test + @DisplayName("대학원생을 분야와 대학교로 검색한다") + void getFieldSenior() throws Exception { + mvc.perform(get("/senior/field", senior.getSeniorId()) + .param("field", "field") + .param("postgradu", "postgradu")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_LIST_INFO.getMessage())) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].seniorId").value(senior.getSeniorId())) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].profile").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].postgradu").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].major").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].lab").isNotEmpty()) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].keyword").isNotEmpty()); + } + + @Test + @DisplayName("후배 전환시 가능 여부를 확인한다") + void checkRole() throws Exception { + mvc.perform(get("/senior/me/role") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_USER_CHECK.getMessage())) + .andExpect(jsonPath("$.data.possible").isNotEmpty()); + } +} \ No newline at end of file diff --git a/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java b/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java new file mode 100644 index 00000000..e347c8f9 --- /dev/null +++ b/src/test/java/com/postgraduate/domain/user/presentation/UserControllerTest.java @@ -0,0 +1,148 @@ +package com.postgraduate.domain.user.presentation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.postgraduate.IntegrationTest; +import com.postgraduate.domain.user.application.dto.req.UserInfoRequest; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.entity.constant.Role; +import com.postgraduate.domain.user.domain.repository.UserRepository; +import com.postgraduate.domain.user.presentation.constant.UserResponseCode; +import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import com.postgraduate.global.slack.SlackMessage; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; + +import java.io.IOException; + +import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_FIND; +import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_UPDATE; +import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.*; +import static java.time.LocalDateTime.now; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class UserControllerTest extends IntegrationTest { + private static final String AUTHORIZATION = "Authorization"; + private static final String BEARER = "Bearer "; + @Autowired + private ObjectMapper objectMapper; + @Autowired + private JwtUtils jwtUtil; + @Autowired + private UserRepository userRepository; + @MockBean + private SlackMessage slackMessage; + private String token; + + @BeforeEach + void setUp() throws IOException { + User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + userRepository.save(user); + + token = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + + doNothing().when(slackMessage).sendSlackLog(any()); + } + + @Test + @DisplayName("유저 마이페이지 정보를 조회한다") + void getUserInfo() throws Exception { + mvc.perform(get("/user/me") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_USER_INFO.getMessage())) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.profile").isNotEmpty()); + } + + @Test + @DisplayName("유저 마이페이지 수정 전 기본 정보를 조회한다") + void getOriginUserInfo() throws Exception { + mvc.perform(get("/user/me/info") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_USER_INFO.getMessage())) + .andExpect(jsonPath("$.data.profile").isNotEmpty()) + .andExpect(jsonPath("$.data.nickName").isNotEmpty()) + .andExpect(jsonPath("$.data.phoneNumber").isNotEmpty()); + } + + @Test + @DisplayName("유저 마이페이지 정보를 수정한다.") + void updateInfo() throws Exception { + String request = objectMapper.writeValueAsString( + new UserInfoRequest("new_profile", "new후배", "01012345667") + ); + mvc.perform(patch("/user/me/info") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_USER_INFO.getMessage())); + } + + @ParameterizedTest + @ValueSource(strings = {"0101234567", "번호를한글열하나글자로"}) + @DisplayName("잘못된 번호로 수정할 수 없다") + void updateInvalidPhoneNumber(String phoneNumber) throws Exception { + String request = objectMapper.writeValueAsString( + new UserInfoRequest("new_profile", "new후배", phoneNumber) + ); + mvc.perform(patch("/user/me/info") + .header(AUTHORIZATION, BEARER + token) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(UserResponseCode.INVALID_PHONE_NUMBER.getCode())) + .andExpect(jsonPath("$.message").value(INVALID_PHONE_NUMBER.getMessage())); + } + + @Test + @DisplayName("선배 전환 가능 여부를 확인한다") + void checkRole() throws Exception { + mvc.perform(get("/user/me/role") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_SENIOR_CHECK.getMessage())) + .andExpect(jsonPath("$.data.possible").isNotEmpty()) + .andExpect(jsonPath("$.data.socialId").isNotEmpty()); + } + + @Test + @DisplayName("사용 가능한 닉네임 중복체크를 한다") + void duplicatedPossibleNickName() throws Exception { + mvc.perform(get("/user/nickname") + .param("nickName", "new후배")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_NICKNAME_CHECK.getMessage())) + .andExpect(jsonPath("$.data").value(true)); + } + + @Test + @DisplayName("사용 불가능한 닉네임 중복체크를 한다") + void duplicatedImpossibleNickName() throws Exception { + mvc.perform(get("/user/nickname") + .param("nickName", "후배")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_NICKNAME_CHECK.getMessage())) + .andExpect(jsonPath("$.data").value(false)); + } +} \ No newline at end of file