diff --git a/dashboard-notifications/src/main/java/uk/gov/hmcts/reform/dashboard/services/TaskListService.java b/dashboard-notifications/src/main/java/uk/gov/hmcts/reform/dashboard/services/TaskListService.java index 0f9f54f6f27..4e270ef73f3 100644 --- a/dashboard-notifications/src/main/java/uk/gov/hmcts/reform/dashboard/services/TaskListService.java +++ b/dashboard-notifications/src/main/java/uk/gov/hmcts/reform/dashboard/services/TaskListService.java @@ -13,11 +13,13 @@ import uk.gov.hmcts.reform.dashboard.utilities.StringUtility; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import java.util.stream.Stream; @Service @Slf4j @@ -83,42 +85,61 @@ public TaskListEntity updateTaskListItem(UUID taskItemIdentifier) { }).orElseThrow(() -> new IllegalArgumentException("Invalid task item identifier " + taskItemIdentifier)); } - private void makeProgressAbleTasksInactiveForCaseIdentifierAndRole(String caseIdentifier, String role, String excludedCategory, String excludedTemplate) { + private void makeProgressAbleTasksInactiveForCaseIdentifierAndRole(String caseIdentifier, String role, List excludedCategories, String excludedTemplate) { log.info( - "makeProgressAbleTasksInactiveForCaseIdentifierAndRole caseIdentifier:{} role: {} excludedCategory: {} excludedTemplate: {}", + "makeProgressAbleTasksInactiveForCaseIdentifierAndRole caseIdentifier:{} role: {} excludedCategories: {} excludedTemplate: {}", caseIdentifier, role, - excludedCategory, + excludedCategories, excludedTemplate ); List tasks = new ArrayList<>(); - if (Objects.nonNull(excludedCategory)) { - List categories = taskItemTemplateRepository.findByCategoryEnAndRole( - excludedCategory, - role - ); - if (Objects.nonNull(categories)) { - List catIds = categories.stream().map(TaskItemTemplateEntity::getId).toList(); + List statusesToSkip = List.of( + TaskStatus.AVAILABLE.getPlaceValue(), + TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ); + if (Objects.nonNull(excludedCategories) && !excludedCategories.isEmpty()) { + List catIds = excludedCategories.stream() + .filter(Objects::nonNull) + .flatMap(category -> { + List templates = taskItemTemplateRepository.findByCategoryEnAndRole( + category, + role + ); + return Objects.nonNull(templates) ? templates.stream() : Stream.of(); + }) + .map(TaskItemTemplateEntity::getId) + .distinct() + .toList(); + if (!catIds.isEmpty()) { tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn( - caseIdentifier, role, List.of( - TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), - TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() - ), catIds + caseIdentifier, + role, + statusesToSkip, + catIds + ); + } else { + log.info("No task templates found for categories {} and role {} - defaulting to all progressable tasks", + excludedCategories, role); + tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn( + caseIdentifier, + role, + statusesToSkip ); } } else if (Objects.nonNull(excludedTemplate)) { tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplateTemplateNameNot( - caseIdentifier, role, List.of( - TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), - TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() - ), excludedTemplate + caseIdentifier, + role, + statusesToSkip, + excludedTemplate ); } else { tasks = taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn( - caseIdentifier, role, List.of( - TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), - TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() - ) + caseIdentifier, + role, + statusesToSkip ); } tasks.forEach(t -> { @@ -143,16 +164,16 @@ public void makeProgressAbleTasksInactiveForCaseIdentifierAndRole(String caseIde caseIdentifier, role ); - makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, null, null); + makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, List.of(), null); } @Transactional - public void makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory(String caseIdentifier, String role, String excludedCategory) { + public void makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory(String caseIdentifier, String role, String... excludedCategories) { log.info( - "makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory caseIdentifier:{} role: {} excludedCategory: {}", - caseIdentifier, role, excludedCategory + "makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory caseIdentifier:{} role: {} excludedCategories: {}", + caseIdentifier, role, Arrays.toString(excludedCategories) ); - makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, excludedCategory, null); + makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, normaliseCategories(excludedCategories), null); } @Transactional @@ -161,7 +182,7 @@ public void makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingTempla "makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingTemplate caseIdentifier:{} role: {} excludedTemplate: {}", caseIdentifier, role, excludedTemplate ); - makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, null, excludedTemplate); + makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseIdentifier, role, List.of(), excludedTemplate); } @Transactional @@ -188,4 +209,14 @@ private void makeViewDocumentTaskAvailable(String caseIdentifier, String role) { taskListRepository.save(task); }); } + + private List normaliseCategories(String... categories) { + if (categories == null || categories.length == 0) { + return List.of(); + } + return Arrays.stream(categories) + .filter(Objects::nonNull) + .filter(category -> !category.isBlank()) + .toList(); + } } diff --git a/dashboard-notifications/src/test/java/uk/gov/hmcts/reform/dashboard/services/TaskListServiceTest.java b/dashboard-notifications/src/test/java/uk/gov/hmcts/reform/dashboard/services/TaskListServiceTest.java index 57451806b42..0f7c00d8523 100644 --- a/dashboard-notifications/src/test/java/uk/gov/hmcts/reform/dashboard/services/TaskListServiceTest.java +++ b/dashboard-notifications/src/test/java/uk/gov/hmcts/reform/dashboard/services/TaskListServiceTest.java @@ -2,8 +2,10 @@ import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -26,6 +28,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -45,6 +49,11 @@ class TaskListServiceTest { @InjectMocks private TaskListService taskListService; + @BeforeEach + void resetMocks() { + reset(taskListRepository, taskItemTemplateRepository); + } + @Test void shouldReturnEmpty_whenTaskListIsNotPresent() { @@ -120,9 +129,7 @@ void shouldThrowExceptionWhenExceptionInGetTaskList() { //then assertThrows( RuntimeException.class, - () -> { - taskListRepository.findByReferenceAndTaskItemTemplateRole(any(), any()); - } + () -> taskListRepository.findByReferenceAndTaskItemTemplateRole(any(), any()) ); } @@ -337,13 +344,13 @@ void shouldMakeProgressAbleTaskListInactive_Except_Ga_whenTaskListIsPresent() { TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() ), - List.of(Long.valueOf(123)) + List.of(123L) )) .thenReturn(tasks); List categories = new ArrayList<>(); categories.add(TaskItemTemplateEntity.builder() - .id(Long.valueOf(123)).taskNameCy("TaskNameCy") + .id(123L).taskNameCy("TaskNameCy") .taskNameEn("TaskNameEn") .scenarioName("Scenario.hearing") .templateName("Hearing.view") @@ -372,7 +379,7 @@ void shouldMakeProgressAbleTaskListInactive_Except_Ga_whenTaskListIsPresent() { TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() ), - List.of(Long.valueOf(123)) + List.of(123L) ); verify(taskListRepository, atLeast(5)).save(ArgumentMatchers.argThat( @@ -394,6 +401,138 @@ void shouldMakeProgressAbleTaskListInactive_Except_Ga_whenTaskListIsPresent() { )); } + @Test + void shouldMakeProgressAbleTaskListInactiveForMultipleCategories_whenTaskListIsPresent() { + + List tasks = new ArrayList<>(); + tasks.add(getTaskListEntity(UUID.randomUUID()).toBuilder() + .currentStatus(TaskStatus.ACTION_NEEDED.getPlaceValue()) + .taskNameEn("Link name") + .taskNameCy("Link name Welsh") + .build()); + + when(taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn( + "123", "Claimant", + List.of( + TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ), + List.of(123L, 456L) + )).thenReturn(tasks); + + List categoryA = List.of(TaskItemTemplateEntity.builder().id(123L).role("Claimant").build()); + List categoryB = List.of(TaskItemTemplateEntity.builder().id(456L).role("Claimant").build()); + + when(taskItemTemplateRepository.findByCategoryEnAndRole("CategoryA", "Claimant")).thenReturn(categoryA); + when(taskItemTemplateRepository.findByCategoryEnAndRole("CategoryB", "Claimant")).thenReturn(categoryB); + + taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( + "123", + "Claimant", + "CategoryA", + "CategoryB" + ); + + verify(taskItemTemplateRepository).findByCategoryEnAndRole("CategoryA", "Claimant"); + verify(taskItemTemplateRepository).findByCategoryEnAndRole("CategoryB", "Claimant"); + verify(taskListRepository).findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn( + "123", "Claimant", + List.of( + TaskStatus.AVAILABLE.getPlaceValue(), TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ), + List.of(123L, 456L) + ); + } + + @Test + void shouldFallbackToDefaultProgressQueryWhenCategoryTemplatesMissing() { + List tasks = List.of(getTaskListEntity(UUID.randomUUID()).toBuilder() + .currentStatus(TaskStatus.IN_PROGRESS.getPlaceValue()) + .build()); + + when(taskItemTemplateRepository.findByCategoryEnAndRole("CategoryEn", "Claimant")).thenReturn(List.of()); + when(taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn( + "123", + "Claimant", + List.of( + TaskStatus.AVAILABLE.getPlaceValue(), + TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ) + )).thenReturn(tasks); + + taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( + "123", + "Claimant", + "CategoryEn" + ); + + verify(taskItemTemplateRepository).findByCategoryEnAndRole("CategoryEn", "Claimant"); + verify(taskListRepository).findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn( + "123", + "Claimant", + List.of( + TaskStatus.AVAILABLE.getPlaceValue(), + TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ) + ); + verify(taskListRepository, never()).findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn( + any(), + any(), + any(), + any() + ); + verify(taskListRepository, atLeast(1)).save(ArgumentMatchers.argThat( + a -> a.getCurrentStatus() == TaskStatus.INACTIVE.getPlaceValue() + )); + } + + @Test + void shouldTreatEmptyExcludedCategoriesAsNoExclusions() { + List tasks = List.of(getTaskListEntity(UUID.randomUUID()).toBuilder() + .currentStatus(TaskStatus.ACTION_NEEDED.getPlaceValue()) + .build()); + + when(taskListRepository.findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn( + "123", + "Claimant", + List.of( + TaskStatus.AVAILABLE.getPlaceValue(), + TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ) + )).thenReturn(tasks); + + taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( + "123", + "Claimant", + null, + " " + ); + + verify(taskItemTemplateRepository, never()).findByCategoryEnAndRole(any(), any()); + verify(taskListRepository).findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotIn( + "123", + "Claimant", + List.of( + TaskStatus.AVAILABLE.getPlaceValue(), + TaskStatus.DONE.getPlaceValue(), + TaskStatus.NOT_AVAILABLE_YET.getPlaceValue() + ) + ); + verify(taskListRepository, never()).findByReferenceAndTaskItemTemplateRoleAndCurrentStatusNotInAndTaskItemTemplate_IdNotIn( + any(), + any(), + any(), + any() + ); + verify(taskListRepository, atLeast(1)).save(ArgumentMatchers.argThat( + a -> a.getCurrentStatus() == TaskStatus.INACTIVE.getPlaceValue() + )); + } + @Test public void shouldDeleteWhenThereWereDuplicateEntriesInTheRepository() { TaskListEntity task = getTaskListEntity(UUID.randomUUID()).toBuilder() @@ -442,8 +581,8 @@ void shouldMakeProgressAbleTaskListActiveExcludingTemplate() { //given List tasks = new ArrayList<>(); tasks.add(getTaskListEntity(UUID.randomUUID()).toBuilder() - .taskNameEn("Link name") - .taskNameCy("Link name Welsh") + .taskNameEn("Link name") + .taskNameCy("Link name Welsh") .currentStatus(TaskStatus.NOT_AVAILABLE_YET.getPlaceValue()) .build()); tasks.add(getTaskListEntity(UUID.randomUUID()).toBuilder() @@ -490,6 +629,18 @@ void shouldMakeProgressAbleTaskListActiveExcludingTemplate() { any(), any() ); + + ArgumentCaptor captor = ArgumentCaptor.forClass(TaskListEntity.class); + verify(taskListRepository, times(2)).save(captor.capture()); + List savedTasks = captor.getAllValues(); + savedTasks.forEach(saved -> { + assertThat(saved.getCurrentStatus()).isEqualTo(TaskStatus.AVAILABLE.getPlaceValue()); + assertThat(saved.getNextStatus()).isEqualTo(TaskStatus.AVAILABLE.getPlaceValue()); + assertThat(saved.getHintTextCy()).isEmpty(); + assertThat(saved.getHintTextEn()).isEmpty(); + assertThat(saved.getTaskNameEn()).isEqualTo("Link name"); + assertThat(saved.getTaskNameCy()).isEqualTo("Link name Welsh"); + }); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/DashboardScenarioService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/DashboardScenarioService.java index 2c6fc1ad8d3..10c93802769 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/DashboardScenarioService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/DashboardScenarioService.java @@ -18,6 +18,7 @@ public abstract class DashboardScenarioService { protected static final String DEFENDANT_ROLE = "DEFENDANT"; protected static final String CLAIMANT_ROLE = "CLAIMANT"; + public static final String HEARING_TASK_CATEGORY = "Hearing"; protected DashboardScenarioService(DashboardScenariosService dashboardScenariosService, DashboardNotificationsParamsMapper mapper) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardService.java index 42e05dd68fb..9b586832892 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardService.java @@ -37,7 +37,7 @@ public void notifyFinalOrder(CaseData caseData, String authToken) { @Override protected String getScenario(CaseData caseData) { - dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData); + dashboardTasksHelper.deleteNotificationAndInactiveTasksForClaimant(caseData, HEARING_TASK_CATEGORY); final String scenario; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardService.java index 04f4d4804cf..5083fd9a2c5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardService.java @@ -37,7 +37,7 @@ public void notifyFinalOrder(CaseData caseData, String authToken) { @Override protected String getScenario(CaseData caseData) { - dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData); + dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData, HEARING_TASK_CATEGORY); final String scenario; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelper.java b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelper.java index 9fec5d9787f..ce95c3bdbb1 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelper.java @@ -6,6 +6,10 @@ import uk.gov.hmcts.reform.dashboard.services.DashboardNotificationService; import uk.gov.hmcts.reform.dashboard.services.TaskListService; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @Service public class DashboardTasksHelper { @@ -13,6 +17,8 @@ public class DashboardTasksHelper { private final FeatureToggleService featureToggleService; private final DashboardNotificationService dashboardNotificationService; + private static final String APPLICATIONS = "Applications"; + public DashboardTasksHelper(TaskListService taskListService, FeatureToggleService featureToggleService, DashboardNotificationService dashboardNotificationService) { @@ -21,32 +27,48 @@ public DashboardTasksHelper(TaskListService taskListService, this.dashboardNotificationService = dashboardNotificationService; } - public void deleteNotificationAndInactiveTasksForClaimant(CaseData caseData) { - deleteNotificationAndInactiveTasksForRole(caseData, "CLAIMANT"); + public void deleteNotificationAndInactiveTasksForClaimant(CaseData caseData, String... excludeCategory) { + deleteNotificationAndInactiveTasksForRole(caseData, "CLAIMANT", excludeCategory); } - public void deleteNotificationAndInactiveTasksForDefendant(CaseData caseData) { - deleteNotificationAndInactiveTasksForRole(caseData, "DEFENDANT"); + public void deleteNotificationAndInactiveTasksForDefendant(CaseData caseData, String... excludeCategories) { + deleteNotificationAndInactiveTasksForRole(caseData, "DEFENDANT", excludeCategories); } - private void deleteNotificationAndInactiveTasksForRole(CaseData caseData, String citizenRole) { - dashboardNotificationService.deleteByReferenceAndCitizenRole( - caseData.getCcdCaseReference().toString(), - citizenRole - ); + private void deleteNotificationAndInactiveTasksForRole( + CaseData caseData, + String citizenRole, + String... excludeCategories) { - if (featureToggleService.isLocationWhiteListed(caseData.getCaseManagementLocation().getBaseLocation()) - || featureToggleService.isCuiGaNroEnabled()) { + String caseReference = caseData.getCcdCaseReference().toString(); + + dashboardNotificationService.deleteByReferenceAndCitizenRole(caseReference, citizenRole); + + List categories = buildCategories(caseData, excludeCategories); + + if (categories.isEmpty()) { + taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRole(caseReference, citizenRole); + } else { taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( - caseData.getCcdCaseReference().toString(), + caseReference, citizenRole, - "Applications" - ); - } else { - taskListService.makeProgressAbleTasksInactiveForCaseIdentifierAndRole( - caseData.getCcdCaseReference().toString(), - citizenRole + categories.toArray(new String[0]) ); } } + + private List buildCategories(CaseData caseData, String... excludeCategories) { + List categories = new ArrayList<>(); + + if (excludeCategories != null) { + categories.addAll(Arrays.asList(excludeCategories)); + } + + if (featureToggleService.isLocationWhiteListed(caseData.getCaseManagementLocation().getBaseLocation()) + || featureToggleService.isCuiGaNroEnabled()) { + categories.add(APPLICATIONS); + } + + return categories; + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardServiceTest.java index 33a7f183ca3..33afefacaa6 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderClaimantDashboardServiceTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_UPDATE_DASHBOARD_CLAIMANT_TASK_LIST_UPLOAD_DOCUMENTS_FINAL_ORDERS; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_UPDATE_TASK_LIST_TRIAL_READY_FINALS_ORDERS_CLAIMANT; +import static uk.gov.hmcts.reform.civil.service.dashboardnotifications.DashboardScenarioService.HEARING_TASK_CATEGORY; @ExtendWith(MockitoExtension.class) class FinalOrderClaimantDashboardServiceTest { @@ -63,7 +64,7 @@ void shouldRecordScenarioClaimantFinalOrderFastTrackNotReadyTrial_whenInvoked() caseData.getCcdCaseReference().toString(), ScenarioRequestParams.builder().params(scenarioParams).build() ); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForClaimant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -87,7 +88,7 @@ void shouldRecordScenarioClaimantFinalOrderFastTrackTrialReady_whenInvoked() { caseData.getCcdCaseReference().toString(), ScenarioRequestParams.builder().params(scenarioParams).build() ); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForClaimant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -102,7 +103,7 @@ void shouldNotRecordScenario_whenApplicant1Represented() { finalOrderClaimantDashboardService.notifyFinalOrder(caseData, AUTH_TOKEN); verifyNoInteractions(dashboardScenariosService); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForClaimant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -118,7 +119,7 @@ void shouldNotRecordScenario_whenLipVLipDisabled() { finalOrderClaimantDashboardService.notifyFinalOrder(caseData, AUTH_TOKEN); verifyNoInteractions(dashboardScenariosService); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForClaimant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -135,6 +136,6 @@ void shouldNotRecordScenario_whenDashBoardDisabled() { finalOrderClaimantDashboardService.notifyFinalOrder(caseData, AUTH_TOKEN); verifyNoInteractions(dashboardScenariosService); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForClaimant(caseData, HEARING_TASK_CATEGORY); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardServiceTest.java index f3bf2fdb354..bfcde828967 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/finalorder/FinalOrderDefendantDashboardServiceTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.civil.service.dashboardnotifications.DashboardScenarioService.HEARING_TASK_CATEGORY; @ExtendWith(MockitoExtension.class) class FinalOrderDefendantDashboardServiceTest { @@ -60,7 +61,7 @@ void shouldRecordScenarioDefendantFinalOrderFastTrackNotReadyTrial_whenInvoked() caseData.getCcdCaseReference().toString(), ScenarioRequestParams.builder().params(new HashMap<>()).build() ); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -83,7 +84,7 @@ void shouldRecordScenarioDefendantFinalOrderFastTrackTrialReady_whenInvoked() { caseData.getCcdCaseReference().toString(), ScenarioRequestParams.builder().params(new HashMap<>()).build() ); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -99,7 +100,7 @@ void shouldNotRecordScenario_whenRespondentRepresented() { finalOrderDefendantDashboardService.notifyFinalOrder(caseData, AUTH_TOKEN); verifyNoInteractions(dashboardScenariosService); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -116,7 +117,7 @@ void shouldNotRecordScenario_whenLipVLipDisabled() { finalOrderDefendantDashboardService.notifyFinalOrder(caseData, AUTH_TOKEN); verifyNoInteractions(dashboardScenariosService); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData, HEARING_TASK_CATEGORY); } @Test @@ -134,6 +135,6 @@ void shouldNotRecordScenario_whenDashBoardDisabled() { finalOrderDefendantDashboardService.notifyFinalOrder(caseData, AUTH_TOKEN); verifyNoInteractions(dashboardScenariosService); - verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData); + verify(dashboardTasksHelper).deleteNotificationAndInactiveTasksForDefendant(caseData, HEARING_TASK_CATEGORY); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelperTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelperTest.java index 026b8b124ad..822997da9e5 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/dashboardnotifications/helper/DashboardTasksHelperTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -12,6 +13,8 @@ import uk.gov.hmcts.reform.dashboard.services.DashboardNotificationService; import uk.gov.hmcts.reform.dashboard.services.TaskListService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -32,24 +35,7 @@ class DashboardTasksHelperTest { private DashboardTasksHelper dashboardTasksHelper; @Test - void shouldExcludeApplicationsForClaimantWhenLocationWhitelisted() { - CaseData caseData = caseData(BASE_LOCATION, CCD_REFERENCE); - when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(true); - - dashboardTasksHelper.deleteNotificationAndInactiveTasksForClaimant(caseData); - - verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( - CCD_REFERENCE.toString(), - "CLAIMANT", - "Applications" - ); - verify(dashboardNotificationService).deleteByReferenceAndCitizenRole( - CCD_REFERENCE.toString(), - "CLAIMANT"); - } - - @Test - void shouldDeleteNotificationAndInactiveTasksForClaimantWhenNoWhitelistOrCuiGaNro() { + void shouldDeleteNotificationWithoutExclusionsWhenFeatureTogglesDisabled() { CaseData caseData = caseData(BASE_LOCATION, CCD_REFERENCE); when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(false); when(featureToggleService.isCuiGaNroEnabled()).thenReturn(false); @@ -66,73 +52,81 @@ void shouldDeleteNotificationAndInactiveTasksForClaimantWhenNoWhitelistOrCuiGaNr } @Test - void shouldExcludeApplicationsForClaimantWhenCuiGaNroEnabled() { + void shouldAddApplicationsWhenLocationIsWhitelisted() { CaseData caseData = caseData(BASE_LOCATION, CCD_REFERENCE); - when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(false); - when(featureToggleService.isCuiGaNroEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(true); dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData); + ArgumentCaptor captor = ArgumentCaptor.forClass(String[].class); verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( - CCD_REFERENCE.toString(), - "DEFENDANT", - "Applications" + eq(CCD_REFERENCE.toString()), + eq("DEFENDANT"), + captor.capture() ); + assertThat(captor.getValue()).containsExactly("Applications"); verify(dashboardNotificationService).deleteByReferenceAndCitizenRole( CCD_REFERENCE.toString(), "DEFENDANT"); } @Test - void shouldExcludeApplicationsForDefendantWhenLocationWhitelisted() { + void shouldAddApplicationsWhenCuiGaNroEnabled() { CaseData caseData = caseData(BASE_LOCATION, CCD_REFERENCE); - when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(true); + when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(false); + when(featureToggleService.isCuiGaNroEnabled()).thenReturn(true); - dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData); + dashboardTasksHelper.deleteNotificationAndInactiveTasksForClaimant(caseData); + ArgumentCaptor captor = ArgumentCaptor.forClass(String[].class); verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( - CCD_REFERENCE.toString(), - "DEFENDANT", - "Applications" + eq(CCD_REFERENCE.toString()), + eq("CLAIMANT"), + captor.capture() ); + assertThat(captor.getValue()).containsExactly("Applications"); verify(dashboardNotificationService).deleteByReferenceAndCitizenRole( CCD_REFERENCE.toString(), - "DEFENDANT"); + "CLAIMANT"); } @Test - void shouldDeleteNotificationAndInactiveTasksForDefendantWhenNoWhitelistOrCuiGaNro() { + void shouldIncludeProvidedCategoriesWhenTogglesDisabled() { CaseData caseData = caseData(BASE_LOCATION, CCD_REFERENCE); when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(false); when(featureToggleService.isCuiGaNroEnabled()).thenReturn(false); - dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData); + dashboardTasksHelper.deleteNotificationAndInactiveTasksForClaimant(caseData, "CategoryA", "CategoryB"); - verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRole( - CCD_REFERENCE.toString(), - "DEFENDANT" + ArgumentCaptor captor = ArgumentCaptor.forClass(String[].class); + verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( + eq(CCD_REFERENCE.toString()), + eq("CLAIMANT"), + captor.capture() ); + assertThat(captor.getValue()).containsExactly("CategoryA", "CategoryB"); verify(dashboardNotificationService).deleteByReferenceAndCitizenRole( CCD_REFERENCE.toString(), - "DEFENDANT"); + "CLAIMANT"); } @Test - void shouldExcludeApplicationsForDefendantWhenCuiGaNroEnabled() { + void shouldAppendApplicationsAfterExtrasWhenToggleEnabled() { CaseData caseData = caseData(BASE_LOCATION, CCD_REFERENCE); - when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(false); - when(featureToggleService.isCuiGaNroEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListed(BASE_LOCATION)).thenReturn(true); - dashboardTasksHelper.deleteNotificationAndInactiveTasksForDefendant(caseData); + dashboardTasksHelper.deleteNotificationAndInactiveTasksForClaimant(caseData, "CategoryX"); + ArgumentCaptor captor = ArgumentCaptor.forClass(String[].class); verify(taskListService).makeProgressAbleTasksInactiveForCaseIdentifierAndRoleExcludingCategory( - CCD_REFERENCE.toString(), - "DEFENDANT", - "Applications" + eq(CCD_REFERENCE.toString()), + eq("CLAIMANT"), + captor.capture() ); + assertThat(captor.getValue()).containsExactly("CategoryX", "Applications"); verify(dashboardNotificationService).deleteByReferenceAndCitizenRole( CCD_REFERENCE.toString(), - "DEFENDANT"); + "CLAIMANT"); } private CaseData caseData(String baseLocation, Long ccdCaseReference) {