diff --git a/backend/src/main/java/com/kurttekin/can/job_track/presentation/rest/ResumeController.java b/backend/src/main/java/com/kurttekin/can/job_track/presentation/rest/ResumeController.java index a1e1b8dd..3a1d61fb 100644 --- a/backend/src/main/java/com/kurttekin/can/job_track/presentation/rest/ResumeController.java +++ b/backend/src/main/java/com/kurttekin/can/job_track/presentation/rest/ResumeController.java @@ -36,7 +36,7 @@ public ResponseEntity createOrUpdateResume( return ResponseEntity.status(HttpStatus.CREATED).body(createdOrUpdatedResume); } - + @GetMapping public ResponseEntity getResume( @AuthenticationPrincipal UserDetails userDetails) { diff --git a/backend/src/test/java/com/kurttekin/can/job_track/presentation/rest/ResumeControllerTest.java b/backend/src/test/java/com/kurttekin/can/job_track/presentation/rest/ResumeControllerTest.java index 307f7862..7c2a8359 100644 --- a/backend/src/test/java/com/kurttekin/can/job_track/presentation/rest/ResumeControllerTest.java +++ b/backend/src/test/java/com/kurttekin/can/job_track/presentation/rest/ResumeControllerTest.java @@ -69,4 +69,51 @@ public void testCreateOrUpdateResume_Success() { verify(userService).findUserByUsername(user.getUsername()); verify(resumeService).createOrUpdateResume(resume); } + + @Test + public void testCreateOrUpdateResume_UserNotFound() { + // Mock userService behavior to return empty + when(userService.findUserByUsername(user.getUsername())).thenReturn(Optional.empty()); + + // Expect an exception when calling the method + RuntimeException exception = assertThrows(RuntimeException.class, + () -> resumeController.createOrUpdateResume(resume, userDetails)); + + assertEquals("User not found", exception.getMessage()); + verify(userService).findUserByUsername(user.getUsername()); + verifyNoInteractions(resumeService); // Ensure resumeService is not called + } + + @Test + public void testGetResume_Success() { + // Mock userService behavior + when(userService.findUserByUsername(user.getUsername())).thenReturn(Optional.of(user)); + + // Mock resumeService behavior + when(resumeService.findById(user.getId())).thenReturn(resumeDTO); + + // Call the controller method + ResponseEntity response = resumeController.getResume(userDetails); + + // Verify and assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(resumeDTO, response.getBody()); + verify(userService).findUserByUsername(user.getUsername()); + verify(resumeService).findById(user.getId()); + } + + @Test + public void testGetResume_UserNotFound() { + // Mock userService behavior to return empty + when(userService.findUserByUsername(user.getUsername())).thenReturn(Optional.empty()); + + // Expect an exception when calling the method + RuntimeException exception = assertThrows(RuntimeException.class, + () -> resumeController.getResume(userDetails)); + + assertEquals("User not found", exception.getMessage()); + verify(userService).findUserByUsername(user.getUsername()); + verifyNoInteractions(resumeService); // Ensure resumeService is not called + } + } \ No newline at end of file