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

Hia 745 bug v 1 persons hmpps id response is returning addresses in contact details when it shouldnt #428

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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ __pycache__/
*.key
*.csr
*.pem

# Localstack
localstack/cache
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.ContactDetailsWithAddress
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.Offender

@Component
Expand Down Expand Up @@ -116,8 +117,26 @@ class ProbationOffenderSearchGateway(
}

fun getAddressesForPerson(hmppsId: String): Response<List<Address>> {
val offender = getOffender(hmppsId)
return Response(data = offender.data?.contactDetails?.addresses.orEmpty().map { it.toAddress() }, errors = offender.errors)
val result =
webClient.requestList<ContactDetailsWithAddress>(
HttpMethod.POST,
"/search",
authenticationHeader(),
UpstreamApi.PROBATION_OFFENDER_SEARCH,
mapOf("crn" to hmppsId),
)

return when (result) {
is WebClientWrapperResponse.Success -> {
return Response(result.data.firstOrNull()?.contactDetails?.addresses.orEmpty().map { it.toAddress() })
}
is WebClientWrapperResponse.Error -> {
Response(
data = emptyList(),
errors = result.errors,
)
}
}
}

private fun authenticationHeader(): Map<String, String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.Address

data class ContactDetailsWithEmailAndPhone(
val addresses: List<Address>?,
val phoneNumbers: List<PhoneNumber>?,
val emails: List<String>?,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch

import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
import java.time.LocalDate
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address as HmppsAddress

data class ContactDetailsWithAddress(
val contactDetails: Addresses? = null,
)

data class Addresses(
val addresses: List<Address>? = listOf(),
)

data class Address(
val addressNumber: String?,
Expand All @@ -18,7 +26,7 @@ data class Address(
val notes: String?,
) {
fun toAddress() =
Address(
HmppsAddress(
country = null,
county = this.county,
endDate = this.to,
Expand All @@ -39,7 +47,7 @@ data class Address(
val description: String?,
) {
fun toAddressType() =
Address.Type(
HmppsAddress.Type(
code = this.code,
description = this.description ?: this.code,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch

open class ContactDetails(
open val addresses: List<Address>? = listOf(),
)
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PhoneNumber
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactDetailsWithEmailAndPhone as PersonContactDetails

class ContactDetails(
val phoneNumbers: List<PhoneNumber>?,
val emailAddresses: List<String>?,
) {
fun toContactDetails(): PersonContactDetails =
PersonContactDetails(
phoneNumbers = this.phoneNumbers,
emails = this.emailAddresses,
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class Offender(
val gender: String? = null,
val offenderProfile: OffenderProfile = OffenderProfile(),
val offenderAliases: List<OffenderAlias> = listOf(),
val contactDetails: ContactDetailsWithEmailAndPhone? = null,
val contactDetails: ContactDetails? = null,
val otherIds: OtherIds = OtherIds(),
val age: Number = 0,
) {
Expand All @@ -34,7 +34,7 @@ data class Offender(
),
pncId = otherIds.pncNumber,
hmppsId = otherIds.crn,
contactDetails = this.contactDetails?.toContactdetails(),
contactDetails = this.contactDetails?.toContactDetails(),
)

fun toPersonProtectedCharacteristics(): PersonProtectedCharacteristics =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ internal class PersonControllerTest(
lastName = "Allen",
middleName = "Jonas",
dateOfBirth = LocalDate.parse("2023-03-01"),
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
),
Person(
firstName = "Barry",
lastName = "Allen",
middleName = "Rock",
dateOfBirth = LocalDate.parse("2022-07-22"),
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ class GetAddressesForPersonTest(
) : DescribeSpec(
{
val probationOffenderSearchApiMockServer = ProbationOffenderSearchApiMockServer()
val hmppsId = "2002/1121M"
val hmppsId = "X777776"

beforeEach {
probationOffenderSearchApiMockServer.start()
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"""
[
{
"firstName": "English",
"surname": "Breakfast",
"contactDetails": {
"addresses": [
{
Expand Down Expand Up @@ -102,7 +100,7 @@ class GetAddressesForPersonTest(

it("returns an empty list when no addresses are found") {
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"""
[
{
Expand All @@ -123,7 +121,7 @@ class GetAddressesForPersonTest(

it("returns an error when no results are returned") {
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"[]",
)

Expand All @@ -134,7 +132,7 @@ class GetAddressesForPersonTest(

it("returns an empty list when there is no contactDetails field") {
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"""
[
{
Expand All @@ -152,7 +150,7 @@ class GetAddressesForPersonTest(

it("returns an empty list when contactDetails field is null") {
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"""
[
{
Expand All @@ -171,7 +169,7 @@ class GetAddressesForPersonTest(

it("returns an empty list when contactDetails.addresses field is null") {
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"""
[
{
Expand All @@ -192,7 +190,7 @@ class GetAddressesForPersonTest(

it("returns an empty list when the type is an empty object") {
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
"{\"pncNumber\": \"$hmppsId\"}",
"{\"crn\": \"$hmppsId\"}",
"""
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,89 +44,72 @@ class PersonSmokeTest : DescribeSpec(

response.body().shouldBe(
"""
{
"data":{
"prisonerOffenderSearch":{
"firstName":"Robert",
"lastName":"Larsen",
"middleName":"John James",
"dateOfBirth":"1975-04-02",
"gender":"Female",
"ethnicity":"White: Eng./Welsh/Scot./N.Irish/British",
"aliases":[
{
"firstName":"Robert",
"lastName":"Lorsen",
"middleName":"Trevor",
"dateOfBirth":"1975-04-02",
"gender":"Male",
"ethnicity":"White : Irish"
}
],
"identifiers":{
"nomisNumber":"A1234AA",
"croNumber":"29906/12J",
"deliusCrn":null
},
"pncId":"12/394773H",
"hmppsId":null,
"contactDetails":null
},
"probationOffenderSearch":{
"firstName":"string",
"lastName":"string",
"middleName":"string",
"dateOfBirth":"2019-08-24",
"gender":"string",
"ethnicity":"string",
"aliases":[
{
"firstName":"string",
"lastName":"string",
"middleName":"string",
"dateOfBirth":"2019-08-24",
"gender":"string",
"ethnicity":null
{
"data": {
"prisonerOffenderSearch": {
"firstName": "Robert",
"lastName": "Larsen",
"middleName": "John James",
"dateOfBirth": "1975-04-02",
"gender": "Female",
"ethnicity": "White: Eng./Welsh/Scot./N.Irish/British",
"aliases": [
{
"firstName": "Robert",
"lastName": "Lorsen",
"middleName": "Trevor",
"dateOfBirth": "1975-04-02",
"gender": "Male",
"ethnicity": "White : Irish"
}
],
"identifiers": {
"nomisNumber": "A1234AA",
"croNumber": "29906/12J",
"deliusCrn": null
},
"pncId": "12/394773H",
"hmppsId": null,
"contactDetails": null
},
"probationOffenderSearch": {
"firstName": "string",
"lastName": "string",
"middleName": "string",
"dateOfBirth": "2019-08-24",
"gender": "string",
"ethnicity": "string",
"aliases": [
{
"firstName": "string",
"lastName": "string",
"middleName": "string",
"dateOfBirth": "2019-08-24",
"gender": "string",
"ethnicity": null
}
],
"identifiers": {
"nomisNumber": "G5555TT",
"croNumber": "123456/24A",
"deliusCrn": "A123456"
},
"pncId": "2012/0052494Q",
"hmppsId": "A123456",
"contactDetails": {
"phoneNumbers": [
{
"number": "string",
"type": "TELEPHONE"
}
],
"emails": [
"string"
]
}
}
}
],
"identifiers":{
"nomisNumber":"G5555TT",
"croNumber":"123456/24A",
"deliusCrn":"A123456"
},
"pncId":"2012/0052494Q",
"hmppsId":"A123456",
"contactDetails":{
"addresses":[
{
"addressNumber":"string",
"district":"string",
"buildingName":"string",
"county":"string",
"from":"2019-08-24",
"postcode":"string",
"streetName":"string",
"type":{
"code":"string",
"description":"string"
},
"to":"2019-08-24",
"town":"string",
"noFixedAbode":true,
"notes":"string"
}
],
"phoneNumbers":[
{
"number":"string",
"type":"TELEPHONE"
}
],
"emails":null
}
}
}
}
}
""".removeWhitespaceAndNewlines(),
)
}
Expand Down
Loading