Skip to content

Commit 6bc0cb1

Browse files
authored
Hia 745 bug v 1 persons hmpps id response is returning addresses in contact details when it shouldnt (#428)
* Fix Bug with Persons Model
1 parent a7d9d48 commit 6bc0cb1

File tree

10 files changed

+125
-124
lines changed

10 files changed

+125
-124
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ __pycache__/
8686
*.key
8787
*.csr
8888
*.pem
89+
90+
# Localstack
91+
localstack/cache

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/ProbationOffenderSearchGateway.kt

+21-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
1111
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
1212
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
1313
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
14+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.ContactDetailsWithAddress
1415
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.Offender
1516

1617
@Component
@@ -116,8 +117,26 @@ class ProbationOffenderSearchGateway(
116117
}
117118

118119
fun getAddressesForPerson(hmppsId: String): Response<List<Address>> {
119-
val offender = getOffender(hmppsId)
120-
return Response(data = offender.data?.contactDetails?.addresses.orEmpty().map { it.toAddress() }, errors = offender.errors)
120+
val result =
121+
webClient.requestList<ContactDetailsWithAddress>(
122+
HttpMethod.POST,
123+
"/search",
124+
authenticationHeader(),
125+
UpstreamApi.PROBATION_OFFENDER_SEARCH,
126+
mapOf("crn" to hmppsId),
127+
)
128+
129+
return when (result) {
130+
is WebClientWrapperResponse.Success -> {
131+
return Response(result.data.firstOrNull()?.contactDetails?.addresses.orEmpty().map { it.toAddress() })
132+
}
133+
is WebClientWrapperResponse.Error -> {
134+
Response(
135+
data = emptyList(),
136+
errors = result.errors,
137+
)
138+
}
139+
}
121140
}
122141

123142
private fun authenticationHeader(): Map<String, String> {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps
22

3-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch.Address
4-
53
data class ContactDetailsWithEmailAndPhone(
6-
val addresses: List<Address>?,
74
val phoneNumbers: List<PhoneNumber>?,
85
val emails: List<String>?,
96
)

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/probationoffendersearch/Address.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch
22

3-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
43
import java.time.LocalDate
4+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address as HmppsAddress
5+
6+
data class ContactDetailsWithAddress(
7+
val contactDetails: Addresses? = null,
8+
)
9+
10+
data class Addresses(
11+
val addresses: List<Address>? = listOf(),
12+
)
513

614
data class Address(
715
val addressNumber: String?,
@@ -18,7 +26,7 @@ data class Address(
1826
val notes: String?,
1927
) {
2028
fun toAddress() =
21-
Address(
29+
HmppsAddress(
2230
country = null,
2331
county = this.county,
2432
endDate = this.to,
@@ -39,7 +47,7 @@ data class Address(
3947
val description: String?,
4048
) {
4149
fun toAddressType() =
42-
Address.Type(
50+
HmppsAddress.Type(
4351
code = this.code,
4452
description = this.description ?: this.code,
4553
)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffendersearch
22

3-
open class ContactDetails(
4-
open val addresses: List<Address>? = listOf(),
5-
)
3+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PhoneNumber
4+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactDetailsWithEmailAndPhone as PersonContactDetails
5+
6+
class ContactDetails(
7+
val phoneNumbers: List<PhoneNumber>?,
8+
val emailAddresses: List<String>?,
9+
) {
10+
fun toContactDetails(): PersonContactDetails =
11+
PersonContactDetails(
12+
phoneNumbers = this.phoneNumbers,
13+
emails = this.emailAddresses,
14+
)
15+
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/probationoffendersearch/ContactDetailsWithEmailAndPhone.kt

-17
This file was deleted.

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/probationoffendersearch/Offender.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class Offender(
1313
val gender: String? = null,
1414
val offenderProfile: OffenderProfile = OffenderProfile(),
1515
val offenderAliases: List<OffenderAlias> = listOf(),
16-
val contactDetails: ContactDetailsWithEmailAndPhone? = null,
16+
val contactDetails: ContactDetails? = null,
1717
val otherIds: OtherIds = OtherIds(),
1818
val age: Number = 0,
1919
) {
@@ -34,7 +34,7 @@ data class Offender(
3434
),
3535
pncId = otherIds.pncNumber,
3636
hmppsId = otherIds.crn,
37-
contactDetails = this.contactDetails?.toContactdetails(),
37+
contactDetails = this.contactDetails?.toContactDetails(),
3838
)
3939

4040
fun toPersonProtectedCharacteristics(): PersonProtectedCharacteristics =

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonControllerTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ internal class PersonControllerTest(
7676
lastName = "Allen",
7777
middleName = "Jonas",
7878
dateOfBirth = LocalDate.parse("2023-03-01"),
79-
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
79+
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
8080
),
8181
Person(
8282
firstName = "Barry",
8383
lastName = "Allen",
8484
middleName = "Rock",
8585
dateOfBirth = LocalDate.parse("2022-07-22"),
86-
contactDetails = ContactDetailsWithEmailAndPhone(emptyList(), phoneNumbers, emails),
86+
contactDetails = ContactDetailsWithEmailAndPhone(phoneNumbers, emails),
8787
),
8888
),
8989
),

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/probationoffendersearch/GetAddressesForPersonTest.kt

+8-10
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ class GetAddressesForPersonTest(
2929
) : DescribeSpec(
3030
{
3131
val probationOffenderSearchApiMockServer = ProbationOffenderSearchApiMockServer()
32-
val hmppsId = "2002/1121M"
32+
val hmppsId = "X777776"
3333

3434
beforeEach {
3535
probationOffenderSearchApiMockServer.start()
3636
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
37-
"{\"pncNumber\": \"$hmppsId\"}",
37+
"{\"crn\": \"$hmppsId\"}",
3838
"""
3939
[
4040
{
41-
"firstName": "English",
42-
"surname": "Breakfast",
4341
"contactDetails": {
4442
"addresses": [
4543
{
@@ -102,7 +100,7 @@ class GetAddressesForPersonTest(
102100

103101
it("returns an empty list when no addresses are found") {
104102
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
105-
"{\"pncNumber\": \"$hmppsId\"}",
103+
"{\"crn\": \"$hmppsId\"}",
106104
"""
107105
[
108106
{
@@ -123,7 +121,7 @@ class GetAddressesForPersonTest(
123121

124122
it("returns an error when no results are returned") {
125123
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
126-
"{\"pncNumber\": \"$hmppsId\"}",
124+
"{\"crn\": \"$hmppsId\"}",
127125
"[]",
128126
)
129127

@@ -134,7 +132,7 @@ class GetAddressesForPersonTest(
134132

135133
it("returns an empty list when there is no contactDetails field") {
136134
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
137-
"{\"pncNumber\": \"$hmppsId\"}",
135+
"{\"crn\": \"$hmppsId\"}",
138136
"""
139137
[
140138
{
@@ -152,7 +150,7 @@ class GetAddressesForPersonTest(
152150

153151
it("returns an empty list when contactDetails field is null") {
154152
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
155-
"{\"pncNumber\": \"$hmppsId\"}",
153+
"{\"crn\": \"$hmppsId\"}",
156154
"""
157155
[
158156
{
@@ -171,7 +169,7 @@ class GetAddressesForPersonTest(
171169

172170
it("returns an empty list when contactDetails.addresses field is null") {
173171
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
174-
"{\"pncNumber\": \"$hmppsId\"}",
172+
"{\"crn\": \"$hmppsId\"}",
175173
"""
176174
[
177175
{
@@ -192,7 +190,7 @@ class GetAddressesForPersonTest(
192190

193191
it("returns an empty list when the type is an empty object") {
194192
probationOffenderSearchApiMockServer.stubPostOffenderSearch(
195-
"{\"pncNumber\": \"$hmppsId\"}",
193+
"{\"crn\": \"$hmppsId\"}",
196194
"""
197195
[
198196
{

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/smoke/person/PersonSmokeTest.kt

+65-82
Original file line numberDiff line numberDiff line change
@@ -44,89 +44,72 @@ class PersonSmokeTest : DescribeSpec(
4444

4545
response.body().shouldBe(
4646
"""
47-
{
48-
"data":{
49-
"prisonerOffenderSearch":{
50-
"firstName":"Robert",
51-
"lastName":"Larsen",
52-
"middleName":"John James",
53-
"dateOfBirth":"1975-04-02",
54-
"gender":"Female",
55-
"ethnicity":"White: Eng./Welsh/Scot./N.Irish/British",
56-
"aliases":[
57-
{
58-
"firstName":"Robert",
59-
"lastName":"Lorsen",
60-
"middleName":"Trevor",
61-
"dateOfBirth":"1975-04-02",
62-
"gender":"Male",
63-
"ethnicity":"White : Irish"
64-
}
65-
],
66-
"identifiers":{
67-
"nomisNumber":"A1234AA",
68-
"croNumber":"29906/12J",
69-
"deliusCrn":null
70-
},
71-
"pncId":"12/394773H",
72-
"hmppsId":null,
73-
"contactDetails":null
74-
},
75-
"probationOffenderSearch":{
76-
"firstName":"string",
77-
"lastName":"string",
78-
"middleName":"string",
79-
"dateOfBirth":"2019-08-24",
80-
"gender":"string",
81-
"ethnicity":"string",
82-
"aliases":[
83-
{
84-
"firstName":"string",
85-
"lastName":"string",
86-
"middleName":"string",
87-
"dateOfBirth":"2019-08-24",
88-
"gender":"string",
89-
"ethnicity":null
47+
{
48+
"data": {
49+
"prisonerOffenderSearch": {
50+
"firstName": "Robert",
51+
"lastName": "Larsen",
52+
"middleName": "John James",
53+
"dateOfBirth": "1975-04-02",
54+
"gender": "Female",
55+
"ethnicity": "White: Eng./Welsh/Scot./N.Irish/British",
56+
"aliases": [
57+
{
58+
"firstName": "Robert",
59+
"lastName": "Lorsen",
60+
"middleName": "Trevor",
61+
"dateOfBirth": "1975-04-02",
62+
"gender": "Male",
63+
"ethnicity": "White : Irish"
64+
}
65+
],
66+
"identifiers": {
67+
"nomisNumber": "A1234AA",
68+
"croNumber": "29906/12J",
69+
"deliusCrn": null
70+
},
71+
"pncId": "12/394773H",
72+
"hmppsId": null,
73+
"contactDetails": null
74+
},
75+
"probationOffenderSearch": {
76+
"firstName": "string",
77+
"lastName": "string",
78+
"middleName": "string",
79+
"dateOfBirth": "2019-08-24",
80+
"gender": "string",
81+
"ethnicity": "string",
82+
"aliases": [
83+
{
84+
"firstName": "string",
85+
"lastName": "string",
86+
"middleName": "string",
87+
"dateOfBirth": "2019-08-24",
88+
"gender": "string",
89+
"ethnicity": null
90+
}
91+
],
92+
"identifiers": {
93+
"nomisNumber": "G5555TT",
94+
"croNumber": "123456/24A",
95+
"deliusCrn": "A123456"
96+
},
97+
"pncId": "2012/0052494Q",
98+
"hmppsId": "A123456",
99+
"contactDetails": {
100+
"phoneNumbers": [
101+
{
102+
"number": "string",
103+
"type": "TELEPHONE"
104+
}
105+
],
106+
"emails": [
107+
"string"
108+
]
109+
}
110+
}
90111
}
91-
],
92-
"identifiers":{
93-
"nomisNumber":"G5555TT",
94-
"croNumber":"123456/24A",
95-
"deliusCrn":"A123456"
96-
},
97-
"pncId":"2012/0052494Q",
98-
"hmppsId":"A123456",
99-
"contactDetails":{
100-
"addresses":[
101-
{
102-
"addressNumber":"string",
103-
"district":"string",
104-
"buildingName":"string",
105-
"county":"string",
106-
"from":"2019-08-24",
107-
"postcode":"string",
108-
"streetName":"string",
109-
"type":{
110-
"code":"string",
111-
"description":"string"
112-
},
113-
"to":"2019-08-24",
114-
"town":"string",
115-
"noFixedAbode":true,
116-
"notes":"string"
117-
}
118-
],
119-
"phoneNumbers":[
120-
{
121-
"number":"string",
122-
"type":"TELEPHONE"
123-
}
124-
],
125-
"emails":null
126-
}
127-
}
128-
}
129-
}
112+
}
130113
""".removeWhitespaceAndNewlines(),
131114
)
132115
}

0 commit comments

Comments
 (0)