Skip to content

Commit

Permalink
Merge pull request #93 from WE-ARE-RACCOONS/RAC-254
Browse files Browse the repository at this point in the history
RAC-254 test: ν†΅ν•©ν…ŒμŠ€νŠΈ
  • Loading branch information
ay-eonii authored Jan 21, 2024
2 parents cafdabb + 5a5017f commit 48f1165
Show file tree
Hide file tree
Showing 16 changed files with 1,134 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,21 +19,7 @@ public static List<Available> sortAvailable(List<AvailableCreateRequest> 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 -> {
Expand All @@ -46,4 +35,17 @@ public static List<Available> sortAvailable(List<AvailableCreateRequest> 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,6 +30,7 @@ public List<Payment> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -22,5 +23,7 @@ public record SeniorMyPageProfileRequest(
@NotBlank
String oneLiner,
@NotEmpty
@Valid
List<AvailableCreateRequest> times
) {}
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Account> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Available> availables = availableGetService.bySenior(senior);
List<AvailableTimeResponse> times = availables.stream()
.map(AvailableMapper::mapToAvailableTimes)
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public enum SeniorResponseMessage {
INVALID_KEYWORD("ν‚€μ›Œλ“œκ°€ 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€."),
NOT_WAITING_STATUS("μŠΉμΈλŒ€κΈ° μƒνƒœμ˜ μ„ λ°°κ°€ μ•„λ‹™λ‹ˆλ‹€."),
EMPTY_TIME("κ°€λŠ₯ μ‹œκ°„μ΄ λΉ„μ—ˆμŠ΅λ‹ˆλ‹€."),
INVALID_DAY("잘λͺ»λœ μš”μΌμž…λ‹ˆλ‹€."),
NONE_PROFILE("λ“±λ‘ν•œ ν”„λ‘œν•„μ΄ μ—†μŠ΅λ‹ˆλ‹€."),
;

private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 48f1165

Please sign in to comment.