Skip to content

Commit

Permalink
CIV-9395 Add Update Contact Information Event (#3086)
Browse files Browse the repository at this point in the history
* Added new ManageContactInformation callback handler and event and whitelisted it within the AllowedFlowState service.
---------

Co-authored-by: GarethLancaster <[email protected]>
Co-authored-by: sherlynkhaw <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent 39e6df6 commit c64f342
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public enum CaseEvent {
REVIEW_HEARING_EXCEPTION(USER),
ASSIGN_LIP_DEFENDANT(USER),

MANAGE_CONTACT_INFORMATION(USER),

APPLICANT_TRIAL_READY_NOTIFY_OTHERS(USER),
RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS(USER),
RESPONDENT2_TRIAL_READY_NOTIFY_OTHERS(USER),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.Callback;
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.UserService;

import java.util.List;
import java.util.Map;

import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MANAGE_CONTACT_INFORMATION;
import static uk.gov.hmcts.reform.civil.enums.CaseState.AWAITING_APPLICANT_INTENTION;

@Service
@RequiredArgsConstructor
public class ManageContactInformationCallbackHandler extends CallbackHandler {

private static final String INVALID_CASE_STATE_ERROR = "You will be able run the manage contact information " +
"event once the claimant has responded.";
private static final List<String> ADMIN_ROLES = List.of(
"caseworker-civil-admin");
private static final List<CaseEvent> EVENTS = List.of(
MANAGE_CONTACT_INFORMATION
);

private final UserService userService;

@Override
protected Map<String, Callback> callbacks() {
return new ImmutableMap.Builder<String, Callback>()
.put(callbackKey(ABOUT_TO_START), this::validateUserCanTriggerEvent)
.put(callbackKey(ABOUT_TO_SUBMIT), this::emptyCallbackResponse)
.put(callbackKey(SUBMITTED), this::emptyCallbackResponse)
.build();
}

@Override
public List<CaseEvent> handledEvents() {
return EVENTS;
}

private CallbackResponse validateUserCanTriggerEvent(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();

List<String> errors = isAwaitingClaimantIntention(caseData)
&& !isAdmin(callbackParams.getParams().get(BEARER_TOKEN).toString())
? List.of(INVALID_CASE_STATE_ERROR) : null;

return AboutToStartOrSubmitCallbackResponse.builder()
.errors(errors)
.build();
}

private boolean isAwaitingClaimantIntention(CaseData caseData) {
return caseData.getCcdState().equals(AWAITING_APPLICANT_INTENTION);
}

private boolean isAdmin(String userAuthToken) {
return userService.getUserInfo(userAuthToken).getRoles()
.stream().anyMatch(role -> ADMIN_ROLES.contains(role));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_LIP_CLAIM;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFAULT_JUDGEMENT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MANAGE_CONTACT_INFORMATION;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_HEARING_PARTIES;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REQUEST_JUDGEMENT_ADMISSION_SPEC;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFAULT_JUDGEMENT_SPEC;
Expand Down Expand Up @@ -1222,8 +1223,6 @@ public boolean isAllowedOnStateForSpec(String stateFullName, CaseEvent caseEvent
}

public boolean isAllowed(CaseDetails caseDetails, CaseEvent caseEvent) {
CaseData caseData = caseDetailsConverter.toCaseData(caseDetails);

if (caseEvent.equals(migrateCase)) {
return true;
}
Expand All @@ -1232,6 +1231,11 @@ public boolean isAllowed(CaseDetails caseDetails, CaseEvent caseEvent) {
return true;
}

if (caseEvent.equals(MANAGE_CONTACT_INFORMATION)) {
return true;
}

CaseData caseData = caseDetailsConverter.toCaseData(caseDetails);
if (SPEC_CLAIM.equals(caseData.getCaseAccessCategory())
|| CREATE_CLAIM_SPEC.equals(caseEvent) || CREATE_LIP_CLAIM.equals(caseEvent)) {
StateFlow stateFlow = stateFlowEngine.evaluateSpec(caseDetails);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CallbackType;
import uk.gov.hmcts.reform.civil.enums.CaseState;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;

@SpringBootTest(classes = {
ManageContactInformationCallbackHandler.class,
JacksonAutoConfiguration.class,
CaseDetailsConverter.class
})
class ManageContactInformationCallbackHandlerTest extends BaseCallbackHandlerTest {

@Autowired
private ManageContactInformationCallbackHandler handler;

private static final UserInfo ADMIN_USER = UserInfo.builder()
.roles(List.of("caseworker-civil-admin"))
.build();
private static final UserInfo LEGAL_REP_USER = UserInfo.builder()
.roles(List.of("caseworker-civil-solicitor"))
.build();

@Nested
class AboutToStart {

@Test
void shouldNotReturnReturnErrors_WhenAboutToStartIsInvokedByAdminUserWhileCaseInAwaitingApplicantIntentionState() {
when(userService.getUserInfo(anyString())).thenReturn(ADMIN_USER);
CaseData caseData = CaseData.builder().ccdState(CaseState.AWAITING_APPLICANT_INTENTION).build();
CallbackParams params = callbackParamsOf(caseData, CallbackType.ABOUT_TO_START);

AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler
.handle(params);

assertNull(response.getErrors());
}

@Test
void shouldReturnErrors_WhenAboutToStartIsInvokedByNonAdminUserWhileCaseInAwaitingApplicantIntentionState() {
when(userService.getUserInfo(anyString())).thenReturn(LEGAL_REP_USER);
CaseData caseData = CaseData.builder().ccdState(CaseState.AWAITING_APPLICANT_INTENTION).build();
CallbackParams params = callbackParamsOf(caseData, CallbackType.ABOUT_TO_START);

AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler
.handle(params);

List<String> expected =
List.of("You will be able run the manage contact information event once the claimant has responded.");

assertEquals(expected, response.getErrors());
}

@Test
void shouldNotReturnErrors_WhenAboutToStartIsInvokedByNonAdminUserWhileCaseInANonAwaitingApplicantIntentionState() {
when(userService.getUserInfo(anyString())).thenReturn(LEGAL_REP_USER);
CaseData caseData = CaseData.builder().ccdState(CaseState.AWAITING_CASE_DETAILS_NOTIFICATION).build();
CallbackParams params = callbackParamsOf(caseData, CallbackType.ABOUT_TO_START);

AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler
.handle(params);

assertNull(response.getErrors());
}

@Nested
class AboutToSubmit {

@Test
void shouldReturnExpectedResponse_WhenAboutToSubmitIsInvoked() {
CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build();
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);

AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler
.handle(params);

assertEquals(AboutToStartOrSubmitCallbackResponse.builder().build(), response);
}
}

@Nested
class Submitted {

@Test
void shouldReturnExpectedResponse_WhenSubmittedIsInvoked() {
CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build();
CallbackParams params = callbackParamsOf(caseData, SUBMITTED);

AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler
.handle(params);

assertEquals(AboutToStartOrSubmitCallbackResponse.builder().build(), response);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.HEARING_SCHEDULED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INFORM_AGREED_EXTENSION_DATE;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INITIATE_GENERAL_APPLICATION;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MANAGE_CONTACT_INFORMATION;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MEDIATION_SUCCESSFUL;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MEDIATION_UNSUCCESSFUL;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MOVE_TO_DECISION_OUTCOME;
Expand Down Expand Up @@ -1062,4 +1063,13 @@ void shouldReturnTrue_whenCaseEventIsNotifyHearingParties() {
assertThat(flowStateAllowedEventService.isAllowed(caseDetails, NOTIFY_HEARING_PARTIES))
.isEqualTo(true);
}

@Test
void shouldReturnTrue_whenCaseEventIsManageContactInformation() {
CaseDetails caseDetails =
CaseDetailsBuilder.builder()
.atStateAwaitingCaseDetailsNotification().build();
assertThat(flowStateAllowedEventService.isAllowed(caseDetails, MANAGE_CONTACT_INFORMATION))
.isEqualTo(true);
}
}

0 comments on commit c64f342

Please sign in to comment.