Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dtsrd 2146 #884

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion infrastructure/demo.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
db_replicas = ["replica"]
pgsql_sku = "GP_Standard_D2s_v3"
pgsql_sku = "GP_Standard_D2s_v3"

3 changes: 2 additions & 1 deletion infrastructure/ithc.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
db_replicas = ["replica"]
pgsql_sku = "GP_Standard_D2s_v3"
pgsql_sku = "GP_Standard_D2s_v3"

Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ActiveProfiles;
import uk.gov.hmcts.reform.cwrdapi.client.domain.CaseWorkerProfile;
import uk.gov.hmcts.reform.cwrdapi.client.domain.StaffProfileWithServiceName;
import uk.gov.hmcts.reform.cwrdapi.client.domain.WorkArea;
import uk.gov.hmcts.reform.cwrdapi.client.response.UserProfileResponse;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerRoleRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerWorkAreaRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkersProfileCreationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkersProfileUpdationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.UserRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.CaseWorkerFileCreationResponse;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.CaseWorkerProfileCreationResponse;
Expand All @@ -51,6 +53,7 @@

import static java.lang.String.format;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -797,6 +800,42 @@ private void createCaseWorkerIds() {
caseWorkerIds = caseWorkerProfileCreationResponse.getCaseWorkerIds();
}

@Test
public void updateCaseworkerToSuspended() {

List<CaseWorkersProfileCreationRequest> caseWorkersProfileCreationRequests = caseWorkerApiClient
.createCaseWorkerProfiles();
Response response = caseWorkerApiClient.createUserProfiles(caseWorkersProfileCreationRequests);

CaseWorkerProfileCreationResponse caseWorkerProfileCreationResponse =
response.getBody().as(CaseWorkerProfileCreationResponse.class);
List<String> caseWorkerIds = caseWorkerProfileCreationResponse.getCaseWorkerIds();

CaseWorkersProfileUpdationRequest caseWorkersProfileUpdationRequest = CaseWorkersProfileUpdationRequest
.caseWorkersProfileUpdationRequest().firstName("StaffProfilefirstNamesnew")
.lastName("StaffProfilelastNamenew")
.userId(caseWorkerIds.get(0))
.emailId(String.format(EMAIL_TEMPLATE, randomAlphanumeric(10)).toLowerCase())
.suspended(true)
.build();

Response updateResponse = caseWorkerApiClient.updateCaseWorkerProfile(caseWorkersProfileUpdationRequest);
assertEquals(200,updateResponse.statusCode());
Response fetchResponse = caseWorkerApiClient.getMultipleAuthHeadersInternal(ROLE_CWD_SYSTEM_USER)
.body(UserRequest.builder().userIds(caseWorkerIds).build())
.post("/refdata/case-worker/users/fetchUsersById/")
.andReturn();
fetchResponse.then()
.assertThat()
.statusCode(200);

List<CaseWorkerProfile> fetchedList =
Arrays.asList(fetchResponse.getBody().as(
CaseWorkerProfile[].class));
assertEquals(1, fetchedList.size());
assertEquals("true", fetchedList.get(0).getSuspended());
}

@AfterAll
public static void cleanUpTestData() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import uk.gov.hmcts.reform.cwrdapi.controllers.response.CaseWorkersProfileUpdationResponse;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffProfileCreationResponse;
import uk.gov.hmcts.reform.cwrdapi.domain.CaseWorkerProfile;
import uk.gov.hmcts.reform.cwrdapi.domain.UserProfileUpdatedData;
import uk.gov.hmcts.reform.cwrdapi.service.CaseWorkerDeleteService;
import uk.gov.hmcts.reform.cwrdapi.service.CaseWorkerProfileUpdateservice;
import uk.gov.hmcts.reform.cwrdapi.service.CaseWorkerService;
import uk.gov.hmcts.reform.cwrdapi.service.StaffRefDataService;

import java.util.List;
import java.util.Optional;

