Skip to content

Commit

Permalink
Merge pull request #50 from STUDIO-EYE/develop
Browse files Browse the repository at this point in the history
V.0.0.6
  • Loading branch information
phonil authored Nov 18, 2024
2 parents 7590e3e + 84f3c96 commit 33e3461
Show file tree
Hide file tree
Showing 8 changed files with 1,776 additions and 473 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public ApiResponse<CompanyInformation> deleteCompanyBasicInformation() {
public ApiResponse<CompanyInformation> deleteCompanyIntroductionInformation() {
List<CompanyInformation> companyInformations = companyInformationRepository.findAll();
if (companyInformations.isEmpty()) {
ApiResponse.withError(ErrorCode.COMPANYINFORMATION_IS_EMPTY);
return ApiResponse.withError(ErrorCode.COMPANYINFORMATION_IS_EMPTY);
}
for (CompanyInformation companyInformation : companyInformations) {
String fileName = companyInformation.getSloganImageFileName();
Expand All @@ -393,7 +393,7 @@ public ApiResponse<CompanyInformation> deleteCompanyIntroductionInformation() {
public ApiResponse<CompanyInformation> deleteCompanyDetailInformation() {
List<CompanyInformation> companyInformations = companyInformationRepository.findAll();
if (companyInformations.isEmpty()) {
ApiResponse.withError(ErrorCode.COMPANYINFORMATION_IS_EMPTY);
return ApiResponse.withError(ErrorCode.COMPANYINFORMATION_IS_EMPTY);
}
CompanyInformation companyInformation = companyInformations.get(0);
companyInformation.deleteCompanyDetailInformation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class EmailService {
// }

public boolean sendEmail(String to, String subject, String text) {
if (to == null || to.isEmpty()) {
throw new IllegalArgumentException("Invalid recipient address");
}
int emailSize = calculateEmailSize(subject, text);
if(emailSize > MAX_EMAIL_SIZE) {
System.out.println("over size");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1372,19 +1372,19 @@ void deleteCompanyIntroductionInformationSuccess() {
verify(s3Adapter, times(1)).deleteFile(anyString()); // S3 파일 삭제 호출 확인
verify(companyInformationRepository, times(1)).save(any(CompanyInformation.class)); // 저장 호출 확인
}
// @Test
// @DisplayName("회사 소개 정보 삭제 실패 - 회사 정보 없음")
// void deleteCompanyIntroductionInformation_emptyCompany_returnsErrorResponse() {
// // given
// when(companyInformationRepository.findAll()).thenReturn(Collections.emptyList());
//
// // when
// ApiResponse<CompanyInformation> response = companyInformationService.deleteCompanyIntroductionInformation();
//
// // then
// assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());
// assertEquals(ErrorCode.COMPANYINFORMATION_IS_EMPTY.getMessage(), response.getMessage());
// }
@Test
@DisplayName("회사 소개 정보 삭제 실패 - 회사 정보 없음")
void deleteCompanyIntroductionInformation_emptyCompany_returnsErrorResponse() {
// given
when(companyInformationRepository.findAll()).thenReturn(Collections.emptyList());

// when
ApiResponse<CompanyInformation> response = companyInformationService.deleteCompanyIntroductionInformation();

// then
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());
assertEquals(ErrorCode.COMPANYINFORMATION_IS_EMPTY.getMessage(), response.getMessage());
}
@Test
@DisplayName("회사 상세 정보 삭제 성공")
void deleteCompanyDetailInformationSuccess() {
Expand All @@ -1402,17 +1402,17 @@ void deleteCompanyDetailInformationSuccess() {
assertEquals("회사 5가지 상세 정보를 성공적으로 삭제했습니다.", response.getMessage());
verify(companyInformationRepository, times(1)).save(any(CompanyInformation.class)); // 저장 호출 확인
}
// @Test
// @DisplayName("회사 상세 정보 삭제 실패 - 회사 정보 없음")
// void deleteCompanyDetailInformation_emptyCompany_returnsErrorResponse() {
// // given
// when(companyInformationRepository.findAll()).thenReturn(Collections.emptyList());
//
// // when
// ApiResponse<CompanyInformation> response = companyInformationService.deleteCompanyDetailInformation();
//
// // then
// assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());
// assertEquals(ErrorCode.COMPANYINFORMATION_IS_EMPTY.getMessage(), response.getMessage());
// }
@Test
@DisplayName("회사 상세 정보 삭제 실패 - 회사 정보 없음")
void deleteCompanyDetailInformation_emptyCompany_returnsErrorResponse() {
// given
when(companyInformationRepository.findAll()).thenReturn(Collections.emptyList());

// when
ApiResponse<CompanyInformation> response = companyInformationService.deleteCompanyDetailInformation();

// then
assertEquals(HttpStatus.BAD_REQUEST, response.getStatus());
assertEquals(ErrorCode.COMPANYINFORMATION_IS_EMPTY.getMessage(), response.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;


@ExtendWith(MockitoExtension.class)
public class CeoServiceTest {
@InjectMocks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package studio.studioeye.domain.email.application;

import org.junit.jupiter.api.DisplayName;
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.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import studio.studioeye.domain.email.service.EmailService;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class EmailServiceTest {

@InjectMocks
private EmailService emailService; // EmailService를 올바르게 주입

@Mock
private JavaMailSender javaMailSender;

@Test
@DisplayName("이메일 전송 성공 테스트")
public void sendEmailSuccess() {
// given
String to = "[email protected]";
String subject = "Test Subject";
String text = "Test Body";
// stub
doNothing().when(javaMailSender).send(any(SimpleMailMessage.class));
// when
boolean result = emailService.sendEmail(to, subject, text);
// then
assertTrue(result, "이메일이 정상적으로 전송되어야 합니다.");
verify(javaMailSender, times(1)).send(any(SimpleMailMessage.class));
}

@Test
@DisplayName("이메일 전송 실패 테스트 - 크기 초과")
public void sendEmailFailDueToSize() {
// given
String to = "[email protected]";
String subject = "This is a very long subject that will exceed the limit";
String text = "A".repeat(25 * 1024 * 1024); // 25MB 이상의 텍스트
// when
boolean result = emailService.sendEmail(to, subject, text);
// then
assertFalse(result, "이메일 크기가 초과된 경우 전송에 실패해야 합니다.");
verify(javaMailSender, never()).send(any(SimpleMailMessage.class));
}

@Test
@DisplayName("이메일 전송 실패 테스트 - 수신자 없음")
public void sendEmailFailNoRecipient() {
// given
String to = null;
String subject = "Test Subject";
String text = "Test Body";
// when
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
emailService.sendEmail(to, subject, text);
});
// then
assertEquals("Invalid recipient address", exception.getMessage());
verify(javaMailSender, never()).send(any(SimpleMailMessage.class));
}
}
Loading

0 comments on commit 33e3461

Please sign in to comment.