diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java index 17730834e..f57487d4b 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java @@ -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; @@ -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); @@ -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)response.get("body")).get("case_worker_id"); + assertThat(caseWorkerId).isNotNull(); + validateCreateCaseWorkerProfile(request.getEmailId(),caseWorkerId); } @@ -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 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); + + + } } diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataIntegrationTest.java index 6788e7cf1..e9f4d3a96 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataIntegrationTest.java @@ -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; @@ -50,12 +59,14 @@ void should_retrieveAllServiceSkills_return_status_code_200() List 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); @@ -80,6 +91,7 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_empty_serviceco List serviceSkills = staffWorkerSkillResponse.getServiceSkills(); assertThat(serviceSkills).isNotNull(); + assertThat(serviceSkills.size()).isEqualTo(3); ServiceSkill serviceSkill = serviceSkills.get(0); @@ -87,6 +99,8 @@ void should_retrieveAllServiceSkills_return_status_code_200_when_empty_serviceco 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"); @@ -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"); @@ -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); @@ -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"); @@ -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 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 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 userTypes = staffRefDataUserTypesResponse.getUserTypes(); + + assertThat(userTypes).isNotNull(); + assertThat(userTypes).hasSize(5); + + + validateUserTypes(userTypes); + + } + + void validateUserTypes(List 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 getUserTypesData() { + + List 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; + } + + + } diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/UpdateStaffReferenceProfileTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/UpdateStaffReferenceProfileTest.java index 60726f33f..4e0185ebf 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/UpdateStaffReferenceProfileTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/UpdateStaffReferenceProfileTest.java @@ -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; @@ -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); @@ -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)response.get("body")).get("case_worker_id"); + assertThat(caseWorkerId).isNotNull(); - List 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 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); @@ -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 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(); + + } } \ No newline at end of file diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java index ce8dcb55f..39f559932 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java @@ -123,6 +123,12 @@ public Object retrieveAllServiceSkills(Class clazz, return mapServiceSkillsIdResponse(responseEntity, clazz); } + public Object retrieveStaffRefData(Class clazz, + String path, String role) throws JsonProcessingException { + ResponseEntity responseEntity = getRequest(path, clazz, role); + return mapServiceSkillsIdResponse(responseEntity, clazz); + } + private Object mapServiceSkillsIdResponse(ResponseEntity responseEntity, Class clazz) throws JsonProcessingException { HttpStatus status = responseEntity.getStatusCode(); diff --git a/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataController.java b/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataController.java index b633e7478..7631f6b43 100644 --- a/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataController.java +++ b/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataController.java @@ -237,19 +237,20 @@ public ResponseEntity fetchUserTypes() { description = "Successfully retrieved list of Job Titles for the request provided", content = @Content(schema = @Schema(implementation = StaffRefJobTitleResponse.class)) ) + @ApiResponse( - responseCode = "400", - description = "Bad Request", + responseCode = "401", + description = UNAUTHORIZED_ERROR, content = @Content ) @ApiResponse( - responseCode = "401", - description = "Forbidden Error: Access denied", + responseCode = "403", + description = FORBIDDEN_ERROR, content = @Content ) @ApiResponse( responseCode = "500", - description = "Internal Server Error", + description = INTERNAL_SERVER_ERROR, content = @Content ) @GetMapping( diff --git a/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/response/StaffRefDataUserType.java b/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/response/StaffRefDataUserType.java index 59733dddd..bcfa704f1 100644 --- a/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/response/StaffRefDataUserType.java +++ b/src/main/java/uk/gov/hmcts/reform/cwrdapi/controllers/response/StaffRefDataUserType.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -11,6 +12,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor +@Builder public class StaffRefDataUserType { @JsonProperty("id") diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java index 73af9f0bb..d97cc5538 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java @@ -214,10 +214,6 @@ void test_StaffRefDataController_Args() { } - - - - @Test void shouldFetchUserTypes() { responseEntity = ResponseEntity.status(200).body(null); @@ -232,6 +228,12 @@ void shouldFetchUserTypes() { assertEquals(responseEntity.getStatusCode(), actual.getStatusCode()); assertEquals((userTypes.size()), actualResponse.getUserTypes().size()); List actualResultUserType = new ArrayList<>(actualResponse.getUserTypes()); + + assertThat(actualResultUserType).hasSize(2); + + assertThat(actualResultUserType.get(0).getId()).isEqualTo(1L); + assertThat(actualResultUserType.get(0).getCode()).isEqualTo("Test"); + //assert all attributes lists assertTrue(verifyAllUserTypes(actualResultUserType, userTypes)); } diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/RoleTypeRepositoryTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/RoleTypeRepositoryTest.java index 93c3262d8..54176ffb5 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/RoleTypeRepositoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/RoleTypeRepositoryTest.java @@ -3,9 +3,9 @@ import org.junit.jupiter.api.Test; import uk.gov.hmcts.reform.cwrdapi.domain.RoleType; -import java.util.ArrayList; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -13,11 +13,31 @@ class RoleTypeRepositoryTest { RoleTypeRepository roleTypeRepository = mock(RoleTypeRepository.class); - List roleTypes = new ArrayList<>(); @Test - void findByServiceCodeTest() { + void findAllRoleTypesTest() { + List roleTypes = getUserTypesData(); when(roleTypeRepository.findAll()).thenReturn(roleTypes); assertNotNull(roleTypeRepository.findAll()); + + assertThat(roleTypes).hasSize(1); + + RoleType roleType = roleTypes.get(0); + + assertThat(roleType.getRoleId()).isEqualTo(1L); + assertThat(roleType.getDescription()).isEqualTo("testRole1"); + + } + + private List getUserTypesData() { + + RoleType roleType = new RoleType(); + roleType.setRoleId(1L); + roleType.setDescription("testRole1"); + + + List roleTypes = List.of(roleType); + + return roleTypes; } } diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/SkillRepositoryTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/SkillRepositoryTest.java index 1d113bf87..f172a2eac 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/SkillRepositoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/SkillRepositoryTest.java @@ -3,21 +3,41 @@ import org.junit.jupiter.api.Test; import uk.gov.hmcts.reform.cwrdapi.domain.Skill; -import java.util.ArrayList; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; class SkillRepositoryTest { private SkillRepository skillRepository = mock(SkillRepository.class); - private List skills = new ArrayList<>(); @Test - void findByServiceCodeTest() { + void findAllSkillsTest() { + List skills = getSkillsData(); when(skillRepository.findAll()).thenReturn(skills); assertNotNull(skillRepository.findAll()); + assertThat(skills).hasSize(1); + Skill skill = skills.get(0); + assertThat(skill.getServiceId()).isEqualTo("BBA3"); + assertThat(skill.getSkillId()).isEqualTo(1L); + assertThat(skill.getSkillCode()).isEqualTo("A1"); + assertThat(skill.getDescription()).isEqualTo("desc1"); + assertThat(skill.getUserType()).isEqualTo("user_type1"); + } + + private List getSkillsData() { + Skill skill1 = new Skill(); + skill1.setServiceId("BBA3"); + skill1.setSkillId(1L); + skill1.setSkillCode("A1"); + skill1.setDescription("desc1"); + skill1.setUserType("user_type1"); + + List skills = List.of(skill1); + + return skills; } } diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/UserTypeRepositoryTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/UserTypeRepositoryTest.java index ad741158e..2bf7bd61a 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/UserTypeRepositoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/repository/UserTypeRepositoryTest.java @@ -3,9 +3,9 @@ import org.junit.jupiter.api.Test; import uk.gov.hmcts.reform.cwrdapi.domain.UserType; -import java.util.ArrayList; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -13,11 +13,32 @@ class UserTypeRepositoryTest { UserTypeRepository userTypeRepository = mock(UserTypeRepository.class); - List userTypes = new ArrayList<>(); @Test - void findByServiceCodeTest() { + void findAllUserTypesTest() { + + List userTypes = getUserTypesData(); when(userTypeRepository.findAll()).thenReturn(userTypes); assertNotNull(userTypeRepository.findAll()); + + assertThat(userTypes).hasSize(1); + + UserType userType = userTypes.get(0); + + assertThat(userType.getUserTypeId()).isEqualTo(1L); + assertThat(userType.getDescription()).isEqualTo("testUser1"); } + + private List getUserTypesData() { + + UserType userType = new UserType(); + userType.setUserTypeId(1L); + userType.setDescription("testUser1"); + + List userTypes = List.of(userType); + + return userTypes; + } + + } diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/StaffRefDataServiceTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/StaffRefDataServiceTest.java index 83b335ddb..cd156e284 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/StaffRefDataServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/StaffRefDataServiceTest.java @@ -197,6 +197,10 @@ void testFetchUserType_one() { var staffRefDataUserTypesResponses = (List) staffRefDataServiceImpl .fetchUserTypes(); assertFalse(verifyCurrentUserTypes(staffRefDataUserTypesResponses.get(0))); + + UserType userType = staffRefDataUserTypesResponses.get(0); + assertThat(userType.getUserTypeId()).isEqualTo(1L); + assertThat(userType.getDescription()).isEqualTo("User Type 1"); } @Test