diff --git a/src/main/java/com/seniors/domain/comment/controller/CommentController.java b/src/main/java/com/seniors/domain/comment/controller/CommentController.java index 3fefce3..a9b1f7d 100644 --- a/src/main/java/com/seniors/domain/comment/controller/CommentController.java +++ b/src/main/java/com/seniors/domain/comment/controller/CommentController.java @@ -36,11 +36,11 @@ public class CommentController { @ApiResponse(responseCode = "200", description = "생성 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "댓글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PostMapping("") @@ -58,11 +58,11 @@ public DataResponseDto commentAdd( @ApiResponse(responseCode = "200", description = "수정 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "댓글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PatchMapping("/{commentId}") @@ -78,11 +78,11 @@ public DataResponseDto commentModify( @ApiResponse(responseCode = "200", description = "삭제 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "댓글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @DeleteMapping("/{commentId}") diff --git a/src/main/java/com/seniors/domain/notification/controller/NotificationController.java b/src/main/java/com/seniors/domain/notification/controller/NotificationController.java index eea23cc..62b574a 100644 --- a/src/main/java/com/seniors/domain/notification/controller/NotificationController.java +++ b/src/main/java/com/seniors/domain/notification/controller/NotificationController.java @@ -50,9 +50,9 @@ public SseEmitter subscribeNotification( content = @Content(mediaType = "application/json", schema = @Schema(implementation = CustomPage.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "알림이 존재하지 않습니다", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @GetMapping("") @@ -72,9 +72,9 @@ public DataResponseDto> notificationList( @ApiResponse(responseCode = "200", description = "단건 조회 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PostDto.GetPostRes.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "알림이 존재하지 않습니다", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PatchMapping("/{id}") diff --git a/src/main/java/com/seniors/domain/post/controller/PostController.java b/src/main/java/com/seniors/domain/post/controller/PostController.java index 05e45dd..c9fa579 100644 --- a/src/main/java/com/seniors/domain/post/controller/PostController.java +++ b/src/main/java/com/seniors/domain/post/controller/PostController.java @@ -43,11 +43,11 @@ public class PostController { @ApiResponse(responseCode = "200", description = "생성 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "게시글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PostMapping(value = "", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE}) @@ -63,9 +63,9 @@ public DataResponseDto postAdd( @ApiResponse(responseCode = "200", description = "단건 조회 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = GetPostRes.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "게시글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @GetMapping("/{postId}") @@ -81,9 +81,9 @@ public DataResponseDto postDetails( content = @Content(mediaType = "application/json", schema = @Schema(implementation = CustomPage.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "게시글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @GetMapping("") @@ -102,11 +102,11 @@ public DataResponseDto> postList( @ApiResponse(responseCode = "200", description = "단건 수정 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "게시글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PatchMapping(value = "/{postId}", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE}) @@ -123,9 +123,9 @@ public DataResponseDto postModify( @ApiResponse(responseCode = "200", description = "단건 삭제 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "게시글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @DeleteMapping("/{postId}") @@ -143,11 +143,11 @@ public DataResponseDto postRemove( @ApiResponse(responseCode = "200", description = "좋아요 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "게시글이 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PostMapping("/like") diff --git a/src/main/java/com/seniors/domain/resume/dto/ResumeDto.java b/src/main/java/com/seniors/domain/resume/dto/ResumeDto.java index 6ca125c..951ca01 100644 --- a/src/main/java/com/seniors/domain/resume/dto/ResumeDto.java +++ b/src/main/java/com/seniors/domain/resume/dto/ResumeDto.java @@ -37,13 +37,13 @@ public static class SaveResumeReq { private String name; @Valid - private List certificateList = new ArrayList<>(); + private List certificates = new ArrayList<>(); @Valid - private List careerList = new ArrayList<>(); + private List careers = new ArrayList<>(); @Valid - private List educationList = new ArrayList<>(); + private List educations = new ArrayList<>(); } @@ -70,13 +70,13 @@ public static class ModifyResumeReq { private String name; @Valid - private List certificateList = new ArrayList<>(); + private List certificates = new ArrayList<>(); @Valid - private List careerList = new ArrayList<>(); + private List careers = new ArrayList<>(); @Valid - private List educationList = new ArrayList<>(); + private List educations = new ArrayList<>(); } diff --git a/src/main/java/com/seniors/domain/resume/service/ResumeService.java b/src/main/java/com/seniors/domain/resume/service/ResumeService.java index 1950f44..1efbf60 100644 --- a/src/main/java/com/seniors/domain/resume/service/ResumeService.java +++ b/src/main/java/com/seniors/domain/resume/service/ResumeService.java @@ -44,16 +44,16 @@ public Long addResume(SaveResumeReq resumeReq, MultipartFile image, Long userId) if (resumeRepository.findByUsersId(userId).isPresent()) { throw new ConflictException("이미 해당 유저의 이력서가 존재합니다."); } + + resumeReq.getCareers().stream() - - resumeReq.getCareerList().stream() .filter(saveCareerReq -> saveCareerReq.getEndedAt()!=null && saveCareerReq.getIsAttendanced()==true) .findAny() .ifPresent(saveCareerReq -> { throw new BadRequestException("퇴사연도를 입력하심면 재직중 여부를 체크하실 수 없습니다."); }); - resumeReq.getEducationList().stream() + resumeReq.getEducations().stream() .filter(saveEducationReq -> saveEducationReq.getEndedAt()!=null && saveEducationReq.getIsProcessed()==true) .findAny() .ifPresent(saveEducationReq1 -> { @@ -73,15 +73,15 @@ public Long addResume(SaveResumeReq resumeReq, MultipartFile image, Long userId) resume.uploadPhotoUrl(null); } - resumeReq.getCareerList().stream() + resumeReq.getCareers().stream() .map(Career::from) .forEach(resume::addCareer); - resumeReq.getCertificateList().stream() + resumeReq.getCertificates().stream() .map(Certificate::from) .forEach(resume::addCertificate); - resumeReq.getEducationList().stream() + resumeReq.getEducations().stream() .map(Education::from) .forEach(resume::addEducation); @@ -141,14 +141,14 @@ public void modifyResume(Long resumeId, ResumeDto.ModifyResumeReq resumeReq, Mul () ->new NotFoundException("이력서가 존재하지 않습니다.") ); - resumeReq.getCareerList().stream() + resumeReq.getCareers().stream() .filter(modifyCareerReq -> modifyCareerReq.getEndedAt()!=null && modifyCareerReq.getIsAttendanced()==true) .findAny() .ifPresent(modifyCareerReq -> { throw new BadRequestException("퇴사연도를 입력하심면 재직중 여부를 체크하실 수 없습니다."); }); - resumeReq.getEducationList().stream() + resumeReq.getEducations().stream() .filter(modifyEducationReq -> modifyEducationReq.getEndedAt()!=null && modifyEducationReq.getIsProcessed()==true) .findAny() .ifPresent(modifyCareerReq -> { @@ -176,15 +176,15 @@ public void modifyResume(Long resumeId, ResumeDto.ModifyResumeReq resumeReq, Mul resume.getCertificates().clear(); resume.getEducations().clear(); - resumeReq.getCareerList().stream() + resumeReq.getCareers().stream() .map(Career::from) .forEach(resume::addCareer); - resumeReq.getCertificateList().stream() + resumeReq.getCertificates().stream() .map(Certificate::from) .forEach(resume::addCertificate); - resumeReq.getEducationList().stream() + resumeReq.getEducations().stream() .map(Education::from) .forEach(resume::addEducation); } diff --git a/src/main/java/com/seniors/domain/users/controller/UsersController.java b/src/main/java/com/seniors/domain/users/controller/UsersController.java index 6a1c4f7..5f21115 100644 --- a/src/main/java/com/seniors/domain/users/controller/UsersController.java +++ b/src/main/java/com/seniors/domain/users/controller/UsersController.java @@ -46,7 +46,7 @@ public class UsersController { @ApiResponse(responseCode = "200", description = "검증 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseEntity.class))) @ApiResponse(responseCode = "401", description = "검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseEntity.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @GetMapping("/validate") public ResponseEntity userValidate( @Parameter(hidden = true) @LoginUsers CustomUserDetails userDetails @@ -60,9 +60,9 @@ public ResponseEntity userValidate( @ApiResponse(responseCode = "200", description = "단건 조회 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = GetUserDetailRes.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "사용자가 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @GetMapping("") @@ -81,11 +81,11 @@ public DataResponseDto usersDetails( @ApiResponse(responseCode = "200", description = "단건 수정 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DataResponseDto.class))) @ApiResponse(responseCode = "400", description = "유효성 검증 실패", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = BadRequestException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "401", description = "유효하지 않은 회원입니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotAuthorizedException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "404", description = "사용자가 존재하지 않습니다.", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = NotFoundException.class))) + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @ApiResponse(responseCode = "500", description = "서버 에러.", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))) @PatchMapping("") diff --git a/src/test/java/com/seniors/domain/resume/controller/ResumeControllerTest.java b/src/test/java/com/seniors/domain/resume/controller/ResumeControllerTest.java index 98a76ab..2dc8fb4 100644 --- a/src/test/java/com/seniors/domain/resume/controller/ResumeControllerTest.java +++ b/src/test/java/com/seniors/domain/resume/controller/ResumeControllerTest.java @@ -1,18 +1,228 @@ package com.seniors.domain.resume.controller; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.seniors.ControllerTestSupport; +import com.seniors.common.constant.OAuthProvider; +import com.seniors.config.security.CustomUserDetails; +import com.seniors.domain.post.repository.post.PostRepository; +import com.seniors.domain.resume.dto.CareerDto; +import com.seniors.domain.resume.dto.ResumeDto; +import com.seniors.domain.resume.entity.Resume; +import com.seniors.domain.resume.service.ResumeService; +import com.seniors.domain.users.entity.Users; +import com.seniors.domain.users.repository.UsersRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; -import static org.junit.jupiter.api.Assertions.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import static org.assertj.core.api.BDDAssumptions.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@ActiveProfiles("dev") +@SpringBootTest +@AutoConfigureMockMvc class ResumeControllerTest { + @Autowired + private MockMvc mockMvc; + @Autowired + protected ObjectMapper objectMapper; + + @MockBean + ResumeService resumeService; + + @BeforeEach + void setUp(@Autowired WebApplicationContext applicationContext) { + this.mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext) + .apply(springSecurity()) + .alwaysDo(print()) + .build(); + } + + @Test + @DisplayName("신규 이력서를 등록한다. 직종은 비워둘 수 없다.") + void resumeAddWithOccupationBlankConstraint() throws Exception { + // given + ResumeDto.SaveResumeReq saveResumeReq = new ResumeDto.SaveResumeReq(); + saveResumeReq.setIntroduce("안녕하세요"); + saveResumeReq.setIsOpened(true); + saveResumeReq.setName("철수"); + + String accessToken = "access_token"; + MockMultipartFile image = new MockMultipartFile("image", "abc.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8)); + MockMultipartFile data = new MockMultipartFile("data", null, "application/json", objectMapper.writeValueAsString(saveResumeReq).getBytes(StandardCharsets.UTF_8)); + + // when, then + mockMvc.perform( + MockMvcRequestBuilders + .multipart(HttpMethod.POST, "/api/resumes") + .file(image) + .file(data) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.MULTIPART_FORM_DATA) + .header("Authorization", accessToken) + ) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.success").value(false)) + .andExpect(jsonPath("$.code").value(400)) + .andExpect(jsonPath("$.message").value("직종은 비워둘 수 없습니다.")) + .andExpect(jsonPath("$.data").doesNotExist()); + + } + + @Test + @DisplayName("신규 이력서를 등록한다. 직종은 30자 이하여야 한다.") + void resumeAddWithOccupationLengthConstraint() throws Exception { + // given + ResumeDto.SaveResumeReq saveResumeReq = new ResumeDto.SaveResumeReq(); + saveResumeReq.setIntroduce("안녕하세요"); + saveResumeReq.setIsOpened(true); + saveResumeReq.setOccupation("가나다라가나다라다나다라가나다라가나다라가나다라가나다라가나다라가나다라가"); + saveResumeReq.setName("철수"); + + String accessToken = "access_token"; + MockMultipartFile image = new MockMultipartFile("image", "abc.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8)); + MockMultipartFile data = new MockMultipartFile("data", null, "application/json", objectMapper.writeValueAsString(saveResumeReq).getBytes(StandardCharsets.UTF_8)); + + // when, then + mockMvc.perform( + MockMvcRequestBuilders + .multipart(HttpMethod.POST, "/api/resumes") + .file(image) + .file(data) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.MULTIPART_FORM_DATA) + .header("Authorization", accessToken) + ) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.success").value(false)) + .andExpect(jsonPath("$.code").value(400)) + .andExpect(jsonPath("$.message").value("직종은 30자 이하여야 합니다.")) + .andExpect(jsonPath("$.data").doesNotExist()); + } @Test - void resumeAdd() { + @DisplayName("신규 이력서를 등록한다. 이름은 비워둘 수 없다.") + void resumeAddWithNameBlankConstraint() throws Exception { + // given + ResumeDto.SaveResumeReq saveResumeReq = new ResumeDto.SaveResumeReq(); + saveResumeReq.setIntroduce("안녕하세요"); + saveResumeReq.setIsOpened(true); + saveResumeReq.setOccupation("의사"); + String accessToken = "access_token"; + MockMultipartFile image = new MockMultipartFile("image", "abc.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8)); + MockMultipartFile data = new MockMultipartFile("data", null, "application/json", objectMapper.writeValueAsString(saveResumeReq).getBytes(StandardCharsets.UTF_8)); + + // when, then + mockMvc.perform( + MockMvcRequestBuilders + .multipart(HttpMethod.POST, "/api/resumes") + .file(image) + .file(data) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.MULTIPART_FORM_DATA) + .header("Authorization", accessToken) + ) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.success").value(false)) + .andExpect(jsonPath("$.code").value(400)) + .andExpect(jsonPath("$.message").value("이름은 비워둘 수 없습니다.")) + .andExpect(jsonPath("$.data").doesNotExist()); } @Test - void resumeDetails() { + @DisplayName("신규 이력서를 등록한다. 이름은 30자 이하여야 한다.") + void resumeAddWithNameLengthConstraint() throws Exception { + // given + ResumeDto.SaveResumeReq saveResumeReq = new ResumeDto.SaveResumeReq(); + saveResumeReq.setIntroduce("안녕하세요"); + saveResumeReq.setIsOpened(true); + saveResumeReq.setOccupation("의사"); + saveResumeReq.setName("가나다라가나다라가나다라가나다라가나다라가나다라가나다라가나다라가나다라가나다라"); + + String accessToken = "access_token"; + MockMultipartFile image = new MockMultipartFile("image", "abc.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8)); + MockMultipartFile data = new MockMultipartFile("data", null, "application/json", objectMapper.writeValueAsString(saveResumeReq).getBytes(StandardCharsets.UTF_8)); + + // when, then + mockMvc.perform( + MockMvcRequestBuilders + .multipart(HttpMethod.POST, "/api/resumes") + .file(image) + .file(data) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.MULTIPART_FORM_DATA) + .header("Authorization", accessToken) + ) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.success").value(false)) + .andExpect(jsonPath("$.code").value(400)) + .andExpect(jsonPath("$.message").value("이름은 30자 이하여야 합니다.")) + .andExpect(jsonPath("$.data").doesNotExist()); + } + + @Test + void resumeDetails() throws Exception{ + + CustomUserDetails customUserDetails = mock(CustomUserDetails.class); + when(customUserDetails.getUserId()).thenReturn(123l); // 예시로 설정한 값, 실제 값으로 대체 + + Resume resume = Resume.builder() + .occupation("의사") + .name("철수").build(); + Long resumeId = 400l; + // given + when(resumeService.findResume(resumeId, 123l)) + .thenReturn(ResumeDto.GetResumeRes.from(resume)); + + mockMvc.perform( + get("/api/resumes/" + resumeId) + .principal(new UsernamePasswordAuthenticationToken(customUserDetails, null, null)) + ) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("200")) + .andExpect(jsonPath("$.status").value("OK")) + .andExpect(jsonPath("$.message").value("OK")) + .andExpect(jsonPath("$.data").isArray()); + } + + @Test + void myResumeDetails() { } @Test @@ -26,4 +236,8 @@ void resumeModify() { @Test void resumeRemove() { } + + @Test + void resumeViewerList() { + } } \ No newline at end of file diff --git a/src/test/java/com/seniors/domain/resume/repository/ResumeRepositoryTest.java b/src/test/java/com/seniors/domain/resume/repository/ResumeRepositoryTest.java index f5b9930..82433e5 100644 --- a/src/test/java/com/seniors/domain/resume/repository/ResumeRepositoryTest.java +++ b/src/test/java/com/seniors/domain/resume/repository/ResumeRepositoryTest.java @@ -7,26 +7,20 @@ import com.seniors.domain.resume.entity.Resume; import com.seniors.domain.users.entity.Users; import com.seniors.domain.users.repository.UsersRepository; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; - -import java.awt.print.Book; -import java.io.IOException; -import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; - import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; @SpringBootTest @Transactional @@ -171,18 +165,15 @@ void findResumeList(){ Pageable pageable = PageRequest.of(0, 2); // when - Slice resumeList = resumeRepository.findResumeList(pageable, null, null); + Slice resumeList = resumeRepository.findResumeList(pageable, null, savedUser1.getId()); // then - assertThat(resumeList.getContent().size()).isEqualTo(pageable.getPageSize()); - assertThat(resumeList.getContent().get(0).getId()).isEqualTo(savedResume4.getId()); - assertThat(resumeList.getContent().get(0).getIntroduce()).isEqualTo(resume4.getIntroduce()); - assertThat(resumeList.getContent().get(0).getOccupation()).isEqualTo(resume4.getOccupation()); - assertThat(resumeList.getContent().get(0).getName()).isEqualTo(resume4.getName()); - assertThat(resumeList.getContent().get(1).getId()).isEqualTo(savedResume3.getId()); - assertThat(resumeList.getContent().get(1).getIntroduce()).isEqualTo(resume3.getIntroduce()); - assertThat(resumeList.getContent().get(1).getOccupation()).isEqualTo(resume3.getOccupation()); - assertThat(resumeList.getContent().get(1).getName()).isEqualTo(resume3.getName()); + assertThat(resumeList).hasSize(pageable.getPageSize()) + .extracting("id", "introduce", "occupation", "name") + .containsExactlyInAnyOrder( + tuple(savedResume4.getId(), "안녕요~!!", "회사원", "송철수"), + tuple(savedResume3.getId(), "안녕!!", "요리사", "이철수") + ); } @Test diff --git a/src/test/java/com/seniors/domain/resume/service/ResumeServiceTest.java b/src/test/java/com/seniors/domain/resume/service/ResumeServiceTest.java index ac45260..fa57cba 100644 --- a/src/test/java/com/seniors/domain/resume/service/ResumeServiceTest.java +++ b/src/test/java/com/seniors/domain/resume/service/ResumeServiceTest.java @@ -98,9 +98,9 @@ void addResume() throws IOException { ResumeDto.SaveResumeReq resumeReq = new ResumeDto.SaveResumeReq(); resumeReq.setOccupation("의사"); resumeReq.setName("김철수"); - resumeReq.setCareerList(careerReqList); - resumeReq.setCertificateList(certificateReqList); - resumeReq.setEducationList(educationReqList); + resumeReq.setCareers(careerReqList); + resumeReq.setCertificates(certificateReqList); + resumeReq.setEducations(educationReqList); // when Long newResumeId = resumeService.addResume(resumeReq, null, savedUser.getId()); @@ -130,34 +130,9 @@ void addResumeMoreThanTwice() { Resume resume1 = createResume("안녕하세요~!!", "개발자", "박철수", savedUser); resumeRepository.save(resume1); - List certificateReqList = new ArrayList<>(); - List careerReqList = new ArrayList<>(); - List educationReqList = new ArrayList<>(); - - CertificateDto.saveCertificateReq certificateReq = new CertificateDto.saveCertificateReq(); - certificateReq.setName("OPIC"); - certificateReq.setIssuedYear(2005); - certificateReq.setIssuedMonth(5); - certificateReqList.add(certificateReq); - - CareerDto.saveCareerReq careerReq = new CareerDto.saveCareerReq(); - careerReq.setStartedAt(2001); - careerReq.setCompany("삼성 병원"); - careerReq.setTitle("부장"); - careerReq.setContent("삼성 병원에서 부장으로 근무"); - careerReqList.add(careerReq); - - EducationDto.saveEducationReq educationReq = new EducationDto.saveEducationReq(); - educationReq.setInstitution("서울대학교"); - educationReq.setStartedAt(1990); - educationReqList.add(educationReq); - ResumeDto.SaveResumeReq resumeReq = new ResumeDto.SaveResumeReq(); resumeReq.setOccupation("의사"); resumeReq.setName("김철수"); - resumeReq.setCareerList(careerReqList); - resumeReq.setCertificateList(certificateReqList); - resumeReq.setEducationList(educationReqList); // when & then assertThatThrownBy(() -> resumeService.addResume(resumeReq, null, savedUser.getId())) @@ -172,15 +147,7 @@ void addResumeWithConstraint1(){ Users user = createUser("mike", "male", "08-08", "20~29"); Users savedUser = usersRepository.save(user); - List certificateReqList = new ArrayList<>(); List careerReqList = new ArrayList<>(); - List educationReqList = new ArrayList<>(); - - CertificateDto.saveCertificateReq certificateReq = new CertificateDto.saveCertificateReq(); - certificateReq.setName("OPIC"); - certificateReq.setIssuedYear(2005); - certificateReq.setIssuedMonth(5); - certificateReqList.add(certificateReq); CareerDto.saveCareerReq careerReq = new CareerDto.saveCareerReq(); careerReq.setStartedAt(2001); @@ -191,17 +158,11 @@ void addResumeWithConstraint1(){ careerReq.setContent("삼성 병원에서 부장으로 근무"); careerReqList.add(careerReq); - EducationDto.saveEducationReq educationReq = new EducationDto.saveEducationReq(); - educationReq.setInstitution("서울대학교"); - educationReq.setStartedAt(1990); - educationReqList.add(educationReq); - ResumeDto.SaveResumeReq resumeReq = new ResumeDto.SaveResumeReq(); resumeReq.setOccupation("의사"); resumeReq.setName("김철수"); - resumeReq.setCareerList(careerReqList); - resumeReq.setCertificateList(certificateReqList); - resumeReq.setEducationList(educationReqList); + resumeReq.setCareers(careerReqList); + // when & then assertThatThrownBy(() -> resumeService.addResume(resumeReq, null, savedUser.getId())) @@ -216,23 +177,8 @@ void addResumeWithConstraint2(){ Users user = createUser("mike", "male", "08-08", "20~29"); Users savedUser = usersRepository.save(user); - List certificateReqList = new ArrayList<>(); - List careerReqList = new ArrayList<>(); List educationReqList = new ArrayList<>(); - CertificateDto.saveCertificateReq certificateReq = new CertificateDto.saveCertificateReq(); - certificateReq.setName("OPIC"); - certificateReq.setIssuedYear(2005); - certificateReq.setIssuedMonth(5); - certificateReqList.add(certificateReq); - - CareerDto.saveCareerReq careerReq = new CareerDto.saveCareerReq(); - careerReq.setStartedAt(2001); - careerReq.setCompany("삼성 병원"); - careerReq.setTitle("부장"); - careerReq.setContent("삼성 병원에서 부장으로 근무"); - careerReqList.add(careerReq); - EducationDto.saveEducationReq educationReq = new EducationDto.saveEducationReq(); educationReq.setInstitution("서울대학교"); educationReq.setEndedAt(1998); // 종료 연도 @@ -243,9 +189,7 @@ void addResumeWithConstraint2(){ ResumeDto.SaveResumeReq resumeReq = new ResumeDto.SaveResumeReq(); resumeReq.setOccupation("의사"); resumeReq.setName("김철수"); - resumeReq.setCareerList(careerReqList); - resumeReq.setCertificateList(certificateReqList); - resumeReq.setEducationList(educationReqList); + resumeReq.setEducations(educationReqList); // when & then assertThatThrownBy(() -> resumeService.addResume(resumeReq, null, savedUser.getId())) @@ -351,13 +295,12 @@ void findResumeList(){ CustomSlice getResumeByQueryDslResCustomSlice = resumeService.findResumeList(pageable, null, user1.getId()); // then - assertThat(getResumeByQueryDslResCustomSlice.getSize()).isEqualTo(pageable.getPageSize()); - assertThat(getResumeByQueryDslResCustomSlice.getContent().get(0).getId()).isEqualTo(savedResume4.getId()); - assertThat(getResumeByQueryDslResCustomSlice.getContent().get(0).getName()).isEqualTo(resume4.getName()); - assertThat(getResumeByQueryDslResCustomSlice.getContent().get(0).getOccupation()).isEqualTo(resume4.getOccupation()); - assertThat(getResumeByQueryDslResCustomSlice.getContent().get(1).getId()).isEqualTo(savedResume3.getId()); - assertThat(getResumeByQueryDslResCustomSlice.getContent().get(1).getName()).isEqualTo(resume3.getName()); - assertThat(getResumeByQueryDslResCustomSlice.getContent().get(1).getOccupation()).isEqualTo(resume3.getOccupation()); + assertThat(getResumeByQueryDslResCustomSlice.getContent()).hasSize(pageable.getPageSize()) + .extracting("id", "introduce", "occupation", "name") + .containsExactlyInAnyOrder( + tuple(savedResume4.getId(), "안녕요~!!", "회사원", "송철수"), + tuple(savedResume3.getId(), "안녕!!", "요리사", "이철수") + ); } @DisplayName("이력서를 수정한다. 자격증, 경력, 교육사항들도 함께 수정할 수 있다.") @@ -378,9 +321,6 @@ void modifyResume() throws IOException { Resume savedResume = resumeRepository.save(resume); List certificateReqList = new ArrayList<>(); - List careerReqList = new ArrayList<>(); - List educationReqList = new ArrayList<>(); - CertificateDto.modifyCertificateReq certificateReq = new CertificateDto.modifyCertificateReq(); certificateReq.setName("TOEIC"); certificateReq.setIssuedYear(1995); @@ -390,9 +330,8 @@ void modifyResume() throws IOException { ResumeDto.ModifyResumeReq resumeReq = new ResumeDto.ModifyResumeReq(); resumeReq.setOccupation("의사"); resumeReq.setName("김철수"); - resumeReq.setCertificateList(certificateReqList); - resumeReq.setCareerList(careerReqList); - resumeReq.setEducationList(educationReqList); + resumeReq.setCertificates(certificateReqList); + // when resumeService.modifyResume(savedResume.getId(), resumeReq, null, savedUser.getId()); @@ -504,10 +443,12 @@ void findResumeViewerList() { List getViewerInfoResList = resumeService.findResumeViewerList(savedUser1.getId()); // then - assertThat(getViewerInfoResList.get(0).getUserId()).isEqualTo(savedUser2.getId()); - assertThat(getViewerInfoResList.get(0).getName()).isEqualTo(savedUser2.getNickname()); - assertThat(getViewerInfoResList.get(1).getUserId()).isEqualTo(savedUser3.getId()); - assertThat(getViewerInfoResList.get(1).getName()).isEqualTo(savedUser3.getNickname()); + assertThat(getViewerInfoResList).hasSize(2) + .extracting("userId", "name") + .containsExactlyInAnyOrder( + tuple(savedUser3.getId(), "tony"), + tuple(savedUser2.getId(), "sam") + ); } private Users createUser(String nickname, String gender, String birthday, String ageRange) {