diff --git a/src/test/java/com/bamdoliro/maru/application/form/SubmitFormUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/form/SubmitFormUseCaseTest.java index 54fd09fc..3bbae926 100644 --- a/src/test/java/com/bamdoliro/maru/application/form/SubmitFormUseCaseTest.java +++ b/src/test/java/com/bamdoliro/maru/application/form/SubmitFormUseCaseTest.java @@ -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; @@ -61,12 +63,14 @@ 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)); @@ -74,6 +78,29 @@ class SubmitFormUseCaseTest { 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)); + } } \ No newline at end of file