use of uk.gov.hmcts.reform.idam.client.models.User in project nfdiv-case-api by hmcts.
the class CaseworkerGeneralEmailTest method shouldSetGeneralEmailDetailsAndSendEmailNotificationWhenExistingGeneralEmailsIsNull.
@Test
void shouldSetGeneralEmailDetailsAndSendEmailNotificationWhenExistingGeneralEmailsIsNull() {
setMockClock(clock);
final CaseData caseData = caseData();
caseData.setGeneralEmail(GeneralEmail.builder().generalEmailParties(APPLICANT).generalEmailDetails("some details").build());
final CaseDetails<CaseData, State> details = new CaseDetails<>();
details.setId(TEST_CASE_ID);
details.setData(caseData);
when(httpServletRequest.getHeader(AUTHORIZATION)).thenReturn(TEST_AUTHORIZATION_TOKEN);
when(idamService.retrieveUser(TEST_AUTHORIZATION_TOKEN)).thenReturn(new User(TEST_AUTHORIZATION_TOKEN, UserDetails.builder().forename("forename").surname("lastname").build()));
AboutToStartOrSubmitResponse<CaseData, State> response = generalEmail.aboutToSubmit(details, details);
assertThat(response.getData().getGeneralEmails()).extracting("value").extracting("generalEmailDateTime", "generalEmailParties", "generalEmailCreatedBy", "generalEmailBody").contains(tuple(getExpectedLocalDateTime(), APPLICANT, "forename lastname", "some details"));
verify(generalEmailNotification).send(caseData, TEST_CASE_ID);
}
use of uk.gov.hmcts.reform.idam.client.models.User in project nfdiv-case-api by hmcts.
the class CcdAccessServiceTest method shouldNotThrowAnyExceptionWhenAddApplicant1RoleIsInvoked.
@Test
public void shouldNotThrowAnyExceptionWhenAddApplicant1RoleIsInvoked() {
User solicitorUser = getIdamUser(APP_1_SOL_AUTH_TOKEN, SOLICITOR_USER_ID, TEST_SOL_USER_EMAIL);
User systemUpdateUser = getIdamUser(SYSTEM_UPDATE_AUTH_TOKEN, SYSTEM_USER_USER_ID, TEST_SYSTEM_UPDATE_USER_EMAIL);
when(idamService.retrieveUser(APP_1_SOL_AUTH_TOKEN)).thenReturn(solicitorUser);
when(idamService.retrieveSystemUpdateUserDetails()).thenReturn(systemUpdateUser);
when(authTokenGenerator.generate()).thenReturn(TEST_SERVICE_AUTH_TOKEN);
when(caseAssignmentApi.removeCaseUserRoles(eq(SYSTEM_UPDATE_AUTH_TOKEN), eq(TEST_SERVICE_AUTH_TOKEN), any(CaseAssignmentUserRolesRequest.class))).thenReturn(CaseAssignmentUserRolesResponse.builder().build());
when(caseAssignmentApi.addCaseUserRoles(eq(SYSTEM_UPDATE_AUTH_TOKEN), eq(TEST_SERVICE_AUTH_TOKEN), any(CaseAssignmentUserRolesRequest.class))).thenReturn(CaseAssignmentUserRolesResponse.builder().build());
assertThatCode(() -> ccdAccessService.addApplicant1SolicitorRole(APP_1_SOL_AUTH_TOKEN, TEST_CASE_ID, "1")).doesNotThrowAnyException();
verify(idamService).retrieveUser(APP_1_SOL_AUTH_TOKEN);
verify(idamService).retrieveSystemUpdateUserDetails();
verify(authTokenGenerator).generate();
verify(caseAssignmentApi).removeCaseUserRoles(eq(SYSTEM_UPDATE_AUTH_TOKEN), eq(TEST_SERVICE_AUTH_TOKEN), any(CaseAssignmentUserRolesRequest.class));
verify(caseAssignmentApi).addCaseUserRoles(eq(SYSTEM_UPDATE_AUTH_TOKEN), eq(TEST_SERVICE_AUTH_TOKEN), any(CaseAssignmentUserRolesRequest.class));
verifyNoMoreInteractions(idamService, authTokenGenerator, caseAssignmentApi);
}
use of uk.gov.hmcts.reform.idam.client.models.User in project nfdiv-case-api by hmcts.
the class CcdAccessServiceTest method shouldThrowInvalidTokenExceptionWhenServiceAuthTokenGenerationFails.
@Test
public void shouldThrowInvalidTokenExceptionWhenServiceAuthTokenGenerationFails() {
User solicitorUser = getIdamUser(APP_1_SOL_AUTH_TOKEN, SOLICITOR_USER_ID, TEST_SOL_USER_EMAIL);
User systemUpdateUser = getIdamUser(SYSTEM_UPDATE_AUTH_TOKEN, SYSTEM_USER_USER_ID, TEST_SYSTEM_UPDATE_USER_EMAIL);
when(idamService.retrieveUser(APP_1_SOL_AUTH_TOKEN)).thenReturn(solicitorUser);
when(idamService.retrieveSystemUpdateUserDetails()).thenReturn(systemUpdateUser);
doThrow(new InvalidTokenException("s2s secret is invalid")).when(authTokenGenerator).generate();
assertThatThrownBy(() -> ccdAccessService.addApplicant1SolicitorRole(APP_1_SOL_AUTH_TOKEN, TEST_CASE_ID, null)).isExactlyInstanceOf(InvalidTokenException.class).hasMessageContaining("s2s secret is invalid");
verify(idamService).retrieveUser(APP_1_SOL_AUTH_TOKEN);
verify(idamService).retrieveSystemUpdateUserDetails();
verifyNoMoreInteractions(idamService);
}
use of uk.gov.hmcts.reform.idam.client.models.User in project nfdiv-case-api by hmcts.
the class CcdAccessServiceTest method shouldReturnTrueWhenUserHasCreatorRole.
@Test
public void shouldReturnTrueWhenUserHasCreatorRole() {
User user = new User(TEST_SERVICE_AUTH_TOKEN, UserDetails.builder().id("user-id").build());
when(idamService.retrieveUser(SYSTEM_UPDATE_AUTH_TOKEN)).thenReturn(user);
when(authTokenGenerator.generate()).thenReturn(TEST_SERVICE_AUTH_TOKEN);
when(caseAssignmentApi.getUserRoles(SYSTEM_UPDATE_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, List.of(TEST_CASE_ID.toString()), List.of("user-id"))).thenReturn(CaseAssignmentUserRolesResource.builder().caseAssignmentUserRoles(List.of(CaseAssignmentUserRole.builder().caseRole(CREATOR.getRole()).build())).build());
boolean expected = ccdAccessService.isApplicant1(SYSTEM_UPDATE_AUTH_TOKEN, TEST_CASE_ID);
assertThat(expected).isTrue();
}
use of uk.gov.hmcts.reform.idam.client.models.User in project nfdiv-case-api by hmcts.
the class CcdAccessServiceTest method shouldNotThrowAnyExceptionWhenLinkApplicant2ToApplicationIsInvoked.
@Test
public void shouldNotThrowAnyExceptionWhenLinkApplicant2ToApplicationIsInvoked() {
User systemUpdateUser = getIdamUser(SYSTEM_UPDATE_AUTH_TOKEN, CASEWORKER_USER_ID, TEST_CASEWORKER_USER_EMAIL);
when(idamService.retrieveUser(SYSTEM_UPDATE_AUTH_TOKEN)).thenReturn(systemUpdateUser);
when(authTokenGenerator.generate()).thenReturn(TEST_SERVICE_AUTH_TOKEN);
when(caseAssignmentApi.addCaseUserRoles(eq(SYSTEM_UPDATE_AUTH_TOKEN), eq(TEST_SERVICE_AUTH_TOKEN), any(CaseAssignmentUserRolesRequest.class))).thenReturn(any());
assertThatCode(() -> ccdAccessService.linkRespondentToApplication(SYSTEM_UPDATE_AUTH_TOKEN, TEST_CASE_ID, APP_2_CITIZEN_USER_ID)).doesNotThrowAnyException();
verify(idamService).retrieveUser(SYSTEM_UPDATE_AUTH_TOKEN);
verify(authTokenGenerator).generate();
verify(caseAssignmentApi).addCaseUserRoles(eq(SYSTEM_UPDATE_AUTH_TOKEN), eq(TEST_SERVICE_AUTH_TOKEN), any(CaseAssignmentUserRolesRequest.class));
verifyNoMoreInteractions(idamService, authTokenGenerator, caseAssignmentApi);
}
Aggregations