Skip to content

Commit 002482b

Browse files
Controller code and smoke test
1 parent f8f48d3 commit 002482b

File tree

3 files changed

+120
-77
lines changed

3 files changed

+120
-77
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonController.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,17 @@ class PersonController(
6161
@GetMapping("{encodedHmppsId}")
6262
fun getPerson(
6363
@PathVariable encodedHmppsId: String,
64-
): Map<String, Person?> {
64+
): Map<String, Map<String, Person?>> {
6565
val hmppsId = encodedHmppsId.decodeUrlCharacters()
66-
val response = getPersonService.execute(hmppsId)
66+
val response = getPersonService.getCombinedDataForPerson(hmppsId)
6767

6868
if (response.hasErrorCausedBy(ENTITY_NOT_FOUND, causedBy = UpstreamApi.PROBATION_OFFENDER_SEARCH)) {
6969
throw EntityNotFoundException("Could not find person with id: $hmppsId")
7070
}
7171

7272
auditService.createEvent("GET_PERSON_DETAILS", mapOf("hmppsId" to hmppsId))
73-
return mapOf("data" to response.data)
73+
val data = response.data.mapValues { it.value }
74+
return mapOf("data" to data)
7475
}
7576

7677
@GetMapping("{encodedHmppsId}/images")

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

+36-22
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ internal class PersonControllerTest(
227227
beforeTest {
228228
Mockito.reset(getPersonService)
229229
Mockito.reset(auditService)
230-
whenever(getPersonService.execute(hmppsId)).thenReturn(Response(data = person))
230+
231+
val personMap = mapOf("probationOffenderSearch" to person, "prisonerOffenderSearch" to null)
232+
whenever(getPersonService.getCombinedDataForPerson(hmppsId)).thenReturn(Response(data = personMap))
231233
}
232234

233235
it("returns a 200 OK status code") {
@@ -248,9 +250,13 @@ internal class PersonControllerTest(
248250
val idThatDoesNotExist = "9999/11111Z"
249251

250252
it("returns a 404 status code when a person cannot be found in both upstream APIs") {
251-
whenever(getPersonService.execute(idThatDoesNotExist)).thenReturn(
253+
whenever(getPersonService.getCombinedDataForPerson(idThatDoesNotExist)).thenReturn(
252254
Response(
253-
data = null,
255+
data =
256+
mapOf(
257+
"prisonerOffenderSearch" to null,
258+
"probationOffenderSearch" to null,
259+
),
254260
errors =
255261
listOf(
256262
UpstreamApiError(
@@ -268,9 +274,13 @@ internal class PersonControllerTest(
268274
}
269275

270276
it("does not return a 404 status code when a person was found in one upstream API") {
271-
whenever(getPersonService.execute(idThatDoesNotExist)).thenReturn(
277+
whenever(getPersonService.getCombinedDataForPerson(idThatDoesNotExist)).thenReturn(
272278
Response(
273-
data = Person("someFirstName", "someLastName"),
279+
data =
280+
mapOf(
281+
"prisonerOffenderSearch" to null,
282+
"probationOffenderSearch" to Person("someFirstName", "someLastName"),
283+
),
274284
errors =
275285
listOf(
276286
UpstreamApiError(
@@ -291,7 +301,7 @@ internal class PersonControllerTest(
291301
it("gets a person with the matching ID") {
292302
mockMvc.performAuthorised("$basePath/$encodedHmppsId")
293303

294-
verify(getPersonService, times(1)).execute(hmppsId)
304+
verify(getPersonService, times(1)).getCombinedDataForPerson(hmppsId)
295305
}
296306

297307
it("returns a person with the matching ID") {
@@ -300,24 +310,28 @@ internal class PersonControllerTest(
300310
result.response.contentAsString.shouldBe(
301311
"""
302312
{
303-
"data": {
304-
"firstName": "Silly",
305-
"lastName": "Sobbers",
306-
"middleName": null,
307-
"dateOfBirth": null,
308-
"gender": null,
309-
"ethnicity": null,
310-
"aliases": [],
311-
"identifiers": {
312-
"nomisNumber": null,
313-
"croNumber": null,
314-
"deliusCrn": null
313+
"data": {
314+
"probationOffenderSearch": {
315+
"firstName": "Silly",
316+
"lastName": "Sobbers",
317+
"middleName": null,
318+
"dateOfBirth": null,
319+
"gender": null,
320+
"ethnicity": null,
321+
"aliases": [],
322+
"identifiers": {
323+
"nomisNumber": null,
324+
"croNumber": null,
325+
"deliusCrn": null
326+
},
327+
"pncId": null,
328+
"hmppsId": null,
329+
"contactDetails": null
315330
},
316-
"pncId": null,
317-
"hmppsId": null,
318-
"contactDetails": null
319-
}
331+
"prisonerOffenderSearch": null
332+
}
320333
}
334+
321335
""".removeWhitespaceAndNewlines(),
322336
)
323337
}

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

+80-52
Original file line numberDiff line numberDiff line change
@@ -45,60 +45,88 @@ class PersonSmokeTest : DescribeSpec(
4545
response.body().shouldBe(
4646
"""
4747
{
48-
"data": {
49-
"firstName": "string",
50-
"lastName": "string",
51-
"middleName": "string",
52-
"dateOfBirth": "2019-08-24",
53-
"gender": "string",
54-
"ethnicity": "string",
55-
"aliases": [
56-
{
57-
"firstName": "string",
58-
"lastName": "string",
59-
"middleName": "string",
60-
"dateOfBirth": "2019-08-24",
61-
"gender": "string",
62-
"ethnicity": null
63-
}
64-
],
65-
"identifiers": {
66-
"nomisNumber": "G5555TT",
67-
"croNumber": "123456/24A",
68-
"deliusCrn": "A123456"
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
6974
},
70-
"pncId": "2012/0052494Q",
71-
"hmppsId": "A123456",
72-
"contactDetails": {
73-
"addresses": [
74-
{
75-
"addressNumber": "string",
76-
"district": "string",
77-
"buildingName": "string",
78-
"county": "string",
79-
"from": "2019-08-24",
80-
"postcode": "string",
81-
"streetName": "string",
82-
"type": {
83-
"code": "string",
84-
"description": "string"
85-
},
86-
"to": "2019-08-24",
87-
"town": "string",
88-
"noFixedAbode": true,
89-
"notes": "string"
90-
}
91-
],
92-
"phoneNumbers": [
93-
{
94-
"number": "string",
95-
"type": "TELEPHONE"
96-
}
97-
],
98-
"emails":null
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+
"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+
}
99127
}
100-
}
101-
}
128+
}
129+
}
102130
""".removeWhitespaceAndNewlines(),
103131
)
104132
}

0 commit comments

Comments
 (0)