Skip to content

Commit

Permalink
test(#111): 원서 테스트 수정
Browse files Browse the repository at this point in the history
- presigned url로 바뀐 파일 업로드 방식에 따라 테스트를 변경했어요.
  • Loading branch information
cabbage16 committed Aug 12, 2024
1 parent 17395fd commit ece13e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public FormResponse execute(User user, Long id) {
Form form = formFacade.getForm(id);
form.isApplicantOrAdmin(user);

String uuid = form.getUser( ).getUuid().toString();
String uuid = form.getUser().getUuid().toString();
String identificationPictureUri = fileService.getPresignedUrl(FolderConstant.IDENTIFICATION_PICTURE, uuid).getDownloadUrl();
String formUrl = fileService.getPresignedUrl(FolderConstant.FORM, uuid).getDownloadUrl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import com.bamdoliro.maru.domain.form.domain.Form;
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.domain.form.exception.FormAlreadySubmittedException;
import com.bamdoliro.maru.domain.form.service.FormFacade;
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.infrastructure.pdf.GeneratePdfService;
import com.bamdoliro.maru.infrastructure.pdf.MergePdfService;
import com.bamdoliro.maru.infrastructure.pdf.exception.FailedToExportPdfException;
import com.bamdoliro.maru.infrastructure.s3.FileService;
import com.bamdoliro.maru.infrastructure.thymeleaf.ProcessTemplateService;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.shared.fixture.SharedFixture;
import com.bamdoliro.maru.shared.fixture.UserFixture;
import com.itextpdf.kernel.utils.PdfMerger;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -48,9 +47,6 @@ class ExportFormUseCaseTest {
@Mock
private MergePdfService mergePdfService;

@Mock
private FileService fileService;

@Test
void 일반전형_원서를_pdf_다운받는다() {
// given
Expand All @@ -60,7 +56,6 @@ class ExportFormUseCaseTest {
given(processTemplateService.execute(any(String.class), any())).willReturn("html");
given(generatePdfService.execute(any(String.class))).willReturn(new ByteArrayOutputStream());
willDoNothing().given(mergePdfService).execute(any(PdfMerger.class), any(ByteArrayOutputStream.class));
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse());

// when
exportFormUseCase.execute(user);
Expand All @@ -70,7 +65,6 @@ class ExportFormUseCaseTest {
verify(processTemplateService, times(4)).execute(any(String.class), any());
verify(generatePdfService, times(4)).execute(any(String.class));
verify(mergePdfService, times(4)).execute(any(PdfMerger.class), any(ByteArrayOutputStream.class));
verify(fileService, times(1)).getPresignedUrl(any(String.class), any(String.class));
}

@Test
Expand All @@ -81,7 +75,6 @@ class ExportFormUseCaseTest {
given(formFacade.getForm(user)).willReturn(form);
given(processTemplateService.execute(any(String.class), any())).willReturn("html");
given(generatePdfService.execute(any(String.class))).willReturn(new ByteArrayOutputStream());
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse());
willDoNothing().given(mergePdfService).execute(any(PdfMerger.class), any(ByteArrayOutputStream.class));

// when
Expand All @@ -92,7 +85,23 @@ class ExportFormUseCaseTest {
verify(processTemplateService, times(5)).execute(any(String.class), any());
verify(generatePdfService, times(5)).execute(any(String.class));
verify(mergePdfService, times(5)).execute(any(PdfMerger.class), any(ByteArrayOutputStream.class));
verify(fileService, times(1)).getPresignedUrl(any(String.class), any(String.class));
}

@Test
void 원서를_pdf_다운받을__이미_제출한_원서라면_에러가_발생한다() {
// given
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.REGULAR);
form.submit();
given(formFacade.getForm(user)).willReturn(form);

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

verify(formFacade, times(1)).getForm(user);
verify(processTemplateService, never()).execute(any(String.class), any());
verify(generatePdfService, never()).execute(any(String.class));
verify(mergePdfService, never()).execute(any(PdfMerger.class), any(ByteArrayOutputStream.class));
}

@Test
Expand All @@ -102,7 +111,6 @@ class ExportFormUseCaseTest {
Form form = FormFixture.createForm(FormType.REGULAR);
given(formFacade.getForm(user)).willReturn(form);
given(processTemplateService.execute(any(String.class), any())).willReturn("html");
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse());
doThrow(FailedToExportPdfException.class).when(generatePdfService).execute(any(String.class));

// when and then
Expand All @@ -113,6 +121,5 @@ class ExportFormUseCaseTest {
verify(processTemplateService, times(1)).execute(any(String.class), any());
verify(generatePdfService, times(1)).execute(any(String.class));
verify(mergePdfService, never()).execute(any(PdfMerger.class), any(ByteArrayOutputStream.class));
verify(fileService, times(1)).getPresignedUrl(any(String.class), any(String.class));
}
}

0 comments on commit ece13e9

Please sign in to comment.