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 ec026ad commit d52e9d6
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

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 @@ -47,6 +48,9 @@ class ExportFormUseCaseTest {
@Mock
private MergePdfService mergePdfService;

@Mock
private FileService fileService;

@Test
void 일반전형_원서를_pdf_다운받는다() {
// given
Expand All @@ -55,6 +59,7 @@ 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 @@ -65,6 +70,7 @@ 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 @@ -75,6 +81,7 @@ 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 @@ -85,23 +92,7 @@ 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));
}

@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));
verify(fileService, times(1)).getPresignedUrl(any(String.class), any(String.class));
}

@Test
Expand All @@ -111,6 +102,7 @@ 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 @@ -121,5 +113,6 @@ 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 d52e9d6

Please sign in to comment.