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

MAN-190: Added lao checks for caseload search #4477

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.audit.BusinessInteraction
import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.data.generator.CourtAppearanceGenerator.COURT_APPEARANCE
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.GENDER_MALE
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode
import uk.gov.justice.digital.hmpps.user.AuditUserRepository
Expand Down Expand Up @@ -41,6 +42,7 @@ class DataLoader(
ContactGenerator.DEFAULT_BOROUGH,
ContactGenerator.DEFAULT_DISTRICT,
ContactGenerator.DEFAULT_STAFF,
ContactGenerator.LIMITED_ACCESS_STAFF,
ContactGenerator.STAFF_1,
ContactGenerator.DEFAULT_TEAM,
ContactGenerator.LOCATION_BRK_1,
Expand All @@ -49,7 +51,9 @@ class DataLoader(

entityManager.persist(ContactGenerator.USER_1)

entityManager.persist(PersonGenerator.OVERVIEW.gender)
entityManager.persist(ContactGenerator.LIMITED_ACCESS_USER)

entityManager.persist(GENDER_MALE)

PersonGenerator.DISABILITIES.forEach { entityManager.persist(it.type) }
PersonGenerator.PROVISIONS.forEach { entityManager.persist(it.type) }
Expand All @@ -62,7 +66,6 @@ class DataLoader(
entityManager.persistCollection(PersonGenerator.PROVISIONS)
entityManager.persistCollection(PersonGenerator.PERSONAL_CIRCUMSTANCES)
entityManager.persist(PersonGenerator.OVERVIEW)

entityManager.persist(CourtGenerator.BHAM)
entityManager.persist(PersonGenerator.EVENT_1)
entityManager.persist(PersonGenerator.EVENT_2)
Expand Down Expand Up @@ -188,6 +191,9 @@ class DataLoader(
PersonDetailsGenerator.LANGUAGE_RD,
PersonDetailsGenerator.GENDER_IDENTITY_RD,
PersonDetailsGenerator.PERSONAL_DETAILS,
PersonDetailsGenerator.RESTRICTION,
PersonDetailsGenerator.EXCLUSION,
PersonDetailsGenerator.RESTRICTION_EXCLUSION,
PersonDetailsGenerator.DISABILITY_1_RD,
PersonDetailsGenerator.DISABILITY_2_RD,
PersonDetailsGenerator.PERSONAL_CIRCUMSTANCE_1_RD,
Expand Down Expand Up @@ -222,10 +228,23 @@ class DataLoader(
entityManager.flush()
entityManager.merge(PersonGenerator.PERSON_1)
entityManager.merge(PersonGenerator.PERSON_2)
entityManager.merge(PersonGenerator.CL_EXCLUDED)
entityManager.merge(PersonGenerator.CL_RESTRICTED)
entityManager.merge(PersonGenerator.CL_RESTRICTED_EXCLUDED)
entityManager.flush()
entityManager.persist(PersonGenerator.CASELOAD_PERSON_1)
entityManager.persist(PersonGenerator.CASELOAD_PERSON_2)
entityManager.persist(PersonGenerator.CASELOAD_PERSON_3)

entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_EXCLUSION)
entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_RESTRICTION)
entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_BOTH)
entityManager.persist(PersonGenerator.CASELOAD_LIMITED_ACCESS_NEITHER)

entityManager.persist(LimitedAccessGenerator.EXCLUSION)
entityManager.persist(LimitedAccessGenerator.RESTRICTION)
entityManager.persist(LimitedAccessGenerator.BOTH_EXCLUSION)
entityManager.persist(LimitedAccessGenerator.BOTH_RESTRICTION)
}

private fun EntityManager.persistAll(vararg entities: Any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object ContactGenerator {

val DEFAULT_STAFF = generateStaff("N01BDT1", "John", "Smith", emptyList())
val STAFF_1 = generateStaff("N01BDT2", "Jim", "Brown", emptyList())
val LIMITED_ACCESS_STAFF = generateStaff("N01BDT3", "Limited", "Access", emptyList())

val DEFAULT_TEAM = generateTeam(code = "TEAM11", description = "Main Team", staff = listOf(DEFAULT_STAFF, STAFF_1))

Expand All @@ -48,6 +49,14 @@ object ContactGenerator {
username = "JimBrown"
)

val LIMITED_ACCESS_USER = User(
id = IdGenerator.getAndIncrement(),
forename = "Limited",
surname = "Access",
staff = LIMITED_ACCESS_STAFF,
username = "LimitedAccess"
)

val COMMUNICATION_CATEGORY_RD = ReferenceData(IdGenerator.getAndIncrement(), "LT", "Communication")

val BREACH_CONTACT_TYPE = generateContactType("BRE02", false, "Breach Contact Type")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator
import uk.gov.justice.digital.hmpps.entity.Exclusion
import uk.gov.justice.digital.hmpps.entity.LimitedAccessPerson
import uk.gov.justice.digital.hmpps.entity.LimitedAccessUser
import uk.gov.justice.digital.hmpps.entity.Restriction
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person
import uk.gov.justice.digital.hmpps.integrations.delius.user.entity.User
import java.time.LocalDateTime

object LimitedAccessGenerator {
val EXCLUSION = generateExclusion(PersonDetailsGenerator.EXCLUSION)
val RESTRICTION =
generateRestriction(PersonDetailsGenerator.RESTRICTION, endDateTime = LocalDateTime.now().plusDays(1))
val BOTH_EXCLUSION = generateExclusion(PersonDetailsGenerator.RESTRICTION_EXCLUSION)
val BOTH_RESTRICTION = generateRestriction(
PersonDetailsGenerator.RESTRICTION_EXCLUSION,
endDateTime = LocalDateTime.now().plusDays(1)
)

fun generateExclusion(
person: Person,
user: User = ContactGenerator.LIMITED_ACCESS_USER,
endDateTime: LocalDateTime? = null,
id: Long = IdGenerator.getAndIncrement()
) = Exclusion(person.limitedAccess(), user.limitedAccess(), endDateTime, id)

fun generateRestriction(
person: Person,
user: User = ContactGenerator.USER_1,
endDateTime: LocalDateTime? = null,
id: Long = IdGenerator.getAndIncrement()
) = Restriction(person.limitedAccess(), user.limitedAccess(), endDateTime, id)

private fun Person.limitedAccess() = LimitedAccessPerson(crn, exclusionMessage, restrictionMessage, id)
private fun User.limitedAccess() = LimitedAccessUser(username, id)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.DEFAULT_STAFF
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.LIMITED_ACCESS_STAFF
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.USER
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.compliance.Nsi
Expand All @@ -23,6 +24,7 @@ import java.time.ZonedDateTime

object PersonGenerator {

val GENDER_MALE = ReferenceData(IdGenerator.getAndIncrement(), "M", "Male")
val OVERVIEW = generateOverview("X000004")
val EVENT_1 = generateEvent(
OVERVIEW,
Expand Down Expand Up @@ -185,10 +187,43 @@ object PersonGenerator {
PersonDetailsGenerator.PERSONAL_DETAILS.surname
)

val CL_EXCLUDED =
generateCaseloadPerson(
PersonDetailsGenerator.EXCLUSION.id,
PersonDetailsGenerator.EXCLUSION.crn,
PersonDetailsGenerator.EXCLUSION.forename,
PersonDetailsGenerator.EXCLUSION.secondName,
PersonDetailsGenerator.EXCLUSION.surname
)
val CL_RESTRICTED = generateCaseloadPerson(
PersonDetailsGenerator.RESTRICTION.id,
PersonDetailsGenerator.RESTRICTION.crn,
PersonDetailsGenerator.RESTRICTION.forename,
PersonDetailsGenerator.RESTRICTION.secondName,
PersonDetailsGenerator.RESTRICTION.surname
)

val CL_RESTRICTED_EXCLUDED = generateCaseloadPerson(
PersonDetailsGenerator.RESTRICTION_EXCLUSION.id,
PersonDetailsGenerator.RESTRICTION_EXCLUSION.crn,
PersonDetailsGenerator.RESTRICTION_EXCLUSION.forename,
PersonDetailsGenerator.RESTRICTION_EXCLUSION.secondName,
PersonDetailsGenerator.RESTRICTION_EXCLUSION.surname
)

val CASELOAD_PERSON_1 = generateCaseload(PERSON_1, DEFAULT_STAFF, ContactGenerator.DEFAULT_TEAM)
val CASELOAD_PERSON_2 = generateCaseload(PERSON_2, ContactGenerator.STAFF_1, ContactGenerator.DEFAULT_TEAM)
val CASELOAD_PERSON_3 = generateCaseload(PERSON_2, DEFAULT_STAFF, ContactGenerator.DEFAULT_TEAM)

val CASELOAD_LIMITED_ACCESS_EXCLUSION =
generateCaseload(CL_EXCLUDED, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM)
val CASELOAD_LIMITED_ACCESS_RESTRICTION =
generateCaseload(CL_RESTRICTED, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM)
val CASELOAD_LIMITED_ACCESS_BOTH =
generateCaseload(CL_RESTRICTED_EXCLUDED, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM)
val CASELOAD_LIMITED_ACCESS_NEITHER =
generateCaseload(PERSON_2, LIMITED_ACCESS_STAFF, ContactGenerator.DEFAULT_TEAM)

fun generateEvent(
person: Person,
id: Long = IdGenerator.getAndIncrement(),
Expand Down Expand Up @@ -295,8 +330,10 @@ object PersonGenerator {
telephoneNumber: String? = "4321",
preferredName: String? = "Dee",
dateOfBirth: LocalDate = LocalDate.now().minusYears(50),
gender: ReferenceData = ReferenceData(IdGenerator.getAndIncrement(), "M", "Male"),
id: Long = IdGenerator.getAndIncrement()
gender: ReferenceData = GENDER_MALE,
id: Long = IdGenerator.getAndIncrement(),
exclusionMessage: String? = null,
restrictionMessage: String? = null
) = Person(
id = id,
crn = crn,
Expand All @@ -314,7 +351,9 @@ object PersonGenerator {
religion = null,
sexualOrientation = null,
genderIdentity = null,
genderIdentityDescription = null
genderIdentityDescription = null,
exclusionMessage = exclusionMessage,
restrictionMessage = restrictionMessage
)

fun generateRequirement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ object PersonDetailsGenerator {
requiresInterpreter = true
)

val EXCLUSION = generatePersonDetails(
"E123456",
exclusionMessage = "There is an exclusion on this person"
)
val RESTRICTION =
generatePersonDetails(
"R123456",
restrictionMessage = "There is a restriction on this person"
)
val RESTRICTION_EXCLUSION = generatePersonDetails(
"B123456",
exclusionMessage = "You are excluded from viewing this case",
restrictionMessage = "You are restricted from viewing this case"
)

val ALIAS_1 = generateAlias("Sam", "Edward", "Smith", PERSONAL_DETAILS.id)
val ALIAS_2 = generateAlias("Joe", "Richard", "Jones", PersonGenerator.OVERVIEW.id)

Expand Down Expand Up @@ -236,6 +251,7 @@ object PersonDetailsGenerator {
endDate: LocalDate? = null,
verified: Boolean? = null,
notes: String? = null

) = PersonAddress(
personId = personId,
id = IdGenerator.getAndIncrement(),
Expand All @@ -255,23 +271,25 @@ object PersonDetailsGenerator {
typeVerified = verified,
telephoneNumber = "0191876865",
lastUpdatedUser = USER,
notes = notes
notes = notes,
)

fun generatePersonDetails(
crn: String,
forename: String,
secondName: String,
surname: String,
preferredName: String,
gender: ReferenceData,
religion: ReferenceData,
sexualOrientation: ReferenceData,
language: ReferenceData,
previousSurname: String,
genderIdentity: ReferenceData,
genderIdentityDescription: String,
requiresInterpreter: Boolean = false
forename: String = "TestForename",
secondName: String = "SecondName",
surname: String = "Surname",
preferredName: String = "PreferredName",
gender: ReferenceData = GENDER_FEMALE,
religion: ReferenceData = RELIGION_DEFAULT,
sexualOrientation: ReferenceData = SEXUAL_ORIENTATION,
language: ReferenceData = LANGUAGE_RD,
previousSurname: String = "PreviousSurname",
genderIdentity: ReferenceData = GENDER_IDENTITY_RD,
genderIdentityDescription: String = "genderIdentityDescription",
requiresInterpreter: Boolean = false,
exclusionMessage: String? = null,
restrictionMessage: String? = null
) = Person(
id = IdGenerator.getAndIncrement(),
crn = crn,
Expand All @@ -292,6 +310,8 @@ object PersonDetailsGenerator {
genderIdentity = genderIdentity,
genderIdentityDescription = genderIdentityDescription,
requiresInterpreter = requiresInterpreter,
exclusionMessage = exclusionMessage,
restrictionMessage = restrictionMessage
)

fun generateDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import uk.gov.justice.digital.hmpps.api.model.appointment.AppointmentDetail
import uk.gov.justice.digital.hmpps.api.model.appointment.CreateAppointment
import uk.gov.justice.digital.hmpps.api.model.appointment.Outcome
import uk.gov.justice.digital.hmpps.api.model.appointment.User
import uk.gov.justice.digital.hmpps.data.generator.AppointmentGenerator.APPOINTMENT_TYPES
import uk.gov.justice.digital.hmpps.data.generator.AppointmentGenerator.ATTENDED_COMPLIED
import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.STAFF_USER_1
import uk.gov.justice.digital.hmpps.data.generator.OffenderManagerGenerator.TEAM
Expand Down Expand Up @@ -66,6 +67,9 @@ class AppointmentOutcomeIntegrationTest {
fun `when an appointment outcome does not exist returns a 404 response`() {
val response = createAppointment()

val expectedContactType =
APPOINTMENT_TYPES.firstOrNull { type -> type.code == CreateAppointment.Type.PlannedOfficeVisitNS.code }

mockMvc
.perform(
MockMvcRequestBuilders.patch("/appointment")
Expand All @@ -76,7 +80,7 @@ class AppointmentOutcomeIntegrationTest {
.andExpect(
jsonPath(
"$.message",
equalTo("ContactTypeOutcome with contact_type_id 8 and outcome code of ABC not found")
equalTo("ContactTypeOutcome with contact_type_id ${expectedContactType?.id} and outcome code of ABC not found")
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package uk.gov.justice.digital.hmpps

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import uk.gov.justice.digital.hmpps.api.model.user.StaffCaseload
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.LIMITED_ACCESS_USER
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.EXCLUSION
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.RESTRICTION_EXCLUSION
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = RANDOM_PORT)
internal class LaoCaseloadIntegrationTest {
@Autowired
lateinit var mockMvc: MockMvc

@Test
fun `all caseload activity for an lao user`() {

val person = LIMITED_ACCESS_USER
val res = mockMvc
.perform(get("/caseload/user/${person.username}").withToken())
.andExpect(status().isOk)
.andReturn().response.contentAsJson<StaffCaseload>()

val caseload = res.caseload.sortedBy { it.crn }

assertThat(caseload[0].crn, equalTo(RESTRICTION_EXCLUSION.crn))
assertThat(caseload[1].crn, equalTo(EXCLUSION.crn))
assertThat(caseload[2].crn, equalTo(RESTRICTION.crn))


assertThat(caseload[0].limitedAccess, equalTo(true))
assertThat(caseload[0].caseName, equalTo(null))
assertThat(caseload[0].latestSentence, equalTo(null))
assertThat(caseload[0].nextAppointment, equalTo(null))
assertThat(caseload[0].previousAppointment, equalTo(null))
assertThat(caseload[0].numberOfAdditionalSentences, equalTo(null))

assertThat(caseload[1].limitedAccess, equalTo(true))
assertThat(caseload[1].caseName, equalTo(null))
assertThat(caseload[1].latestSentence, equalTo(null))
assertThat(caseload[1].nextAppointment, equalTo(null))
assertThat(caseload[1].previousAppointment, equalTo(null))
assertThat(caseload[1].numberOfAdditionalSentences, equalTo(null))

assertThat(caseload[2].limitedAccess, equalTo(true))
assertThat(caseload[2].caseName, equalTo(null))
assertThat(caseload[2].latestSentence, equalTo(null))
assertThat(caseload[2].nextAppointment, equalTo(null))
assertThat(caseload[2].previousAppointment, equalTo(null))
assertThat(caseload[2].numberOfAdditionalSentences, equalTo(null))

assertThat(caseload[3].limitedAccess, equalTo(false))
assertNotEquals(caseload[3].caseName, null)
}
}
Loading
Loading