Skip to content

Commit

Permalink
RAC-307 test : 변경사항 테스트 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
ywj9811 committed Feb 4, 2024
1 parent 7ce045a commit 3d32813
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.postgraduate.domain.mentoring.domain.service.MentoringSaveService;
import com.postgraduate.domain.mentoring.exception.MentoringDateException;
import com.postgraduate.domain.payment.domain.entity.Payment;
import com.postgraduate.domain.payment.domain.service.PaymentGetService;
import com.postgraduate.domain.senior.domain.entity.Info;
import com.postgraduate.domain.senior.domain.entity.Profile;
import com.postgraduate.domain.senior.domain.entity.Senior;
Expand Down Expand Up @@ -45,6 +46,9 @@ class MentoringApplyUseCaseTest {
@Mock
private MentoringSaveService mentoringSaveService;

@Mock
private PaymentGetService paymentGetService;

@InjectMocks
private MentoringApplyUseCase mentoringApplyUseCase;

Expand All @@ -60,15 +64,17 @@ void applyMentoring() {
, USER, TRUE, LocalDateTime.now(), LocalDateTime.now(), FALSE);
Senior senior = new Senior(1L, seniorUser, "a", Status.WAITING,
100, new Info(), new Profile(), now(), now());
MentoringApplyRequest request = new MentoringApplyRequest(senior.getSeniorId(), "topic", "ques", "1201,1202,1203");

MentoringApplyRequest request = new MentoringApplyRequest("1", senior.getSeniorId(), "topic", "ques", "1201,1202,1203");

given(paymentGetService.byOrderId(any()))
.willReturn(payment);
given(seniorGetService.bySeniorId(request.seniorId()))
.willReturn(senior);
Mentoring mentoring = mapToMentoring(user, senior, payment, request);
given(mentoringSaveService.save(any()))
.willReturn(mentoring);

assertThat(mentoringApplyUseCase.applyMentoring(user, request))
assertThat(mentoringApplyUseCase.applyMentoringWithPayment(user, request))
.isEqualTo(mentoring.getMentoringId());
}

Expand All @@ -77,9 +83,12 @@ void applyMentoring() {
@DisplayName("날짜 예외 테스트 3보다 작을 경우")
void applyMentoringWithInvalidDatesSmaller(String dates) {
User user = mock(User.class);
MentoringApplyRequest request = new MentoringApplyRequest(-1L, "topic", "ques", dates);
Payment payment = mock(Payment.class);
MentoringApplyRequest request = new MentoringApplyRequest("1", -1L, "topic", "ques", dates);
given(paymentGetService.byOrderId(any()))
.willReturn(payment);

assertThatThrownBy(()-> mentoringApplyUseCase.applyMentoring(user, request))
assertThatThrownBy(()-> mentoringApplyUseCase.applyMentoringWithPayment(user, request))
.isInstanceOf(MentoringDateException.class);
}

Expand All @@ -88,9 +97,13 @@ void applyMentoringWithInvalidDatesSmaller(String dates) {
@DisplayName("날짜 예외 테스트 3보다 큰 경우")
void applyMentoringWithInvalidDateBigger(String dates) {
User user = mock(User.class);
MentoringApplyRequest request = new MentoringApplyRequest(-1L, "topic", "ques", dates);
Payment payment = mock(Payment.class);

MentoringApplyRequest request = new MentoringApplyRequest("1", -1L, "topic", "ques", dates);
given(paymentGetService.byOrderId(any()))
.willReturn(payment);

assertThatThrownBy(()-> mentoringApplyUseCase.applyMentoring(user, request))
assertThatThrownBy(()-> mentoringApplyUseCase.applyMentoringWithPayment(user, request))
.isInstanceOf(MentoringDateException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void setUp() throws IOException {
salary = new Salary(0L, false, senior, payments, 20000, LocalDate.now(), LocalDateTime.now(), null, null, null);
salaryRepository.save(salary);

payment = new Payment(0L, salary, user, 20000, "123", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE);
payment = new Payment(0L, salary, user, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE);
paymentRepository.save(payment);

userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER);
Expand Down Expand Up @@ -185,7 +185,7 @@ void getDoneMentoringDetail(Status status) throws Exception {
@Test
@DisplayName("대학생이 멘토링을 신청한다.")
void applyMentoring() throws Exception {
String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), "topic", "question", "date1,date2,date3"));
String request = objectMapper.writeValueAsString(new MentoringApplyRequest("1", senior.getSeniorId(), "topic", "question", "date1,date2,date3"));

mvc.perform(post("/mentoring/applying")
.header(AUTHORIZATION, BEARER + userAccessToken)
Expand All @@ -201,7 +201,7 @@ void applyMentoring() throws Exception {
@ValueSource(strings = {"date1", "date1,date2", "date1,date2,date3,date4"})
@DisplayName("날짜가 3개가 아니라면 멘토링을 신청할 수 없다.")
void applyMentoringWithoutThreeDates(String date) throws Exception {
String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), "topic", "question", date));
String request = objectMapper.writeValueAsString(new MentoringApplyRequest("1", senior.getSeniorId(), "topic", "question", date));

mvc.perform(post("/mentoring/applying")
.header(AUTHORIZATION, BEARER + userAccessToken)
Expand All @@ -218,7 +218,7 @@ void applyMentoringWithoutThreeDates(String date) throws Exception {
@NullAndEmptySource
@DisplayName("신청서가 빈 칸이라면 멘토링을 신청할 수 없다")
void emptyApplyMentoring(String empty) throws Exception {
String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), empty, empty, empty));
String request = objectMapper.writeValueAsString(new MentoringApplyRequest("1", senior.getSeniorId(), empty, empty, empty));

mvc.perform(post("/mentoring/applying")
.header(AUTHORIZATION, BEARER + userAccessToken)
Expand Down

0 comments on commit 3d32813

Please sign in to comment.