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 4fc85d6 commit 7015e33
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 233 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 @@ -45,7 +45,7 @@ class ApproveFormUseCaseTest {
void 원서를_승인할__원서가_없으면_에러가_발생한다() {
// given
Form form = FormFixture.createForm(FormType.REGULAR);
form.submit("https://maru.bamdoliro.com/form.pdf");
form.submit();
willThrow(new FormNotFoundException()).given(formFacade).getForm(form.getId());

// when and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ExportFormUseCaseTest {
// given
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.REGULAR);
form.submit("https://maru.bamdoliro.com/form.pdf");
form.submit();
given(formFacade.getForm(user)).willReturn(form);

// when and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.bamdoliro.maru.domain.form.domain.Form;
import com.bamdoliro.maru.domain.form.domain.type.FormStatus;
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.domain.form.service.AssignExaminationNumberService;
import com.bamdoliro.maru.domain.form.service.CalculateFormScoreService;
import com.bamdoliro.maru.domain.user.domain.User;
Expand All @@ -23,8 +22,6 @@
import java.util.List;
import java.util.Random;

import static com.bamdoliro.maru.domain.form.domain.type.FormStatus.SUBMITTED;

@Disabled
@ActiveProfiles("test")
@SpringBootTest
Expand Down Expand Up @@ -56,7 +53,7 @@ void setUp() {
assignExaminationNumberService.execute(form);

switch (randomFormStatus()) {
case FINAL_SUBMITTED -> form.submit("");
case FINAL_SUBMITTED -> form.submit();
case APPROVED -> form.approve();
case REJECTED -> form.reject();
case RECEIVED -> form.receive();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.bamdoliro.maru.application.form;

import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.infrastructure.s3.FileService;
import com.bamdoliro.maru.presentation.form.dto.response.FormUrlResponse;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.shared.fixture.SharedFixture;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -12,6 +14,7 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -25,6 +28,9 @@ class QueryFormUrlUseCaseTest {
@Mock
private FormRepository formRepository;

@Mock
private FileService fileService;

@Test
void 원서_url_조회한다() {
// given
Expand All @@ -34,6 +40,7 @@ class QueryFormUrlUseCaseTest {
FormFixture.createFormUrlVo(),
FormFixture.createFormUrlVo()
));
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse());

// when
List<FormUrlResponse> responseList = queryFormUrlUseCase.execute(idList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import com.bamdoliro.maru.domain.form.exception.FormNotFoundException;
import com.bamdoliro.maru.domain.form.service.FormFacade;
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.domain.user.service.UserFacade;
import com.bamdoliro.maru.infrastructure.s3.FileService;
import com.bamdoliro.maru.presentation.form.dto.response.FormResponse;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.shared.fixture.SharedFixture;
import com.bamdoliro.maru.shared.fixture.UserFixture;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -18,6 +19,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
Expand All @@ -32,6 +34,9 @@ class QueryFormUseCaseTest {
@Mock
private FormFacade formFacade;

@Mock
private FileService fileService;

@Test
void 원서를_조회한다() {
// given
Expand All @@ -41,6 +46,7 @@ class QueryFormUseCaseTest {


given(formFacade.getForm(id)).willReturn(form);
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse());

// when
FormResponse response = queryFormUseCase.execute(user, id);
Expand Down Expand Up @@ -74,7 +80,6 @@ class QueryFormUseCaseTest {
Long id = -1L;
User user = UserFixture.createUser();


willThrow(new FormNotFoundException()).given(formFacade).getForm(id);

// when and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RejectFormUseCaseTest {
void 원서를_반려할__원서가_없으면_에러가_발생한다() {
// given
Form form = FormFixture.createForm(FormType.REGULAR);
form.submit("https://maru.bamdoliro.com/form.pdf");
form.submit();
willThrow(new FormNotFoundException()).given(formFacade).getForm(form.getId());

// when and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.presentation.form.dto.request.SubmitFinalFormRequest;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -33,15 +32,13 @@ class SubmitFinalFormUseCaseTest {
void 원서를_최종_제출한다() {
// given
Form form = FormFixture.createForm(FormType.REGULAR);
SubmitFinalFormRequest request = new SubmitFinalFormRequest("https://maru.bamdoliro.com/form.pdf");

given(formFacade.getForm(any(User.class))).willReturn(form);

// when
submitFinalFormUseCase.execute(form.getUser(), request);
submitFinalFormUseCase.execute(form.getUser());

// then
assertEquals(form.getFormUrl(), request.getFormUrl());
verify(formFacade, times(1)).getForm(any(User.class));
}

Expand All @@ -50,14 +47,12 @@ class SubmitFinalFormUseCaseTest {
// given
Form form = FormFixture.createForm(FormType.REGULAR);
form.approve();
SubmitFinalFormRequest request = new SubmitFinalFormRequest("https://maru.bamdoliro.com/form.pdf");

given(formFacade.getForm(any(User.class))).willReturn(form);

// when and then
assertThrows(FormAlreadySubmittedException.class, () -> submitFinalFormUseCase.execute(form.getUser(), request));
assertThrows(FormAlreadySubmittedException.class, () -> submitFinalFormUseCase.execute(form.getUser()));

assertNull(form.getFormUrl());
verify(formFacade, times(1)).getForm(any(User.class));
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package com.bamdoliro.maru.application.form;

import com.bamdoliro.maru.domain.form.domain.Form;
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.infrastructure.s3.UploadFileService;
import com.bamdoliro.maru.infrastructure.s3.dto.response.UploadResponse;
import com.bamdoliro.maru.infrastructure.s3.validator.FileValidator;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.infrastructure.s3.FileService;
import com.bamdoliro.maru.shared.fixture.SharedFixture;
import com.bamdoliro.maru.shared.fixture.UserFixture;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.nio.charset.StandardCharsets;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
Expand All @@ -31,25 +22,18 @@ class UploadFormUseCaseTest {
private UploadFormUseCase uploadFormUseCase;

@Mock
private UploadFileService uploadFileService;
private FileService fileService;

@Test
void 원서_서류를_업로드한다() {
// given
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.REGULAR);
MockMultipartFile image = new MockMultipartFile(
"file",
"file.pdf",
MediaType.APPLICATION_PDF_VALUE,
"<<file>>".getBytes(StandardCharsets.UTF_8)
);
given(uploadFileService.execute(any(MultipartFile.class), any(String.class), any(String.class), any(FileValidator.class))).willReturn(new UploadResponse("https://host.com/image.pdf"));
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse());

// when
uploadFormUseCase.execute(user, image);
uploadFormUseCase.execute(user);

// then
verify(uploadFileService, times(1)).execute(any(MultipartFile.class), any(String.class), any(String.class), any(FileValidator.class));
verify(fileService, times(1)).getPresignedUrl(any(String.class), any(String.class));
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
package com.bamdoliro.maru.application.form;

import com.bamdoliro.maru.domain.form.domain.Form;
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.infrastructure.s3.UploadFileService;
import com.bamdoliro.maru.infrastructure.s3.dto.response.UploadResponse;
import com.bamdoliro.maru.infrastructure.s3.exception.ImageSizeMismatchException;
import com.bamdoliro.maru.infrastructure.s3.validator.FileValidator;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.infrastructure.s3.FileService;
import com.bamdoliro.maru.shared.fixture.SharedFixture;
import com.bamdoliro.maru.shared.fixture.UserFixture;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand All @@ -34,47 +22,18 @@ class UploadIdentificationPictureUseCaseTest {
private UploadIdentificationPictureUseCase uploadIdentificationPictureUseCase;

@Mock
private UploadFileService uploadFileService;
private FileService fileService;

@Test
void 증명_사진을_업로드한다() {
// given
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.MEISTER_TALENT);
String fileName = "identification-picture.png";
MockMultipartFile image = new MockMultipartFile(
"image",
fileName,
MediaType.IMAGE_PNG_VALUE,
"<<image>>".getBytes(StandardCharsets.UTF_8)
);
given(uploadFileService.execute(any(MultipartFile.class), any(String.class), any(String.class), any(FileValidator.class))).willReturn(new UploadResponse("https://host.com/image.png"));
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createIdentificationPictureUrlResponse());

// when
uploadIdentificationPictureUseCase.execute(user, image);
uploadIdentificationPictureUseCase.execute(user);

// then
verify(uploadFileService, times(1)).execute(any(MultipartFile.class), any(String.class), any(String.class), any(FileValidator.class));
}

@Test
void 증명_사진의_크기가_크면_에러가_발생한다() {
// given
User user = UserFixture.createUser();
Form form = FormFixture.createForm(FormType.MEISTER_TALENT);
String fileName = "identification-picture-big.png";
MockMultipartFile image = new MockMultipartFile(
"image",
fileName,
MediaType.IMAGE_PNG_VALUE,
"<<image>>".getBytes(StandardCharsets.UTF_8)
);
willThrow(ImageSizeMismatchException.class).given(uploadFileService).execute(any(MultipartFile.class), any(String.class), any(String.class), any(FileValidator.class));

// when and then
assertThrows(ImageSizeMismatchException.class,
() -> uploadIdentificationPictureUseCase.execute(user, image));

verify(uploadFileService, times(1)).execute(any(MultipartFile.class), any(String.class), any(String.class), any(FileValidator.class));
verify(fileService, times(1)).getPresignedUrl(any(String.class), any(String.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SendMessageUseCaseTest {

//given
Form form = FormFixture.createForm(FormType.REGULAR);
form.submit("https://maru.bamdoliro.com/pdf/1");
form.submit();
given(formRepository.findByStatus(FormStatus.FINAL_SUBMITTED)).willReturn(List.of(form));
SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "테스트입니다", FormStatus.FINAL_SUBMITTED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void isReceived() {
Form form = FormFixture.createForm(FormType.REGULAR);
assertFalse(form.isReceived());

form.submit("");
form.submit();
assertFalse(form.isReceived());

form.approve();
Expand Down Expand Up @@ -48,7 +48,7 @@ void isFirstPassed() {
Form form = FormFixture.createForm(FormType.REGULAR);
assertNull(form.isFirstPassed());

form.submit("");
form.submit();
assertNull(form.isFirstPassed());

form.approve();
Expand Down Expand Up @@ -81,7 +81,7 @@ void isPassed() {
Form form = FormFixture.createForm(FormType.REGULAR);
assertNull(form.isPassed());

form.submit("");
form.submit();
assertNull(form.isPassed());

form.approve();
Expand Down
Loading

0 comments on commit 7015e33

Please sign in to comment.