Skip to content

Commit

Permalink
feat: make deletion routine more error tolerant
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Jul 19, 2024
1 parent a353293 commit f5ab90e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/userstatistics", "/userstatistics/**")
.permitAll()
.antMatchers(HttpMethod.DELETE, "/useradmin/consultants/{consultantId:[0-9]+}/delete")
.hasAuthority(USER_ADMIN)
.hasAnyAuthority(USER_ADMIN, RESTRICTED_AGENCY_ADMIN)
.antMatchers(HttpMethod.GET, "/actuator/health")
.permitAll()
.antMatchers(HttpMethod.GET, "/actuator/health/*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,8 @@ private List<DeletionWorkflowError> performSessionDeletion(

Optional<Session> session = findSessionInUserSessionList(rcGroupId, userSessionList);

session.ifPresentOrElse(
s -> workflowErrors.addAll(deleteSessionService.performSessionDeletion(s)),
() ->
workflowErrors.add(
DeletionWorkflowError.builder()
.deletionSourceType(ASKER)
.deletionTargetType(ALL)
.identifier(rcGroupId)
.reason(RC_SESSION_GROUP_NOT_FOUND_REASON)
.timestamp(nowInUtc())
.build()));
session.ifPresent(
s -> workflowErrors.addAll(deleteSessionService.performSessionDeletion(s)));

return workflowErrors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class DeleteInactiveSessionsAndUserServiceTest {
class DeleteInactiveSessionsAndUserServiceTest {

@InjectMocks private DeleteInactiveSessionsAndUserService deleteInactiveSessionsAndUserService;

Expand All @@ -42,7 +42,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
@Mock private InactivePrivateGroupsProvider inactivePrivateGroupsProvider;

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail_When_userNotFoundReason() {

EasyRandom easyRandom = new EasyRandom();
Expand Down Expand Up @@ -71,7 +71,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_DeleteEntireUserAccount_WhenUserHasOnlyInactiveSessions() {

EasyRandom easyRandom = new EasyRandom();
Expand All @@ -96,7 +96,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_DeleteSingleSession_WhenUserHasActiveAndInactiveSessions() {

EasyRandom easyRandom = new EasyRandom();
Expand All @@ -121,7 +121,7 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_logWorkflowErrorMail_WhenUserHasActiveAndInactiveSessionsAndHasErrors() {

EasyRandom easyRandom = new EasyRandom();
Expand Down Expand Up @@ -159,8 +159,8 @@ public class DeleteInactiveSessionsAndUserServiceTest {
}

@Test
public void
deleteInactiveSessionsAndUsers_Should_logWorkflowErrorMail_WhenSessionCouldNotBeFound() {
void
deleteInactiveSessionsAndUsers_Should_notLogError_WhenSessionCouldNotBeFound_BecauseItMayHaveBeenDeletedByPreviousWorkflowRun() {

EasyRandom easyRandom = new EasyRandom();
User user = easyRandom.nextObject(User.class);
Expand All @@ -181,14 +181,12 @@ public class DeleteInactiveSessionsAndUserServiceTest {

deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers();

verify(workflowErrorLogService, Mockito.times(1))
.logWorkflowErrors(argThat(list -> !list.isEmpty()));
verify(workflowErrorMailService, Mockito.times(1))
.buildAndSendErrorMail(Collections.emptyList());
verify(workflowErrorLogService, Mockito.never()).logWorkflowErrors(Mockito.anyList());
verify(workflowErrorMailService, Mockito.never()).buildAndSendErrorMail(Mockito.anyList());
}

@Test
public void
void
deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorMail_WhenUserCouldNotBeFound() {

EasyRandom easyRandom = new EasyRandom();
Expand Down

0 comments on commit f5ab90e

Please sign in to comment.