Skip to content

Commit

Permalink
PI-2346 Add full address line to core-person response
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Jul 8, 2024
1 parent 0a5f52e commit 791cf03
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ object PersonGenerator {
)

val FULL_PERSON_ADDRESSES = listOf(
generateAddress(FULL_PERSON.id, MAIN_ADDRESS, "PC1 1TS", LocalDate.now().minusDays(30))
generateAddress(
FULL_PERSON.id,
MAIN_ADDRESS,
"1",
null,
"Main Street",
"",
" ",
"London",
"PC1 1TS",
LocalDate.now().minusDays(30)
)
)

val FULL_PERSON_EXCLUSIONS = listOf(
Expand Down Expand Up @@ -133,12 +144,32 @@ object PersonGenerator {
fun generateAddress(
personId: Long,
status: ReferenceData,
postcode: String,
addressNumber: String?,
buildingName: String?,
streetName: String?,
townCity: String?,
county: String?,
district: String?,
postcode: String?,
startDate: LocalDate,
endDate: LocalDate? = null,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = PersonAddress(personId, status, postcode, startDate, endDate, softDeleted, id)
) = PersonAddress(
personId,
status,
addressNumber,
buildingName,
streetName,
townCity,
county,
district,
postcode,
startDate,
endDate,
softDeleted,
id,
)

private fun generateExclusion(
personId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,10 @@ 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.boot.test.mock.mockito.MockBean
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import uk.gov.justice.digital.hmpps.api.model.LimitedAccess
import uk.gov.justice.digital.hmpps.api.model.LimitedAccessUser
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.integration.delius.entity.Alias
import uk.gov.justice.digital.hmpps.integration.delius.entity.PersonAddress
import uk.gov.justice.digital.hmpps.service.asAddress
import uk.gov.justice.digital.hmpps.service.asModel
import uk.gov.justice.digital.hmpps.service.detail
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.andExpectJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken

@AutoConfigureMockMvc
Expand All @@ -29,37 +18,110 @@ internal class CorePersonIntegrationTest {
@Autowired
lateinit var mockMvc: MockMvc

@MockBean
lateinit var telemetryService: TelemetryService

val minPerson = PersonGenerator.MIN_PERSON.detail(listOf(), listOf())
val fullPerson = PersonGenerator.FULL_PERSON.detail(
aliases = PersonGenerator.FULL_PERSON_ALIASES.map(Alias::asModel),
addresses = PersonGenerator.FULL_PERSON_ADDRESSES.mapNotNull(PersonAddress::asAddress),
exclusions = LimitedAccess(
message = "This case is excluded because ...",
users = listOf(LimitedAccessUser("SomeUser1"))
),
restrictions = LimitedAccess(
message = "This case is restricted because ...",
users = listOf(LimitedAccessUser("SomeUser2"), LimitedAccessUser("FutureEndDatedUser"))
),
)

@Test
fun `correctly returns detail by crn`() {
mockMvc
.perform(get("/probation-cases/${PersonGenerator.MIN_PERSON.crn}").withToken())
.andExpect(status().is2xxSuccessful)
.andExpectJson(minPerson)
.andExpect(
content().json(
"""
{
"identifiers": {
"deliusId": ${PersonGenerator.MIN_PERSON.id},
"crn": "M123456"
},
"name": {
"forename": "Isabelle",
"surname": "Necessary"
},
"dateOfBirth": "1990-03-05",
"aliases": [],
"addresses": []
}
""".trimIndent()
)
)
}

@Test
fun `correctly returns detail by id`() {
mockMvc
.perform(get("/probation-cases/${PersonGenerator.FULL_PERSON.id}").withToken())
.andExpect(status().is2xxSuccessful)
.andExpectJson(fullPerson)
.andExpect(
content().json(
"""
{
"identifiers": {
"deliusId": ${PersonGenerator.FULL_PERSON.id},
"crn": "F123456",
"nomsId": "A3349EX",
"prisonerNumber": "94600E",
"pnc": "2011/0593710D",
"cro": "89861/11W",
"ni": "FJ123456W"
},
"name": {
"forename": "Frederick",
"middleName": "Paul Bernard",
"surname": "Johnson",
"previousSurname": "No Previous",
"preferred": "Freddy"
},
"dateOfBirth": "1975-07-15",
"title": {
"code": "TIT",
"description": "Description of TIT"
},
"gender": {
"code": "GEN",
"description": "Description of GEN"
},
"nationality": {
"code": "NAT",
"description": "Description of NAT"
},
"ethnicity": {
"code": "ETH",
"description": "Description of ETH"
},
"ethnicityDescription": "Description of ethnicity",
"contactDetails": {
"telephone": "0191 755 4789",
"mobile": "07895746789",
"email": "[email protected]"
},
"aliases": [
{
"name": {
"forename": "Freddy",
"surname": "Banter"
},
"dateOfBirth": "1974-02-17"
}
],
"addresses": [
{
"fullAddress": "1 Main Street, London, PC1 1TS",
"postcode": "PC1 1TS"
}
],
"excludedFrom": {
"message": "This case is excluded because ...",
"users": [{ "username": "SomeUser1" }]
},
"restrictedTo": {
"message": "This case is restricted because ...",
"users": [
{ "username": "SomeUser2" },
{ "username": "FutureEndDatedUser" }
]
}
}
""".trimIndent()
)
)
}

@Test
Expand All @@ -68,7 +130,7 @@ internal class CorePersonIntegrationTest {
.perform(get("/all-probation-cases?sort=crn,desc").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("page.totalElements", equalTo(2)))
.andExpect(jsonPath("content[0].identifiers.crn", equalTo(minPerson.identifiers.crn)))
.andExpect(jsonPath("content[1].identifiers.crn", equalTo(fullPerson.identifiers.crn)))
.andExpect(jsonPath("content[0].identifiers.crn", equalTo(PersonGenerator.MIN_PERSON.crn)))
.andExpect(jsonPath("content[1].identifiers.crn", equalTo(PersonGenerator.FULL_PERSON.crn)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ data class CodeDescription(val code: String, val description: String)

data class Alias(val name: Name, val dateOfBirth: LocalDate)

data class Address(val postcode: String)
data class Address(val fullAddress: String, val postcode: String)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class PersonAddress(
@ManyToOne
@JoinColumn(name = "address_status_id")
val status: ReferenceData,
val addressNumber: String?,
var buildingName: String?,
var streetName: String?,
var townCity: String?,
var county: String?,
var district: String?,
val postcode: String?,
val startDate: LocalDate?,
val endDate: LocalDate?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,22 @@ fun uk.gov.justice.digital.hmpps.integration.delius.entity.Alias.asModel() = Ali
dateOfBirth
)

fun PersonAddress.asAddress() = postcode?.let { Address(it) }
fun PersonAddress.asAddress() = postcode?.let {
Address(
fullAddress = listOf(
buildingName,
listOf(addressNumber, streetName).trimAndJoin(" "),
district,
townCity,
county,
postcode
).trimAndJoin(),
postcode = postcode
)
}

private fun List<String?>.trimAndJoin(separator: String = ", ") =
filterNotNull().filter { it.isNotBlank() }.joinToString(separator) { it.trim() }

fun List<Exclusion>.exclusionsAsLimitedAccess(message: String?) = if (isNotEmpty()) {
LimitedAccess(
Expand Down

0 comments on commit 791cf03

Please sign in to comment.