-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIV-9395 Add Update Contact Information Event (#3086)
* 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
1 parent
39e6df6
commit c64f342
Showing
5 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters