Skip to content

Commit 9e1266a

Browse files
committed
fix: coderabbitai issue
1 parent c1aa085 commit 9e1266a

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/main/java/com/itasocialacademy/oitassist/task/service/TaskServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public TaskResponseDTO updateTask(Long taskId, UpdateTaskRequestDTO requestDTO)
135135
existingTask.setTitle(requestDTO.title());
136136
existingTask.setDescription(requestDTO.description());
137137

138-
TaskBody updatedTask = taskBodyRepository.save(existingTask);
138+
TaskBody updatedTask = taskBodyRepository.saveAndFlush(existingTask);
139139
log.debug("Updated Task: Id {}, Title - {}", updatedTask.getId(), updatedTask.getTitle());
140140

141141
Long currentUserId = securityFacade.getCurrentUserId()
@@ -354,6 +354,6 @@ private void checkTaskVersion(Long actualVersion, Long providedVersion, Long tas
354354
private void auditOwnersUpdate(TaskBody taskBody) {
355355
taskBody.setUpdatedAt(Instant.now());
356356
taskBody.setUpdatedBy(securityFacade.getCurrentUserId().orElseThrow(UserNotFoundException::new));
357-
taskBodyRepository.save(taskBody);
357+
taskBodyRepository.saveAndFlush(taskBody);
358358
}
359359
}

src/test/java/com/itasocialacademy/oitassist/task/service/TaskServiceTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void updateTask_asOwner_shouldUpdateFieldsAndPublishBothEvents() {
356356

357357
when(taskBodyRepository.findById(1L)).thenReturn(Optional.of(taskBody));
358358
when(securityFacade.hasRole("ADMIN")).thenReturn(false);
359-
when(taskBodyRepository.save(any(TaskBody.class))).thenReturn(taskBody);
359+
when(taskBodyRepository.saveAndFlush(any(TaskBody.class))).thenReturn(taskBody);
360360
when(fileManagerFacade.getFilesByEntity(any(), eq(1L), any())).thenReturn(testFiles);
361361
when(taskBodyMapper.toResponse(taskBody, testFiles, "creator@mail.com")).thenReturn(updatedResponse);
362362
when(securityFacade.getCurrentUserId()).thenReturn(Optional.of(100L));
@@ -369,7 +369,7 @@ void updateTask_asOwner_shouldUpdateFieldsAndPublishBothEvents() {
369369
assertEquals("creator@mail.com", result.createdByEmail());
370370

371371
ArgumentCaptor<TaskBody> captor = ArgumentCaptor.forClass(TaskBody.class);
372-
verify(taskBodyRepository).save(captor.capture());
372+
verify(taskBodyRepository).saveAndFlush(captor.capture());
373373
assertEquals("Updated Title", captor.getValue().getTitle());
374374
assertEquals("Updated Description", captor.getValue().getDescription());
375375

@@ -385,7 +385,7 @@ void updateTask_shouldPublishAttachEvent() {
385385

386386
when(taskBodyRepository.findById(1L)).thenReturn(Optional.of(taskBody));
387387
when(securityFacade.hasRole("ADMIN")).thenReturn(true);
388-
when(taskBodyRepository.save(any(TaskBody.class))).thenReturn(taskBody);
388+
when(taskBodyRepository.saveAndFlush(any(TaskBody.class))).thenReturn(taskBody);
389389
when(fileManagerFacade.getFilesByEntity(any(), eq(1L), any())).thenReturn(testFiles);
390390
when(taskBodyMapper.toResponse(taskBody, testFiles, "creator@mail.com")).thenReturn(taskResponse);
391391
when(securityFacade.getCurrentUserId()).thenReturn(Optional.of(100L));
@@ -404,7 +404,7 @@ void updateTask_shouldPublishDetachEvent() {
404404

405405
when(taskBodyRepository.findById(1L)).thenReturn(Optional.of(taskBody));
406406
when(securityFacade.hasRole("ADMIN")).thenReturn(true);
407-
when(taskBodyRepository.save(any(TaskBody.class))).thenReturn(taskBody);
407+
when(taskBodyRepository.saveAndFlush(any(TaskBody.class))).thenReturn(taskBody);
408408
when(fileManagerFacade.getFilesByEntity(any(), eq(1L), any())).thenReturn(testFiles);
409409
when(taskBodyMapper.toResponse(taskBody, testFiles, "creator@mail.com")).thenReturn(taskResponse);
410410
when(securityFacade.getCurrentUserId()).thenReturn(Optional.of(100L));
@@ -425,7 +425,7 @@ void updateTask_nonExistingTask_shouldThrowTaskNotFoundException() {
425425

426426
assertThrows(TaskNotFoundException.class, () -> taskService.updateTask(99L, request));
427427

428-
verify(taskBodyRepository, never()).save(any());
428+
verify(taskBodyRepository, never()).saveAndFlush(any());
429429
}
430430

431431
@Test
@@ -439,7 +439,7 @@ void updateTask_notOwnerNotAdmin_shouldThrowTaskAccessRestrictedException() {
439439

440440
assertThrows(TaskAccessRestrictedException.class, () -> taskService.updateTask(1L, request));
441441

442-
verify(taskBodyRepository, never()).save(any());
442+
verify(taskBodyRepository, never()).saveAndFlush(any());
443443
}
444444

445445
// ---- addTaskOwner ----
@@ -454,7 +454,7 @@ void addTaskOwner_asAdmin_toOrgUser_shouldSucceed() {
454454
when(securityFacade.getCurrentUserId()).thenReturn(Optional.of(100L));
455455
when(taskBodyRepository.findById(1L)).thenReturn(Optional.of(taskBody));
456456
when(userFacade.findByEmail("newowner@mail.com")).thenReturn(Optional.of(newOwner));
457-
when(taskBodyRepository.save(any(TaskBody.class))).thenReturn(taskBody);
457+
when(taskBodyRepository.saveAndFlush(any(TaskBody.class))).thenReturn(taskBody);
458458
when(fileManagerFacade.getFilesByEntity(any(), eq(1L), any())).thenReturn(testFiles);
459459
when(taskBodyMapper.toResponse(any(TaskBody.class), any(), eq("creator@mail.com"))).thenReturn(taskResponse);
460460

@@ -564,7 +564,7 @@ void removeTaskOwner_shouldSucceed() {
564564
when(securityFacade.getCurrentUserId()).thenReturn(Optional.of(100L));
565565
when(taskBodyRepository.findById(1L)).thenReturn(Optional.of(taskBody));
566566
when(userFacade.findByEmail("currentowner@mail.com")).thenReturn(Optional.of(owner));
567-
when(taskBodyRepository.save(any(TaskBody.class))).thenReturn(taskBody);
567+
when(taskBodyRepository.saveAndFlush(any(TaskBody.class))).thenReturn(taskBody);
568568
when(fileManagerFacade.getFilesByEntity(any(), eq(1L), any())).thenReturn(testFiles);
569569
when(taskBodyMapper.toResponse(taskBody, testFiles, "creator@mail.com")).thenReturn(taskResponse);
570570

0 commit comments

Comments
 (0)