Skip to content

Commit

Permalink
Feat:SRD- Test coverage (#710)
Browse files Browse the repository at this point in the history
* RDCC-5984:Changes made to add additional test cases
  • Loading branch information
shivajihmcts authored Nov 14, 2023
1 parent e9d0ed6 commit bf4a5f4
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerLocationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerServicesRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.StaffProfileCreationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.StaffProfileRoleRequest;
import uk.gov.hmcts.reform.cwrdapi.domain.CaseWorkerProfile;
import uk.gov.hmcts.reform.cwrdapi.domain.StaffAudit;
import uk.gov.hmcts.reform.cwrdapi.repository.CaseWorkerLocationRepository;
import uk.gov.hmcts.reform.cwrdapi.repository.CaseWorkerProfileRepository;
Expand Down Expand Up @@ -95,6 +97,7 @@ public static void tearDown() {

@Test
@DisplayName("Create Staff profile with status 201")
@Transactional
void should_return_staff_user_with_status_code_201() {
CaseWorkerReferenceDataClient.setBearerToken(EMPTY);
userProfilePostUserWireMockForStaffProfile(HttpStatus.CREATED);
Expand All @@ -106,7 +109,9 @@ void should_return_staff_user_with_status_code_201() {
.isNotNull()
.containsEntry("http_status", "201 CREATED");

assertThat(response.get("case_worker_id")).isNotNull();
String caseWorkerId = ((Map<String, String>)response.get("body")).get("case_worker_id");
assertThat(caseWorkerId).isNotNull();
validateCreateCaseWorkerProfile(request.getEmailId(),caseWorkerId);
}


Expand Down Expand Up @@ -460,4 +465,51 @@ void should_return_create_staff_user_with_status_code_400_invalid_roles() throws
assertThat(caseWorkerSkillRepository.count()).isZero();
assertThat(staffAuditRepository.count()).isEqualTo(1);
}

void validateCreateCaseWorkerProfile(String emailId, String caseWorkerId) {

CaseWorkerProfile caseWorkerProfile = caseWorkerProfileRepository.findByEmailId(emailId);

assertThat(caseWorkerProfile).isNotNull();

assertThat(caseWorkerProfile.getEmailId()).isNotNull();

assertThat(caseWorkerProfile.getFirstName()).isEqualTo("StaffProfilefirstName");
assertThat(caseWorkerProfile.getLastName()).isEqualTo("StaffProfilelastName");
assertThat(caseWorkerProfile.getRegion()).isEqualTo("National");
assertThat(caseWorkerProfile.getSuspended()).isFalse();
assertThat(caseWorkerProfile.getTaskSupervisor()).isTrue();
assertThat(caseWorkerProfile.getCaseAllocator()).isTrue();

assertThat(caseWorkerProfile.getUserAdmin()).isFalse();

assertThat(caseWorkerProfile.getUserType().getUserTypeId()).isEqualTo(1);
assertThat(caseWorkerProfile.getUserType().getDescription()).isEqualTo("CTSC");

assertThat(caseWorkerProfile.getCaseWorkerRoles()).hasSize(1);
assertThat(caseWorkerProfile.getCaseWorkerRoles().get(0).getRoleId()).isEqualTo(2);
assertThat(caseWorkerProfile.getCaseWorkerRoles().get(0).getPrimaryFlag()).isTrue();

assertThat(caseWorkerProfile.getCaseWorkerLocations()).hasSize(2);
assertThat(caseWorkerProfile.getCaseWorkerLocations().get(0).getLocationId()).isEqualTo(6789);
assertThat(caseWorkerProfile.getCaseWorkerLocations().get(0).getLocation()).isEqualTo("test location2");

assertThat(caseWorkerProfile.getCaseWorkerWorkAreas()).hasSize(2);
assertThat(caseWorkerProfile.getCaseWorkerWorkAreas().get(0).getServiceCode()).isEqualTo("ABA1");

assertThat(caseWorkerProfile.getCaseWorkerSkills()).hasSize(1);
assertThat(caseWorkerProfile.getCaseWorkerSkills().get(0).getSkillId()).isEqualTo(9);

List<StaffAudit> staffAudits = staffAuditRepository.findAll();

assertThat(staffAudits.size()).isEqualTo(1);
assertThat(staffAudits.get(0).getStatus()).isEqualTo("SUCCESS");
assertThat(staffAudits.get(0).getOperationType()).isEqualTo("CREATE");
assertThat(staffAudits.get(0).getErrorDescription()).isBlank();
assertThat(staffAudits.get(0).getRequestLog()).isNotNull();
assertThat(staffAudits.get(0).getRequestTimeStamp()).isNotNull();
assertThat(staffAudits.get(0).getCaseWorkerId()).isEqualTo(caseWorkerId);


}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package uk.gov.hmcts.reform.cwrdapi;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffRefDataJobTitle;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffRefDataUserType;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffRefDataUserTypesResponse;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffRefJobTitleResponse;
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffWorkerSkillResponse;
import uk.gov.hmcts.reform.cwrdapi.domain.ServiceSkill;
import uk.gov.hmcts.reform.cwrdapi.domain.SkillDTO;
import uk.gov.hmcts.reform.cwrdapi.util.AuthorizationEnabledIntegrationTest;
import uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerReferenceDataClient;

import java.util.ArrayList;
import java.util.List;

import static org.apache.logging.log4j.util.Strings.EMPTY;
Expand Down Expand Up @@ -50,12 +59,14 @@ void should_retrieveAllServiceSkills_return_status_code_200()

List<ServiceSkill> serviceSkills = staffWorkerSkillResponse.getServiceSkills();

assertThat(serviceSkills).isNotNull();
assertThat(serviceSkills.size()).isEqualTo(3);

ServiceSkill serviceSkill = serviceSkills.get(0);

assertThat(serviceSkill.getId()).isEqualTo("AAA7");

assertThat(serviceSkill.getSkills().size()).isEqualTo(4);

SkillDTO skillDTO = serviceSkill.getSkills().get(0);

assertThat(skillDTO.getSkillId()).isEqualTo(9L);
Expand All @@ -80,13 +91,16 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_empty_serviceco
List<ServiceSkill> serviceSkills = staffWorkerSkillResponse.getServiceSkills();

assertThat(serviceSkills).isNotNull();
assertThat(serviceSkills.size()).isEqualTo(3);

ServiceSkill serviceSkill = serviceSkills.get(0);

assertThat(serviceSkill.getId()).isEqualTo("AAA7");

SkillDTO skillDTO = serviceSkill.getSkills().get(0);

assertThat(serviceSkill.getSkills().size()).isEqualTo(4);

assertThat(skillDTO.getSkillId()).isEqualTo(9L);
assertThat(skillDTO.getSkillCode()).isEqualTo("SKILL:AAA7:TEST1");
assertThat(skillDTO.getDescription()).isEqualTo("testskill1");
Expand Down Expand Up @@ -116,6 +130,8 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_provide_multipl

SkillDTO skillDTO = serviceSkill.getSkills().get(0);

assertThat(serviceSkill.getSkills().size()).isEqualTo(4);

assertThat(skillDTO.getSkillId()).isEqualTo(9L);
assertThat(skillDTO.getSkillCode()).isEqualTo("SKILL:AAA7:TEST1");
assertThat(skillDTO.getDescription()).isEqualTo("testskill1");
Expand All @@ -128,6 +144,7 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_provide_multipl

skillDTO = serviceSkill.getSkills().get(0);

assertThat(serviceSkill.getSkills().size()).isEqualTo(11);


assertThat(skillDTO.getSkillId()).isEqualTo(26L);
Expand Down Expand Up @@ -160,6 +177,8 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_provide_single_

SkillDTO skillDTO = serviceSkill.getSkills().get(0);

assertThat(serviceSkill.getSkills().size()).isEqualTo(4);

assertThat(skillDTO.getSkillId()).isEqualTo(9L);
assertThat(skillDTO.getSkillCode()).isEqualTo("SKILL:AAA7:TEST1");
assertThat(skillDTO.getDescription()).isEqualTo("testskill1");
Expand All @@ -168,4 +187,118 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_provide_single_

}

@Test
void should_retrieveAllServiceSkills_return_status_code_200_when_provide_invalid_servicecode()
throws JsonProcessingException {
String path = "/skill?service_codes=Invalid";

String role = "staff-admin";


final var staffWorkerSkillResponse = (StaffWorkerSkillResponse) caseworkerReferenceDataClient
.retrieveAllServiceSkills(StaffWorkerSkillResponse.class, path, role);

assertThat(staffWorkerSkillResponse).isNotNull();

List<ServiceSkill> serviceSkills = staffWorkerSkillResponse.getServiceSkills();

assertThat(serviceSkills.size()).isEqualTo(0);

}

@Test
void should_retrieveAllTitles_return_status_code_200()
throws JsonProcessingException {
String path = "/job-title";

String role = "staff-admin";


final var staffRefJobTitleResponse = (StaffRefJobTitleResponse) caseworkerReferenceDataClient
.retrieveStaffRefData(StaffRefJobTitleResponse.class, path, role);

assertThat(staffRefJobTitleResponse).isNotNull();

List<StaffRefDataJobTitle> jobTitles = staffRefJobTitleResponse.getJobTitles();

assertThat(jobTitles).isNotNull();
assertThat(jobTitles).hasSize(18);

StaffRefDataJobTitle staffRefDataJobTitle = jobTitles.get(0);

assertThat(staffRefDataJobTitle.getRoleId()).isEqualTo(3L);
assertThat(staffRefDataJobTitle.getRoleDescription()).isEqualTo("Hearing Centre Team Leader");

}

@Test
void should_retrieveAllUserTypes_return_status_code_200()
throws JsonProcessingException, JSONException {
String path = "/user-type";

String role = "staff-admin";


final var staffRefDataUserTypesResponse = (StaffRefDataUserTypesResponse) caseworkerReferenceDataClient
.retrieveStaffRefData(StaffRefDataUserTypesResponse.class, path, role);

assertThat(staffRefDataUserTypesResponse).isNotNull();

List<StaffRefDataUserType> userTypes = staffRefDataUserTypesResponse.getUserTypes();

assertThat(userTypes).isNotNull();
assertThat(userTypes).hasSize(5);


validateUserTypes(userTypes);

}

void validateUserTypes(List<StaffRefDataUserType> userTypes) throws JsonProcessingException, JSONException {

ObjectMapper mapper = new ObjectMapper();

String actual = mapper.writeValueAsString(getUserTypesData());
String userTypesData = mapper.writeValueAsString(userTypes);

JSONAssert.assertEquals(userTypesData, actual, JSONCompareMode.LENIENT);

}

private List<StaffRefDataUserType> getUserTypesData() {

List<StaffRefDataUserType> userTypes = new ArrayList<>();
StaffRefDataUserType staffRefDataUserType;

userTypes.add(StaffRefDataUserType.builder()
.id(1L)
.code("CTSC")
.build());

userTypes.add(StaffRefDataUserType.builder()
.id(2L)
.code("Future Operations")
.build());

userTypes.add(StaffRefDataUserType.builder()
.id(3L)
.code("Legal office")
.build());

userTypes.add(StaffRefDataUserType.builder()
.id(4L)
.code("NBC")
.build());

userTypes.add(StaffRefDataUserType.builder()
.id(5L)
.code("Other Government Department")
.build());


return userTypes;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerLocationRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerServicesRequest;
import uk.gov.hmcts.reform.cwrdapi.controllers.request.SkillsRequest;
Expand Down Expand Up @@ -100,6 +101,7 @@ public static void tearDown() {


@Test
@Transactional
void should_return_update_staff_user_with_status_code_200_child_tables_size() throws Exception {

CaseWorkerReferenceDataClient.setBearerToken(EMPTY);
Expand All @@ -126,22 +128,14 @@ void should_return_update_staff_user_with_status_code_200_child_tables_size() th
assertThat(response.get("case_worker_id")).isNotNull();
assertThat(response.get("http_status")).isEqualTo("200 OK");

String caseWorkerId = ((Map<String, String>)response.get("body")).get("case_worker_id");
assertThat(caseWorkerId).isNotNull();

List<StaffAudit> staffAudits = staffAuditRepository.findAll();


validateUpdateCaseWorkerProfile(request.getEmailId(),caseWorkerId);

assertThat(staffAudits.size()).isEqualTo(2);
assertThat(staffAudits.get(0).getStatus()).isEqualTo("SUCCESS");
assertThat(staffAudits.get(0).getOperationType()).isEqualTo("CREATE");
assertThat(staffAudits.get(0).getErrorDescription()).isBlank();

assertThat(staffAudits.get(1).getStatus()).isEqualTo("SUCCESS");
assertThat(staffAudits.get(1).getOperationType()).isEqualTo("UPDATE");
assertThat(staffAudits.get(1).getErrorDescription()).isBlank();
List<StaffAudit> staffAudits = staffAuditRepository.findAll();

assertThat(staffAudits.get(1).getRequestLog().contains(request.getFirstName())).isTrue();
assertThat(staffAudits.get(1).getRequestLog().contains(request.getLastName())).isTrue();

ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Expand Down Expand Up @@ -562,7 +556,58 @@ public StaffProfileCreationRequest getStaffProfileCreationRequest() {

}

void validateUpdateCaseWorkerProfile(String emailId, String caseWorkerId) {

CaseWorkerProfile caseWorkerProfile = caseWorkerProfileRepository.findByEmailId(emailId);

assertThat(caseWorkerProfile).isNotNull();

assertThat(caseWorkerProfile.getEmailId()).isNotNull();


assertThat(caseWorkerProfile.getFirstName()).isEqualTo("StaffProfilefirstNameCN");
assertThat(caseWorkerProfile.getLastName()).isEqualTo("StaffProfilelastNameCN");
assertThat(caseWorkerProfile.getRegion()).isEqualTo("National");
assertThat(caseWorkerProfile.getSuspended()).isFalse();
assertThat(caseWorkerProfile.getTaskSupervisor()).isTrue();
assertThat(caseWorkerProfile.getCaseAllocator()).isTrue();

assertThat(caseWorkerProfile.getUserAdmin()).isFalse();

assertThat(caseWorkerProfile.getUserType().getUserTypeId()).isEqualTo(1);
assertThat(caseWorkerProfile.getUserType().getDescription()).isEqualTo("CTSC");

assertThat(caseWorkerProfile.getCaseWorkerRoles()).hasSize(1);
assertThat(caseWorkerProfile.getCaseWorkerRoles().get(0).getRoleId()).isEqualTo(2);
assertThat(caseWorkerProfile.getCaseWorkerRoles().get(0).getPrimaryFlag()).isTrue();

assertThat(caseWorkerProfile.getCaseWorkerLocations()).hasSize(2);
assertThat(caseWorkerProfile.getCaseWorkerLocations().get(0).getLocationId()).isEqualTo(6789);
assertThat(caseWorkerProfile.getCaseWorkerLocations().get(0).getLocation()).isEqualTo("test location2");

assertThat(caseWorkerProfile.getCaseWorkerWorkAreas()).hasSize(2);
assertThat(caseWorkerProfile.getCaseWorkerWorkAreas().get(0).getServiceCode()).isEqualTo("ABA1");

assertThat(caseWorkerProfile.getCaseWorkerSkills()).hasSize(1);
assertThat(caseWorkerProfile.getCaseWorkerSkills().get(0).getSkillId()).isEqualTo(9);

List<StaffAudit> staffAudits = staffAuditRepository.findAll();



assertThat(staffAudits.size()).isEqualTo(2);
assertThat(staffAudits.get(0).getStatus()).isEqualTo("SUCCESS");
assertThat(staffAudits.get(0).getOperationType()).isEqualTo("CREATE");
assertThat(staffAudits.get(0).getErrorDescription()).isBlank();

assertThat(staffAudits.get(1).getStatus()).isEqualTo("SUCCESS");
assertThat(staffAudits.get(1).getOperationType()).isEqualTo("UPDATE");
assertThat(staffAudits.get(1).getErrorDescription()).isBlank();

assertThat(staffAudits.get(1).getRequestLog().contains(caseWorkerProfile.getFirstName())).isTrue();
assertThat(staffAudits.get(1).getRequestLog().contains(caseWorkerProfile.getFirstName())).isTrue();

}


}
Loading

0 comments on commit bf4a5f4

Please sign in to comment.