diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/usermanagement/controller/UserControllerIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/usermanagement/controller/UserControllerIntTest.java index 892e7ebf106..28c346cd5e8 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/usermanagement/controller/UserControllerIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/usermanagement/controller/UserControllerIntTest.java @@ -19,6 +19,7 @@ import uk.gov.hmcts.darts.common.entity.UserAccountEntity; import uk.gov.hmcts.darts.common.enums.SecurityGroupEnum; import uk.gov.hmcts.darts.common.repository.SecurityGroupRepository; +import uk.gov.hmcts.darts.common.repository.SecurityRoleRepository; import uk.gov.hmcts.darts.common.repository.UserAccountRepository; import uk.gov.hmcts.darts.common.util.DateConverterUtil; import uk.gov.hmcts.darts.test.common.data.UserAccountTestData; @@ -35,7 +36,9 @@ import java.time.OffsetDateTime; import java.util.List; +import java.util.Objects; import java.util.Optional; +import java.util.Set; import static java.time.OffsetDateTime.now; import static java.time.ZoneOffset.UTC; @@ -67,6 +70,9 @@ class UserControllerIntTest extends IntegrationBase { @Autowired private SecurityGroupRepository securityGroupRepository; + + @Autowired + private SecurityRoleRepository securityRoleRepository; @Autowired private UserAccountRepository userAccountRepository; @@ -80,18 +86,20 @@ class UserControllerIntTest extends IntegrationBase { private static final String SOME_CASE_ID = "1"; private static final OffsetDateTime YESTERDAY = now(UTC).minusDays(1).withHour(9).withMinute(0) .withSecond(0).withNano(0); + private static final int TRANSCRIBER_SG_ID = -4; + private static final int REQUESTOR_SG_ID = -2; + private static final int APPROVER_SG_ID = -1; @Test - void testDeactivateModifyWithSuperAdmin() throws Exception { + void deactivateUser_ShouldDeactivateUserAndRollBackTranscriptions_WhenTranscriber() throws Exception { superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); userAccountEntity = userAccountRepository.save(userAccountEntity); - Optional groupEntity - = securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_ADMIN.getName()); + SecurityGroupEntity transcriberGroupEntity = securityGroupRepository.getReferenceById(TRANSCRIBER_SG_ID); + userAccountEntity.setSecurityGroupEntities(Set.of(transcriberGroupEntity)); - userAccountEntity.getSecurityGroupEntities().add(groupEntity.get()); userAccountEntity = dartsDatabaseStub.save(userAccountEntity); HearingEntity hearingEntity = dartsDatabase.givenTheDatabaseContainsCourtCaseWithHearingAndCourthouseWithRoom( @@ -141,18 +149,19 @@ void testDeactivateModifyWithSuperAdmin() throws Exception { } @Test - void testDeactivateUserWithSuperUser() throws Exception { - superAdminUserStub.givenSystemUserIsAuthorised(userIdentity); + void deactivateUser_ShouldDeactivateUser_WhenSuperAdmin() throws Exception { + securityGroupStub.clearUsers(SecurityGroupEnum.SUPER_ADMIN); + superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); userAccountEntity = userAccountRepository.save(userAccountEntity); - // add user to the super user group Optional groupEntity - = securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_USER.getName()); + = securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_ADMIN.getName()); + SecurityGroupEntity superAdminGroup = groupEntity.get(); + userAccountEntity.getSecurityGroupEntities().add(superAdminGroup); - userAccountEntity.getSecurityGroupEntities().add(groupEntity.get()); userAccountEntity = dartsDatabaseStub.save(userAccountEntity); HearingEntity hearingEntity = dartsDatabase.givenTheDatabaseContainsCourtCaseWithHearingAndCourthouseWithRoom( @@ -168,7 +177,66 @@ void testDeactivateUserWithSuperUser() throws Exception { // now run the test to disable the user UserPatch userPatch = new UserPatch(); userPatch.setActive(false); + userPatch.setDescription(""); + List workflowEntityBefore + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + Assertions.assertFalse(containsApprovedWorkflow(workflowEntityBefore)); + + MvcResult mvcResult = mockMvc.perform(patch(ENDPOINT_URL + userAccountEntity.getId()) + .header("Content-Type", "application/json") + .content(objectMapper.writeValueAsString(userPatch))) + .andExpect(status().is2xxSuccessful()) + .andReturn(); + + Optional fndUserIdentity = dartsDatabase.getUserAccountRepository().findById(userAccountEntity.getId()); + Assertions.assertTrue(fndUserIdentity.isPresent()); + + Assertions.assertFalse(securityGroupStub.isPartOfAnySecurityGroup(fndUserIdentity.get().getId())); + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + + UserWithIdAndTimestamps userWithIdAndTimestamps = mapper.readValue(mvcResult.getResponse().getContentAsString(), + UserWithIdAndTimestamps.class); + + List rolledBackTranscription = userWithIdAndTimestamps.getRolledBackTranscriptRequests(); + + List workflowEntityAfter + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + + // transcription workflows should not be changed if user is not transcriber + Assertions.assertNull(rolledBackTranscription); + Assertions.assertEquals(workflowEntityBefore.size(), workflowEntityAfter.size()); + } + + @Test + void deactivateUser_ShouldDeactivateUser_WhenRequester() throws Exception { + superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); + UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); + userAccountEntity = userAccountRepository.save(userAccountEntity); + + SecurityGroupEntity requesterSecurityGroup = securityGroupRepository.getReferenceById(REQUESTOR_SG_ID); + userAccountEntity.setSecurityGroupEntities(Set.of(requesterSecurityGroup)); + + userAccountEntity = dartsDatabaseStub.save(userAccountEntity); + + HearingEntity hearingEntity = dartsDatabase.givenTheDatabaseContainsCourtCaseWithHearingAndCourthouseWithRoom( + SOME_CASE_ID, + SOME_COURTHOUSE, + SOME_COURTROOM, + DateConverterUtil.toLocalDateTime(SOME_DATE_TIME)); + + var courtCase = authorisationStub.getCourtCaseEntity(); + TranscriptionEntity transcription + = dartsDatabase.getTranscriptionStub().createAndSaveWithTranscriberTranscription(userAccountEntity, courtCase, hearingEntity, YESTERDAY, false); + // confirm user is requester of the transcription + Assertions.assertEquals(userAccountEntity.getId(), transcription.getRequestedBy().getId()); + + // now run the test to disable the user + UserPatch userPatch = new UserPatch(); + userPatch.setActive(false); + userPatch.setDescription(""); List workflowEntityBefore = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); Assertions.assertFalse(containsApprovedWorkflow(workflowEntityBefore)); @@ -195,14 +263,137 @@ void testDeactivateUserWithSuperUser() throws Exception { List workflowEntityAfter = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); - Assertions.assertEquals(1, rolledBackTranscription.size()); - Assertions.assertEquals(transcription.getId(), rolledBackTranscription.getFirst()); - Assertions.assertEquals(workflowEntityBefore.size() + 1, workflowEntityAfter.size()); - Assertions.assertTrue(containsApprovedWorkflow(workflowEntityAfter)); + // transcription workflows should not be changed if user is not transcriber + Assertions.assertNull(rolledBackTranscription); + Assertions.assertEquals(workflowEntityBefore.size(), workflowEntityAfter.size()); + } + + @Test + void deactivateUser_ShouldDeactivateUser_WhenApprover() throws Exception { + superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); + + UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); + userAccountEntity = userAccountRepository.save(userAccountEntity); + + SecurityGroupEntity approverSecurityGroup = securityGroupRepository.getReferenceById(APPROVER_SG_ID); + userAccountEntity.setSecurityGroupEntities(Set.of(approverSecurityGroup)); + + userAccountEntity = dartsDatabaseStub.save(userAccountEntity); + + HearingEntity hearingEntity = dartsDatabase.givenTheDatabaseContainsCourtCaseWithHearingAndCourthouseWithRoom( + SOME_CASE_ID, + SOME_COURTHOUSE, + SOME_COURTROOM, + DateConverterUtil.toLocalDateTime(SOME_DATE_TIME)); + + var courtCase = authorisationStub.getCourtCaseEntity(); + TranscriptionEntity transcription + = dartsDatabase.getTranscriptionStub().createAndSaveWithTranscriberTranscription(userAccountEntity, courtCase, hearingEntity, YESTERDAY, false); + // Set user as approver + TranscriptionWorkflowEntity workflowEntity = new TranscriptionWorkflowEntity(); + workflowEntity.setTranscription(transcription); + workflowEntity.setTranscriptionStatus(dartsDatabase.getTranscriptionStub().getTranscriptionStatusByEnum(TranscriptionStatusEnum.APPROVED)); + workflowEntity.setWorkflowActor(userAccountEntity); + workflowEntity.setWorkflowTimestamp(YESTERDAY.minusHours(1)); + dartsDatabase.getTranscriptionWorkflowRepository().save(workflowEntity); + // confirm user is approver of the transcription + List workflowEntities + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + Integer userId = userAccountEntity.getId(); + Assertions.assertTrue(workflowEntities.stream().anyMatch(w -> Objects.equals(w.getTranscriptionStatus().getId(), + TranscriptionStatusEnum.APPROVED.getId()) + && w.getWorkflowActor() != null && w.getWorkflowActor().getId().equals(userId))); + + // now run the test to disable the user + UserPatch userPatch = new UserPatch(); + userPatch.setActive(false); + userPatch.setDescription(""); + List workflowEntityBefore + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + + MvcResult mvcResult = mockMvc.perform(patch(ENDPOINT_URL + userAccountEntity.getId()) + .header("Content-Type", "application/json") + .content(objectMapper.writeValueAsString(userPatch))) + .andExpect(status().is2xxSuccessful()) + .andReturn(); + + Optional fndUserIdentity = dartsDatabase.getUserAccountRepository().findById(userAccountEntity.getId()); + Assertions.assertTrue(fndUserIdentity.isPresent()); + + Assertions.assertFalse(securityGroupStub.isPartOfAnySecurityGroup(fndUserIdentity.get().getId())); + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + + UserWithIdAndTimestamps userWithIdAndTimestamps = mapper.readValue(mvcResult.getResponse().getContentAsString(), + UserWithIdAndTimestamps.class); + + List rolledBackTranscription = userWithIdAndTimestamps.getRolledBackTranscriptRequests(); + + List workflowEntityAfter + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + + // transcription workflows should not be changed if user is not transcriber + Assertions.assertNull(rolledBackTranscription); + Assertions.assertEquals(workflowEntityBefore.size(), workflowEntityAfter.size()); + } + + @Test + void deactivateUser_ShouldDeactivateUser_WhenSuperUser() throws Exception { + superAdminUserStub.givenSystemUserIsAuthorised(userIdentity); + + UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); + userAccountEntity = userAccountRepository.save(userAccountEntity); + + // add user to the super user group + Optional groupEntity + = securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_USER.getName()); + userAccountEntity.getSecurityGroupEntities().add(groupEntity.get()); + userAccountEntity = dartsDatabaseStub.save(userAccountEntity); + + HearingEntity hearingEntity = dartsDatabase.givenTheDatabaseContainsCourtCaseWithHearingAndCourthouseWithRoom( + SOME_CASE_ID, + SOME_COURTHOUSE, + SOME_COURTROOM, + DateConverterUtil.toLocalDateTime(SOME_DATE_TIME)); + + var courtCase = authorisationStub.getCourtCaseEntity(); + TranscriptionEntity transcription + = dartsDatabase.getTranscriptionStub().createAndSaveWithTranscriberTranscription(userAccountEntity, courtCase, hearingEntity, YESTERDAY, false); + + // now run the test to disable the user + UserPatch userPatch = new UserPatch(); + userPatch.setActive(false); + + List workflowEntityBefore + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + Assertions.assertFalse(containsApprovedWorkflow(workflowEntityBefore)); + + MvcResult mvcResult = mockMvc.perform(patch(ENDPOINT_URL + userAccountEntity.getId()) + .header("Content-Type", "application/json") + .content(objectMapper.writeValueAsString(userPatch))) + .andExpect(status().is2xxSuccessful()) + .andReturn(); + + Optional fndUserIdentity = dartsDatabase.getUserAccountRepository().findById(userAccountEntity.getId()); + Assertions.assertTrue(fndUserIdentity.isPresent()); + + Assertions.assertFalse(securityGroupStub.isPartOfAnySecurityGroup(fndUserIdentity.get().getId())); + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JavaTimeModule()); + UserWithIdAndTimestamps userWithIdAndTimestamps = mapper.readValue(mvcResult.getResponse().getContentAsString(), + UserWithIdAndTimestamps.class); + + List rolledBackTranscription = userWithIdAndTimestamps.getRolledBackTranscriptRequests(); + Assertions.assertNull(rolledBackTranscription); + List workflowEntityAfter + = dartsDatabase.getTranscriptionWorkflowRepository().findByTranscriptionOrderByWorkflowTimestampDesc(transcription); + Assertions.assertEquals(workflowEntityBefore.size(), workflowEntityAfter.size()); } @Test - void testActivateModifyUserWithSuperAdmin() throws Exception { + void activateUser_ShouldActivateUser_WhenSuperAdmin() throws Exception { superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); @@ -263,7 +454,7 @@ void testActivateModifyUserWithSuperAdmin() throws Exception { } @Test - void testActivateModifyUserWithSuperAdminAndFailWithNoEmailAddress() throws Exception { + void activateUser_ShouldFail_WhenSuperAdminAndNoEmailAddress() throws Exception { superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); @@ -312,7 +503,7 @@ void testActivateModifyUserWithSuperAdminAndFailWithNoEmailAddress() throws Exce } @Test - void testActivateModifyUserWithSuperAdminAndFailWithNoFullNameAndNoEmailAddress() throws Exception { + void activateUser_ShouldFail_WhenSuperAdminAndNoFullNameOrEmailAddress() throws Exception { superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); @@ -358,7 +549,7 @@ void testActivateModifyUserWithSuperAdminAndFailWithNoFullNameAndNoEmailAddress( } @Test - void testDeactivateFailureWhereUserIsLastInSuperAdminGroup() throws Exception { + void deactivateUser_ShouldFail_WhenUserIsLastInSuperAdminGroup() throws Exception { superAdminUserStub.givenSystemAdminIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); @@ -391,7 +582,7 @@ void testDeactivateFailureWhereUserIsLastInSuperAdminGroup() throws Exception { } @Test - void testDeactivateFailureFromSuperUserModifyChange() throws Exception { + void setDescription_ShouldFail_WhenSuperUser() throws Exception { superAdminUserStub.givenSystemUserIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); @@ -419,7 +610,7 @@ void testDeactivateFailureFromSuperUserModifyChange() throws Exception { } @Test - void testActivateFailureFromSuperUser() throws Exception { + void activateUser_ShouldFail_WhenSuperUser() throws Exception { superAdminUserStub.givenSystemUserIsAuthorised(userIdentity); UserAccountEntity userAccountEntity = UserAccountTestData.minimalUserAccount(); diff --git a/src/main/java/uk/gov/hmcts/darts/usermanagement/service/impl/UserManagementServiceImpl.java b/src/main/java/uk/gov/hmcts/darts/usermanagement/service/impl/UserManagementServiceImpl.java index b57005b0afc..546d2facc0f 100644 --- a/src/main/java/uk/gov/hmcts/darts/usermanagement/service/impl/UserManagementServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/darts/usermanagement/service/impl/UserManagementServiceImpl.java @@ -44,6 +44,7 @@ import static java.util.Objects.isNull; import static java.util.stream.Collectors.toSet; +import static uk.gov.hmcts.darts.common.enums.SecurityRoleEnum.TRANSCRIBER; import static uk.gov.hmcts.darts.usermanagement.auditing.UserAccountUpdateAuditActivityProvider.auditActivitiesFor; @Service @@ -195,15 +196,22 @@ private List updateEntity(UserPatch userPatch, UserAccountEntity userAccou } Boolean active = userPatch.getActive(); + // if we are disabling the user + if (Boolean.FALSE.equals(active)) { + // unassign from any groups they are part of and if they are a transcriber, roll back any transcriptions they are assigned to + boolean isTranscriber = userAccountRepository + .findByRoleAndUserId(TRANSCRIBER.getId(), userAccountEntity.getId()) + .isPresent(); + + if (isTranscriber) { + rolledBackTranscriptionsList = + transcriptionService.rollbackUserTranscriptions(userAccountEntity); + } + unassignUserFromGroupsTheyArePartOf(userAccountEntity); + } + // set active status to new value if it is not null if (active != null) { userAccountEntity.setActive(active); - - // if we are disabling the user then disable the transcriptions - // and remove user from security groups - if (active.equals(Boolean.FALSE)) { - unassignUserFromGroupsTheyArePartOf(userAccountEntity); - rolledBackTranscriptionsList = transcriptionService.rollbackUserTranscriptions(userAccountEntity); - } } if (BooleanUtils.isTrue(userAccountEntity.isActive())) { diff --git a/src/test/java/uk/gov/hmcts/darts/usermanagement/service/impl/usermanagement/service/UserManagementServiceImplTest.java b/src/test/java/uk/gov/hmcts/darts/usermanagement/service/impl/usermanagement/service/UserManagementServiceImplTest.java index 00b9e1d106a..cdc5f86456c 100644 --- a/src/test/java/uk/gov/hmcts/darts/usermanagement/service/impl/usermanagement/service/UserManagementServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/darts/usermanagement/service/impl/usermanagement/service/UserManagementServiceImplTest.java @@ -10,6 +10,7 @@ import uk.gov.hmcts.darts.authorisation.api.AuthorisationApi; import uk.gov.hmcts.darts.authorisation.component.UserIdentity; import uk.gov.hmcts.darts.common.entity.SecurityGroupEntity; +import uk.gov.hmcts.darts.common.entity.SecurityRoleEntity; import uk.gov.hmcts.darts.common.entity.UserAccountEntity; import uk.gov.hmcts.darts.common.enums.SecurityGroupEnum; import uk.gov.hmcts.darts.common.enums.SecurityRoleEnum; @@ -151,13 +152,20 @@ void testGetUserWithIncludeSystemUser() { } @Test - void modifyUser_ReturnsUpdatedUser_WithActivateFalse() { + void modifyUser_ShouldReturnUpdatedUserAndRollsBackTranscriptions_WhenTranscriberAndWithActivateFalse() { + UserAccountEntity user = createUserAccount(1, EXISTING_EMAIL_ADDRESS); + user.setActive(true); + user.setIsSystemUser(false); + + SecurityRoleEntity roleEntity = new SecurityRoleEntity(); + roleEntity.setId(SecurityRoleEnum.TRANSCRIBER.getId()); + + SecurityGroupEntity groupEntity = new SecurityGroupEntity(); + groupEntity.setSecurityRoleEntity(roleEntity); + groupEntity.setUsers(new HashSet<>(Set.of(user))); + user.setSecurityGroupEntities(new HashSet<>(Set.of(groupEntity))); List userAccountEntities = new ArrayList<>(); - userAccountEntities.add(createUserAccount(1, EXISTING_EMAIL_ADDRESS)); - - userAccountEntities.getFirst().setActive(false); - userAccountEntities.getFirst().setIsSystemUser(false); - + userAccountEntities.add(user); userAccountEntities.add(createUserAccount(2, "another-user-email@hmcts.net")); Integer userId = 1001; @@ -174,6 +182,9 @@ void modifyUser_ReturnsUpdatedUser_WithActivateFalse() { when(securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_ADMIN.getName())).thenReturn(Optional.of(securityGroupEntity)); when(userAccountRepository.existsById(userId)).thenReturn(true); when(userAccountRepository.findById(userId)).thenReturn(Optional.of(userAccountEntities.getFirst())); + when(userAccountRepository.findByRoleAndUserId( + SecurityRoleEnum.TRANSCRIBER.getId(), user.getId())) + .thenReturn(Optional.of(user)); when(transcriptionService.rollbackUserTranscriptions(userAccountEntities.getFirst())).thenReturn(Arrays.asList(transcriptionId)); when(securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_ADMIN.getName())).thenReturn(Optional.of(securityGroupEntity)); @@ -184,7 +195,34 @@ void modifyUser_ReturnsUpdatedUser_WithActivateFalse() { } @Test - void modifyUser_ReturnsUpdatedUser_WithoutActiveSet() { + void modifyUser_ShouldNotRollbackTranscriptions_WhenUserNotTranscriber() { + List userAccountEntities = new ArrayList<>(); + userAccountEntities.add(createUserAccount(1, EXISTING_EMAIL_ADDRESS)); + + userAccountEntities.getFirst().setActive(false); + userAccountEntities.getFirst().setIsSystemUser(false); + + userAccountEntities.add(createUserAccount(2, "another-user-email@hmcts.net")); + + Integer userId = 1001; + UserPatch patch = new UserPatch(); + patch.setActive(false); + + Set userAccountEntitySet = new HashSet<>(userAccountEntities); + SecurityGroupEntity securityGroupEntity = Mockito.mock(SecurityGroupEntity.class); + when(securityGroupEntity.getUsers()).thenReturn(userAccountEntitySet); + + when(userIdentity.userHasGlobalAccess(Mockito.notNull())).thenReturn(true); + when(securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_ADMIN.getName())).thenReturn(Optional.of(securityGroupEntity)); + when(userAccountRepository.existsById(userId)).thenReturn(true); + when(userAccountRepository.findById(userId)).thenReturn(Optional.of(userAccountEntities.getFirst())); + when(securityGroupRepository.findByGroupNameIgnoreCase(SecurityGroupEnum.SUPER_ADMIN.getName())).thenReturn(Optional.of(securityGroupEntity)); + service.modifyUser(userId, patch); + verify(transcriptionService, times(0)).rollbackUserTranscriptions(Mockito.any()); + } + + @Test + void modifyUser_ShouldReturnUpdatedUser_WhenActiveNotSet() { List userAccountEntities = Collections.singletonList(createUserAccount(1, EXISTING_EMAIL_ADDRESS)); userAccountEntities.getFirst().setIsSystemUser(false); @@ -226,7 +264,7 @@ void modifyUser_ReturnsUpdatedUser_WithoutActiveSet() { } @Test - void modifyUser_ReturnsUpdatedUser_WithActiveTrue() { + void modifyUser_ShouldReturnUpdatedUser_WhenActiveTrue() { List userAccountEntities = Collections.singletonList(createUserAccount(1, EXISTING_EMAIL_ADDRESS)); userAccountEntities.getFirst().setIsSystemUser(false);