Skip to content

Commit

Permalink
test(#151): 테스트 수정 및 추가
Browse files Browse the repository at this point in the history
- 원서 상태가 반려되면 초안 제출부터 다시할 수 있는지 테스트 코드를 작성했어요.
- 기존의 재제출 에러 테스트를 반려상태가 아니면서 이미 원서가 존재할 때 예외가 발생하도록 변경했어요.
  • Loading branch information
jyj1289 committed Oct 13, 2024
1 parent 56a0240 commit f120f2f
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -61,19 +63,44 @@ class SubmitFormUseCaseTest {
}

@Test
void 원서를_제출할__이미_제출한_원서가_있으면_에러가_발생한다() {
void 원서를_제출할__이미_제출한_원서가_반려상태가_아니면서_있으면_에러가_발생한다() {
// given
SubmitFormRequest request = FormFixture.createFormRequest(FormType.REGULAR);
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.REGULAR);

given(formRepository.existsByUserId(user.getId())).willReturn(true);
given(formRepository.findByUser(user)).willReturn(Optional.of(form));

// when and then
assertThrows(FormAlreadySubmittedException.class, () -> submitFormUseCase.execute(user, request));

verify(formRepository, times(1)).existsByUserId(user.getId());
verify(calculateFormScoreService, never()).execute(any(Form.class));
verify(assignExaminationNumberService, never()).execute(any(Form.class));
verify(formRepository, never()).deleteByUser(any(User.class));
verify(formRepository, never()).save(any(Form.class));
}

@Test
void 원서를_제출할__이미_제출한_원서가_반려상태면_다시_작성한다() {
//given
SubmitFormRequest request = FormFixture.createFormRequest(FormType.REGULAR);
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.REGULAR);
form.reject();

given(formRepository.existsByUserId(user.getId())).willReturn(true);
given(formRepository.findByUser(user)).willReturn(Optional.of(form));

//when
submitFormUseCase.execute(user, request);

//then
verify(formRepository, times(1)).existsByUserId(user.getId());
verify(calculateFormScoreService, times(1)).execute(any(Form.class));
verify(assignExaminationNumberService, times(1)).execute(any(Form.class));
verify(formRepository, times(1)).deleteByUser(any(User.class));
verify(formRepository, times(1)).save(any(Form.class));
}
}

0 comments on commit f120f2f

Please sign in to comment.