import static java.lang.String.format;
import static org.apache.commons.lang3.ObjectUtils.isEmpty;
Expand All @@ -51,6 +53,8 @@
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.API_IS_NOT_AVAILABLE_IN_PROD_ENV;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.BAD_REQUEST;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.FORBIDDEN_ERROR;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.IDAM_STATUS_PENDING;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.IDAM_STATUS_SUSPENDED;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.INTERNAL_SERVER_ERROR;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.NO_DATA_FOUND;
import static uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants.RECORDS_UPLOADED;
Expand Down Expand Up @@ -337,9 +341,18 @@ public ResponseEntity<Object> updateCaseWorkerDetails(@RequestBody CaseWorkersPr
caseWorkersProfileUpdationResponse = caseWorkerProfileUpdateservice
.updateCaseWorkerProfile(caseWorkersProfileUpdationRequest);
if (isNotEmpty(caseWorkersProfileUpdationResponse)) {
StaffProfileCreationResponse staffProfileCreationResponse = StaffProfileCreationResponse
.builder().caseWorkerId(caseWorkersProfileUpdationResponse.getUserId()).build();
staffRefDataService.publishStaffProfileToTopic(staffProfileCreationResponse);

Optional<Object> resultResponse = caseWorkerService.getUserProfileUpdateResponse(
UserProfileUpdatedData.builder().idamStatus(
caseWorkersProfileUpdationRequest.getSuspended() ? IDAM_STATUS_SUSPENDED
: IDAM_STATUS_PENDING).build(),
caseWorkersProfileUpdationRequest.getUserId(), "NON-EXUI");

if (isNotEmpty(resultResponse)) {
StaffProfileCreationResponse staffProfileCreationResponse = StaffProfileCreationResponse
.builder().caseWorkerId(caseWorkersProfileUpdationResponse.getUserId()).build();
staffRefDataService.publishStaffProfileToTopic(staffProfileCreationResponse);
}
}
return ResponseEntity
.status(HttpStatus.OK).body(caseWorkersProfileUpdationResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkersProfileCreationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.IdamRolesMappingResponse;
import uk.gov.hmcts.reform.cwrdapi.domain.CaseWorkerProfile;
import uk.gov.hmcts.reform.cwrdapi.domain.UserProfileUpdatedData;

import java.util.List;
import java.util.Optional;

@Service
public interface CaseWorkerService {
Expand Down Expand Up @@ -47,5 +49,8 @@ List<CaseWorkerProfile> processCaseWorkerProfiles(List<CaseWorkersProfileCreatio
* @return StaffProfile
*/
ResponseEntity<Object> fetchStaffProfilesForRoleRefresh(String ccdServiceNames, PageRequest pageRequest);

public Optional<Object> getUserProfileUpdateResponse(UserProfileUpdatedData userProfileUpdatedData,
String userId, String origin);
}

Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public boolean isEachRoleUpdated(UserProfileUpdatedData userProfileUpdatedData,
return isEachRoleUpdated;
}

private Optional<Object> getUserProfileUpdateResponse(UserProfileUpdatedData userProfileUpdatedData,
public Optional<Object> getUserProfileUpdateResponse(UserProfileUpdatedData userProfileUpdatedData,
String userId, String origin) {
Response response = userProfileFeignClient.modifyUserRoles(userProfileUpdatedData, userId, origin);
log.info("{}:: UserProfile update roles :: status code {}:: Job Id {}", loggingComponentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkersProfileUpdationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.UserRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.CaseWorkerProfileCreationResponse;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.CaseWorkersProfileUpdationResponse;
import uk.gov.hmcts.reform.cwrdapi.domain.CaseWorkerProfile;
import uk.gov.hmcts.reform.cwrdapi.service.CaseWorkerProfileUpdateservice;
import uk.gov.hmcts.reform.cwrdapi.service.CaseWorkerService;
import uk.gov.hmcts.reform.cwrdapi.service.StaffRefDataService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -40,6 +43,7 @@ class CaseWorkerRefUsersControllerTest {

CaseWorkerService caseWorkerServiceMock;
CaseWorkerProfileUpdateservice caseWorkerProfileUpdateserviceMock;
StaffRefDataService staffRefDataServiceMock;
List<CaseWorkersProfileCreationRequest> caseWorkersProfileCreationRequest = new ArrayList<>();
CaseWorkersProfileCreationRequest cwRequest;
CaseWorkerProfileCreationResponse cwProfileCreationResponse;
Expand All @@ -52,6 +56,7 @@ class CaseWorkerRefUsersControllerTest {
void setUp() {
caseWorkerServiceMock = mock(CaseWorkerService.class);
caseWorkerProfileUpdateserviceMock = mock(CaseWorkerProfileUpdateservice.class);
staffRefDataServiceMock = mock(StaffRefDataService.class);
cwResponse = CaseWorkerProfileCreationResponse
.builder()
.caseWorkerRegistrationResponse("Case Worker Profiles Created.")
Expand Down Expand Up @@ -232,4 +237,40 @@ void updateCaseWorkerProfileFromProfileSyncShouldThrow400() {
caseWorkerRefUsersController.updateCaseWorkerDetails(caseWorkersProfileUpdationRequest));

}

@Test
void updateCaseWorkerProfileAlsoUpdateStaffProfile() {

CaseWorkersProfileUpdationRequest caseWorkersProfileUpdationRequest = CaseWorkersProfileUpdationRequest
.caseWorkersProfileUpdationRequest()
.suspended(true)
.build();
when(caseWorkerProfileUpdateserviceMock.updateCaseWorkerProfile(caseWorkersProfileUpdationRequest))
.thenReturn(new CaseWorkersProfileUpdationResponse());
when(caseWorkerServiceMock.getUserProfileUpdateResponse(any(), any(), any()))
.thenReturn(Optional.empty());
ResponseEntity<?> actual =
caseWorkerRefUsersController.updateCaseWorkerDetails(caseWorkersProfileUpdationRequest);
assertNotNull(actual);
verify(staffRefDataServiceMock, times(1))
.publishStaffProfileToTopic(any());
}

@Test
void updateCaseWorkerProfileWhenUserIdEmpty() {

when(caseWorkerServiceMock.getUserProfileUpdateResponse(any(), any(), any()))
.thenReturn(any());
CaseWorkersProfileUpdationRequest caseWorkersProfileUpdationRequest = CaseWorkersProfileUpdationRequest
.caseWorkersProfileUpdationRequest()
.suspended(true)
.build();
when(caseWorkerProfileUpdateserviceMock.updateCaseWorkerProfile(caseWorkersProfileUpdationRequest))
.thenReturn(new CaseWorkersProfileUpdationResponse());
ResponseEntity<?> actual =
caseWorkerRefUsersController.updateCaseWorkerDetails(caseWorkersProfileUpdationRequest);
assertNotNull(actual);
verify(staffRefDataServiceMock, times(0))
.publishStaffProfileToTopic(any());
}
}