@@ -20,12 +20,14 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
20
20
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
21
21
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.helpers.IntegrationAPIMockMvc
22
22
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactDetailsWithEmailAndPhone
23
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
23
24
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ImageMetadata
24
25
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
25
26
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PhoneNumber
26
27
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
27
28
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
28
29
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
30
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSPrisoner
29
31
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetImageMetadataForPersonService
30
32
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetPersonService
31
33
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetPersonsService
@@ -222,12 +224,20 @@ internal class PersonControllerTest(
222
224
}
223
225
224
226
describe("GET $basePath/{id}") {
225
- val person = Person ("Silly ", "Sobbers ")
227
+ val probationOffenderSearch = Person ("Sam ", "Smith ", identifiers = Identifiers (nomisNumber = "1234ABC"))
228
+ val prisonOffenderSearch = POSPrisoner ("Kim ", "Kardashian ")
229
+ val prisonResponse = Response (data = prisonOffenderSearch, errors = emptyList())
226
230
227
231
beforeTest {
228
232
Mockito .reset(getPersonService)
229
233
Mockito .reset(auditService)
230
- whenever(getPersonService.execute(hmppsId)).thenReturn(Response (data = person))
234
+
235
+ val personMap =
236
+ mapOf(
237
+ "probationOffenderSearch" to probationOffenderSearch,
238
+ "prisonerOffenderSearch" to prisonResponse.data.toPerson(),
239
+ )
240
+ whenever(getPersonService.getCombinedDataForPerson(hmppsId)).thenReturn(Response (data = personMap))
231
241
}
232
242
233
243
it("returns a 200 OK status code") {
@@ -248,9 +258,13 @@ internal class PersonControllerTest(
248
258
val idThatDoesNotExist = " 9999/11111Z"
249
259
250
260
it("returns a 404 status code when a person cannot be found in both upstream APIs ") {
251
- whenever(getPersonService.execute (idThatDoesNotExist)).thenReturn(
261
+ whenever(getPersonService.getCombinedDataForPerson (idThatDoesNotExist)).thenReturn(
252
262
Response (
253
- data = null,
263
+ data =
264
+ mapOf(
265
+ "prisonerOffenderSearch" to null,
266
+ "probationOffenderSearch" to null,
267
+ ),
254
268
errors =
255
269
listOf(
256
270
UpstreamApiError (
@@ -268,9 +282,13 @@ internal class PersonControllerTest(
268
282
}
269
283
270
284
it("does not return a 404 status code when a person was found in one upstream API ") {
271
- whenever(getPersonService.execute (idThatDoesNotExist)).thenReturn(
285
+ whenever(getPersonService.getCombinedDataForPerson (idThatDoesNotExist)).thenReturn(
272
286
Response (
273
- data = Person ("someFirstName", "someLastName"),
287
+ data =
288
+ mapOf(
289
+ "prisonerOffenderSearch" to null,
290
+ "probationOffenderSearch" to Person ("someFirstName", "someLastName"),
291
+ ),
274
292
errors =
275
293
listOf(
276
294
UpstreamApiError (
@@ -291,33 +309,56 @@ internal class PersonControllerTest(
291
309
it("gets a person with the matching ID ") {
292
310
mockMvc.performAuthorised("$basePath/$encodedHmppsId")
293
311
294
- verify(getPersonService, times(1)).execute (hmppsId)
312
+ verify(getPersonService, times(1)).getCombinedDataForPerson (hmppsId)
295
313
}
296
314
297
315
it("returns a person with the matching ID ") {
298
316
val result = mockMvc.performAuthorised("$basePath/$encodedHmppsId")
299
317
300
318
result.response.contentAsString.shouldBe(
301
319
"""
302
- {
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
315
- },
316
- "pncId": null,
317
- "hmppsId": null,
318
- "contactDetails": null
319
- }
320
- }
320
+ {
321
+ "data":{
322
+ "probationOffenderSearch":{
323
+ "firstName":"Sam ",
324
+ "lastName":"Smith ",
325
+ "middleName":null,
326
+ "dateOfBirth":null,
327
+ "gender":null,
328
+ "ethnicity":null,
329
+ "aliases":[
330
+
331
+ ],
332
+ "identifiers":{
333
+ "nomisNumber":"1234ABC",
334
+ "croNumber":null,
335
+ "deliusCrn":null
336
+ },
337
+ "pncId":null,
338
+ "hmppsId":null,
339
+ "contactDetails":null
340
+ },
341
+ "prisonerOffenderSearch":{
342
+ "firstName":"Kim ",
343
+ "lastName":"Kardashian ",
344
+ "middleName":null,
345
+ "dateOfBirth":null,
346
+ "gender":null,
347
+ "ethnicity":null,
348
+ "aliases":[
349
+
350
+ ],
351
+ "identifiers":{
352
+ "nomisNumber":null,
353
+ "croNumber":null,
354
+ "deliusCrn":null
355
+ },
356
+ "pncId":null,
357
+ "hmppsId":null,
358
+ "contactDetails":null
359
+ }
360
+ }
361
+ }
321
362
""".removeWhitespaceAndNewlines(),
322
363
)
323
364
}
0 commit comments